Skip to content

Commit d0a67eb

Browse files
authored
Merge pull request #267 from th555/sunspot
sunspot: add validation messages to incomplete moves
2 parents 02f1300 + 100e1c8 commit d0a67eb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

locales/en/apgames.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,6 +5044,10 @@
50445044
"NO_PIECE": "You don't have a size {{size}} piece to place.",
50455045
"PARTIAL_PLACEMENT": "Click an empty space on the board to place your {{size}} piece."
50465046
},
5047+
"sunspot": {
5048+
"OPTIONAL_FLIP": "You may submit the move as-is, or you may additionally flip an interior stone that is part of a combined group to your colour.",
5049+
"MANDATORY_COUNTERFLIP": "You must flip one of your own edge subgroups in the same group as the flipped stone."
5050+
},
50475051
"surmount": {
50485052
"BAD_CAP": "You may not capture the stone at {{cell}}. The captured stone must be adjacent to the capturing group and must be part of a group that is the same size as the capturing group.",
50495053
"BAD_CONTINUE": "You may not place a stone at {{cell}}. Continuations may not make contact with any groups other than those initially contacted, and they may not grow the group any larger than the largest enemy group initially contacted.",

src/games/sunspot.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type MovePart = {
1818
previousAction: string
1919
) => [boolean, Map<string, cellcontent>];
2020
condition?: (board: Map<string, cellcontent>, previousAction: string) => boolean;
21+
message?: string;
2122
}
2223

2324
export interface IMoveState extends IIndividualState {
@@ -212,6 +213,8 @@ export class SunspotGame extends GameBase {
212213
- Finally, actions also return the board after the action has been applied.
213214
- Note that conditions don't have an 'action' argument.
214215
- Note that they must be arrow functions, to keep the 'this' in scope.
216+
- Moves that have both a condition and an action can have a message, to indicate to the player
217+
what to do next in case of an incomplete move.
215218
*/
216219

217220
/* Actions */
@@ -305,12 +308,14 @@ export class SunspotGame extends GameBase {
305308

306309
private flipAction = {
307310
condition: this.checkFlipIsPossible,
308-
action: this.doFlipAction
311+
action: this.doFlipAction,
312+
message: "apgames:validation.sunspot.OPTIONAL_FLIP"
309313
}
310314

311315
private counterFlipAction = {
312316
condition: this.checkCounterFlipIsPossible,
313-
action: this.doCounterFlipAction
317+
action: this.doCounterFlipAction,
318+
message: "apgames:validation.sunspot.MANDATORY_COUNTERFLIP"
314319
}
315320

316321
private placeIsNotPossible = {
@@ -362,6 +367,7 @@ export class SunspotGame extends GameBase {
362367

363368
let complete = false; // found at least one (valid) complete move
364369
let incomplete = false; // found at least one (valid) incomplete move
370+
let message = undefined;
365371
for (const movePartSequence of validMoves) {
366372
let remainingActionStrs = m.split(';');
367373
let previousActionStr = "";
@@ -393,6 +399,9 @@ export class SunspotGame extends GameBase {
393399
movePartSequence. */
394400
incomplete = true;
395401
validComplete = false;
402+
if (movePart.message !== undefined) {
403+
message = movePart.message;
404+
}
396405
break;
397406
}
398407
}
@@ -417,6 +426,9 @@ export class SunspotGame extends GameBase {
417426
result.complete = -1;
418427
result.message = i18next.t("apgames:validation._general.INCOMPLETE_MOVE");
419428
}
429+
if (incomplete && message !== undefined) {
430+
result.message = i18next.t(message);
431+
}
420432
return result
421433
} else {
422434
return {

0 commit comments

Comments
 (0)