Skip to content

Commit

Permalink
rename movesPerTurn to moveLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolodavis committed Sep 10, 2019
1 parent 6dc3856 commit 61eb8d8
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/react-native/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TicTacToe = {
},
},

turn: { movesPerTurn: 1 },
turn: { moveLimit: 1 },

endIf: (G, ctx) => {
if (IsVictory(G.cells)) {
Expand Down
2 changes: 1 addition & 1 deletion examples/react-web/src/chess/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ChessGame = {
},
},

turn: { movesPerTurn: 1 },
turn: { moveLimit: 1 },

endIf: G => {
const chess = Load(G.pgn);
Expand Down
2 changes: 1 addition & 1 deletion examples/react-web/src/tic-tac-toe/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TicTacToe = {
},

turn: {
movesPerTurn: 1,
moveLimit: 1,
},

endIf: (G, ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/react-web/src/ui/chess3d/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const ChessGame = {
},
},

turn: { movesPerTurn: 1 },
turn: { moveLimit: 1 },

endIf: G => {
const chess = Load(G.pgn);
Expand Down
2 changes: 1 addition & 1 deletion integration/src/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const TicTacToe = Game({
},

flow: {
movesPerTurn: 1,
moveLimit: 1,

endGameIf: (G, ctx) => {
if (IsVictory(G.cells)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ai/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const TicTacToe = Game({
},
},

turn: { movesPerTurn: 1 },
turn: { moveLimit: 1 },

endIf: (G, ctx) => {
if (IsVictory(G.cells)) {
Expand Down
11 changes: 4 additions & 7 deletions src/core/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function Flow({
*
* // End the turn automatically after a certain number
* // of moves.
* movesPerTurn: 1,
* moveLimit: 1,
*
* // Code to run at the end of a move.
* onMove: (G, ctx, { type: 'moveName', args: [] }) => G
Expand Down Expand Up @@ -262,10 +262,7 @@ export function FlowWithPhases({
const conf = phaseMap[ctx.phase];

const currentPlayerMoves = ctx.stats.turn.numMoves[ctx.currentPlayer] || 0;
if (
conf.turn.movesPerTurn &&
currentPlayerMoves >= conf.turn.movesPerTurn
) {
if (conf.turn.moveLimit && currentPlayerMoves >= conf.turn.moveLimit) {
return true;
}
return conf.turn.endIf(G, ctx);
Expand Down Expand Up @@ -424,9 +421,9 @@ export function FlowWithPhases({

const conf = phaseMap[ctx.phase];

// Prevent ending the turn if movesPerTurn haven't been made.
// Prevent ending the turn if moveLimit haven't been made.
const currentPlayerMoves = ctx.stats.turn.numMoves[ctx.currentPlayer] || 0;
if (conf.turn.movesPerTurn && currentPlayerMoves < conf.turn.movesPerTurn) {
if (conf.turn.moveLimit && currentPlayerMoves < conf.turn.moveLimit) {
return state;
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/flow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ describe('phases', () => {
});
});

test('movesPerTurn', () => {
test('moveLimit', () => {
{
const flow = FlowWithPhases({
turn: {
movesPerTurn: 2,
moveLimit: 2,
},
});
let state = flow.init({ ctx: flow.ctx(2) });
Expand All @@ -215,11 +215,11 @@ test('movesPerTurn', () => {

{
const flow = FlowWithPhases({
turn: { movesPerTurn: 2 },
turn: { moveLimit: 2 },
phases: {
B: {
turn: {
movesPerTurn: 1,
moveLimit: 1,
},
},
},
Expand Down

0 comments on commit 61eb8d8

Please sign in to comment.