Skip to content

Commit

Permalink
v5.0.0-alpha.273: Move Token Titles and CPU Strategy Bug Fix (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertyishi committed Nov 22, 2023
1 parent 7a15373 commit 9794a7f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
"preview:https": "serve dist",
"reinstall": "rm -rf node_modules; yarn; vue-tsc --noEmit"
},
"version": "5.0.0-alpha.272"
"version": "5.0.0-alpha.273"
}
26 changes: 20 additions & 6 deletions src/components/units/GameBody/AppGameBodyStatisticsMessage.vue
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
<template>
<div id="app-game-body-statistics-message" v-if="showNextMoveHints">
<!-- Game not over -->
<template v-if="currentRemoteness != 0">
<!-- Games: Special handling if current position is drawing -->
<p v-if="!isPuzzleGame && currentPositionValue === 'draw'">
<b class="uni-turn-1">{{ currentLeftPlayerName }}</b> and
<b class="uni-turn-2">{{ currentRightPlayerName }}</b> are in a
<mark :class="`uni-${currentPositionValue}`">draw</mark>!
</p>
<!-- Games: Special handling if current position is unsolved -->
<p v-else-if="!isPuzzleGame && currentPositionValue === 'unsolved'">
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b>'s
turn. {{ mexStr }}
</p>
<!-- Games: win/lose/tie in <remoteness> moves -->
<p v-else-if="!isPuzzleGame">
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b> should
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b>
{{ currentPlayerIsComputer ? "will" : "should" }}
<mark :class="`uni-${currentPositionValue}`">{{ currentPositionValue }}</mark>
the game in {{ currentRemoteness }}
move<span v-if="currentRemoteness !== 1">s</span>. {{ mexStr }}
{{ currentRemoteness == 1 ? "move" : "moves" }}{{ currentWinBy ? " or by " + currentWinBy : "" }}.
{{ mexStr }}
</p>
<!-- Puzzles: solve the puzzle in <remoteness> moves -->
<p v-else>
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b> should
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b>
{{ currentPlayerIsComputer ? "will" : "should" }}
<mark :class="`uni-win`">solve</mark> the puzzle in {{ currentRemoteness }}
move<span v-if="currentRemoteness !== 1">s</span>.
{{ currentRemoteness == 1 ? "move" : "moves" }}.
</p>
</template>

<!-- Game over -->
<template v-else>
<p v-if="!isPuzzleGame && currentPositionValue === 'win'">
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b> has
<mark :class="`uni-${currentPositionValue}`">won</mark> the game! {{ mexStr }}
<mark :class="`uni-${currentPositionValue}`">won</mark>
the game{{ currentWinBy ? " by " + currentWinBy : "" }}! {{ mexStr }}
</p>
<p v-else-if="!isPuzzleGame && currentPositionValue === 'tie'">
<b class="uni-turn-1">{{ currentLeftPlayerName }}</b> and
Expand All @@ -34,7 +45,8 @@
</p>
<p v-else-if="!isPuzzleGame && currentPositionValue === 'lose'">
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b> has
<mark :class="`uni-${currentPositionValue}`">lost</mark> the game! {{ mexStr }}
<mark :class="`uni-${currentPositionValue}`">lost</mark>
the game{{ currentWinBy ? " by " + currentWinBy : "" }}! {{ mexStr }}
</p>
<p v-else-if="isPuzzleGame">
<b :class="`uni-turn-${currentTurn}`">{{ currentPlayerName }}</b> has
Expand All @@ -61,8 +73,10 @@
const currentLeftPlayerName = computed(() => store.getters.currentLeftPlayer.name);
const currentRightPlayerName = computed(() => store.getters.currentRightPlayer.name);
const currentPlayerName = computed(() => (store.getters.currentPlayer ? store.getters.currentPlayer.name : ""));
const currentPlayerIsComputer = computed(() => (store.getters.currentPlayer ? store.getters.currentPlayer.isComputer : false));
const currentRemoteness = computed(() => store.getters.currentRemoteness);
const currentPositionValue = computed(() => store.getters.currentPositionValue);
const currentWinBy = computed(() => store.getters.currentWinBy);
const mexStr = computed(() => (store.getters.currentPositionMex !== "") ? "[Grundy #: " + store.getters.currentPositionMex + "]" : "");
</script>

Expand Down
86 changes: 81 additions & 5 deletions src/components/units/GameBody/ImageAutoGUI.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,21 @@
:d="formatArrowPolylinePoints(arrow, arrowWidth)"
:class="'app-game-board-default-arrow ' + getBoardMoveElementHintClass(arrow.move)"
:opacity="options.showNextMoveHints && options.showNextMoveDeltaRemotenesses ? arrow.move.hintOpacity : 1"
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: arrow.move.str })"/>
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: arrow.move.str })">
<title>
{{
!options.showNextMoveHints ? "" : (
arrow.move.value + (
arrow.move.value === "draw" || arrow.move.value === "unsolved" ? "" : (
" in " + arrow.move.remoteness + (
!arrow.move.winby ? "" : " by " + arrow.move.winby
)
)
)
)
}}
</title>
</path>
</g>
</g>

Expand Down Expand Up @@ -51,7 +65,21 @@
:class="'app-game-board-default-button ' + (token.move ? 'move ' : '') + getBoardMoveElementHintClass(token.move)"
:opacity="options.showNextMoveHints && options.showNextMoveDeltaRemotenesses ? token.move.hintOpacity : 1"
:style="'--tOrigin: ' + centers[token.to][0] + 'px ' + centers[token.to][1] + 'px;'"
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: token.move.str })"/>
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: token.move.str })">
<title>
{{
!options.showNextMoveHints ? "" : (
token.move.value + (
token.move.value === "draw" || token.move.value === "unsolved" ? "" : (
" in " + token.move.remoteness + (
!token.move.winby ? "" : " by " + token.move.winby
)
)
)
)
}}
</title>
</circle>

<!-- Else use the svg corresponding to the move token. If no svg is mapped to the character, skip. -->
<g v-else-if="token.token in entities">
Expand All @@ -71,7 +99,21 @@
:class="'app-game-board-default-button ' + (token.move ? 'move ' : '') + getBoardMoveElementHintClass(token.move)"
:opacity="options.showNextMoveHints && options.showNextMoveDeltaRemotenesses ? token.move.hintOpacity : 1"
:style="'--tOrigin: ' + centers[token.to][0] + 'px ' + centers[token.to][1] + 'px;mask: url(#svgmask' + i + ');'"
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: token.move.str })"/>
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: token.move.str })">
<title>
{{
!options.showNextMoveHints ? "" : (
token.move.value + (
token.move.value === "draw" || token.move.value === "unsolved" ? "" : (
" in " + token.move.remoteness + (
!token.move.winby ? "" : " by " + token.move.winby
)
)
)
)
}}
</title>
</rect>
</g>
</g>
</g>
Expand All @@ -83,7 +125,21 @@
:d="formatArrowPolylinePoints(arrow, arrowWidth)"
:class="'app-game-board-default-arrow ' + getBoardMoveElementHintClass(arrow.move)"
:opacity="options.showNextMoveHints && options.showNextMoveDeltaRemotenesses ? arrow.move.hintOpacity : 1"
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: arrow.move.str })"/>
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: arrow.move.str })">
<title>
{{
!options.showNextMoveHints ? "" : (
arrow.move.value + (
arrow.move.value === "draw" || arrow.move.value === "unsolved" ? "" : (
" in " + arrow.move.remoteness + (
!arrow.move.winby ? "" : " by " + arrow.move.winby
)
)
)
)
}}
</title>
</path>
</g>
</g>

Expand All @@ -99,7 +155,21 @@
:stroke-width="lineWidth * widthFactor"
:class="'app-game-board-default-line ' + getBoardMoveElementHintClass(line.move)"
:opacity="options.showNextMoveHints && options.showNextMoveDeltaRemotenesses ? line.move.hintOpacity : 1"
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: line.move.str })"/>
@click="!isComputerTurn && store.dispatch(actionTypes.runMove, { move: line.move.str })">
<title>
{{
!options.showNextMoveHints ? "" : (
line.move.value + (
line.move.value === "draw" || line.move.value === "unsolved" ? "" : (
" in " + line.move.remoteness + (
!line.move.winby ? "" : " by " + line.move.winby
)
)
)
)
}}
</title>
</line>
</g>
</g>
</svg>
Expand All @@ -112,6 +182,9 @@
interface GDefaultRegular2DMove {
str: string; // UWAPI move string
value: string;
remoteness: number;
winby: number;
hint: string;
hintOpacity: number;
nextPosition: string;
Expand Down Expand Up @@ -181,7 +254,10 @@
for (let nextMoveData of Object.values(currentAvailableMoves.value)) {
const move = {
str: nextMoveData.move,
value: nextMoveData.moveValue,
hint: nextMoveData.moveValue,
remoteness: nextMoveData.remoteness,
winby: nextMoveData.winby,
hintOpacity: !options.value.showNextMoves ? 0.001 : nextMoveData.moveValueOpacity,
nextPosition: nextMoveData.position
};
Expand Down
4 changes: 3 additions & 1 deletion src/models/datas/defaultApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export const defaultMatch: Types.Match = {
animationPlaying: false
};

export const defaultCPUsStrategy: Array<string> = ["Remoteness", "Remoteness"];

export const defaultApp: Types.App = {
...defaultUpdate,
version: <string>import.meta.env.PACKAGE_VERSION || "",
Expand Down Expand Up @@ -182,5 +184,5 @@ export const defaultApp: Types.App = {
backgroundLoading: false,
computerMoving: false
},
CPUsStrategy: ["Remoteness", "Remoteness"],
CPUsStrategy: defaultCPUsStrategy,
};
1 change: 1 addition & 0 deletions src/scripts/gamesmanUni/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ export const initiateMatch = async (app: Types.App, payload: {
const updatedApp = await loadPosition(app, { ...payload, position: startPosition });
if (!updatedApp) return undefined;

if (!game.supportsWinBy) app.CPUsStrategy = Defaults.defaultCPUsStrategy;
app.currentMatch.gameTheme = gameVariant.imageAutoGUIData ? gameVariant.imageAutoGUIData.defaultTheme : "";
app.currentMatch.startPosition = startPosition;
app.currentMatch.moveHistory = game.name + moveHistoryDelim + startPosition;
Expand Down

0 comments on commit 9794a7f

Please sign in to comment.