Skip to content

Commit d5e2b55

Browse files
committed
start turn at 1
1 parent d8bf5ef commit d5e2b55

8 files changed

Lines changed: 37 additions & 36 deletions

File tree

src/ai/bot.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('MCTSBot', () => {
145145
const state = InitializeGame({ game });
146146
const bot = new MCTSBot({ seed: 'test', game, enumerate: () => [] });
147147
const { state: endState } = Simulate({ game, bots: bot, state });
148-
expect(endState.ctx.turn).toBe(0);
148+
expect(endState.ctx.turn).toBe(1);
149149
});
150150

151151
test('RandomBot vs. MCTSBot', () => {

src/client/client.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ describe('event dispatchers', () => {
311311
const game = {};
312312
const client = Client({ game });
313313
expect(Object.keys(client.events)).toEqual(['endTurn']);
314-
expect(client.getState().ctx.turn).toBe(0);
315-
client.events.endTurn();
316314
expect(client.getState().ctx.turn).toBe(1);
315+
client.events.endTurn();
316+
expect(client.getState().ctx.turn).toBe(2);
317317
});
318318

319319
test('all events', () => {
@@ -331,9 +331,9 @@ describe('event dispatchers', () => {
331331
'endGame',
332332
'setActionPlayers',
333333
]);
334-
expect(client.getState().ctx.turn).toBe(0);
335-
client.events.endTurn();
336334
expect(client.getState().ctx.turn).toBe(1);
335+
client.events.endTurn();
336+
expect(client.getState().ctx.turn).toBe(2);
337337
});
338338

339339
test('no events', () => {
@@ -440,13 +440,13 @@ describe('log handling', () => {
440440
action: makeMove('A', [], '0'),
441441
_stateID: 0,
442442
phase: '',
443-
turn: 0,
443+
turn: 1,
444444
},
445445
{
446446
action: makeMove('A', [], '0'),
447447
_stateID: 1,
448448
phase: '',
449-
turn: 0,
449+
turn: 1,
450450
},
451451
]);
452452
});

src/client/log/log.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('time travel', () => {
119119
.simulate('mouseenter');
120120

121121
expect(hoverState.G).toMatchObject({ arg: 1 });
122-
expect(hoverState.ctx.turn).toBe(0);
122+
expect(hoverState.ctx.turn).toBe(1);
123123
expect(hoverState.ctx.currentPlayer).toBe('0');
124124
});
125125

@@ -130,7 +130,7 @@ describe('time travel', () => {
130130
.simulate('mouseenter');
131131

132132
expect(hoverState.G).toMatchObject({ arg: 42 });
133-
expect(hoverState.ctx.turn).toBe(2);
133+
expect(hoverState.ctx.turn).toBe(3);
134134
expect(hoverState.ctx.currentPlayer).toBe('0');
135135
});
136136

@@ -141,7 +141,7 @@ describe('time travel', () => {
141141
.simulate('mouseenter');
142142

143143
expect(hoverState.G).toMatchObject({ arg: 2 });
144-
expect(hoverState.ctx.turn).toBe(2);
144+
expect(hoverState.ctx.turn).toBe(3);
145145
expect(hoverState.ctx.currentPlayer).toBe('0');
146146
});
147147

src/core/events.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ test('update ctx', () => {
5151
},
5252
};
5353
const client = Client({ game });
54-
expect(client.getState().ctx.turn).toBe(0);
55-
client.moves.A();
5654
expect(client.getState().ctx.turn).toBe(1);
55+
client.moves.A();
56+
expect(client.getState().ctx.turn).toBe(2);
5757
});

src/core/flow.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,9 @@ export function FlowWithPhases({ phases, endIf, turn, events, plugins }) {
369369
// Start //
370370
///////////
371371

372-
function StartGame(state) {
373-
return ProcessEvents(state, [{ fn: StartPhase }]);
372+
function StartGame(state, { next }) {
373+
next.push({ fn: StartPhase });
374+
return state;
374375
}
375376

376377
function StartPhase(state, { next }) {
@@ -706,7 +707,7 @@ export function FlowWithPhases({ phases, endIf, turn, events, plugins }) {
706707
return Flow({
707708
ctx: numPlayers => ({
708709
numPlayers,
709-
turn: -1,
710+
turn: 0,
710711
currentPlayer: '0',
711712
actionPlayers: ['0'],
712713
currentPlayerMoves: 0,
@@ -716,7 +717,7 @@ export function FlowWithPhases({ phases, endIf, turn, events, plugins }) {
716717
stage: {},
717718
}),
718719
init: state => {
719-
return StartGame(state);
720+
return ProcessEvents(state, [{ fn: StartGame }]);
720721
},
721722
eventHandlers,
722723
enabledEvents,

src/core/flow.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ test('moveLimit', () => {
163163
},
164164
});
165165
let state = flow.init({ ctx: flow.ctx(2) });
166-
expect(state.ctx.turn).toBe(0);
166+
expect(state.ctx.turn).toBe(1);
167167
state = flow.processMove(state, makeMove('move', null, '0').payload);
168-
expect(state.ctx.turn).toBe(0);
168+
expect(state.ctx.turn).toBe(1);
169169
state = flow.processGameEvent(state, gameEvent('endTurn'));
170-
expect(state.ctx.turn).toBe(0);
171-
state = flow.processMove(state, makeMove('move', null, '0').payload);
172170
expect(state.ctx.turn).toBe(1);
171+
state = flow.processMove(state, makeMove('move', null, '0').payload);
172+
expect(state.ctx.turn).toBe(2);
173173
}
174174

175175
{
@@ -184,20 +184,20 @@ test('moveLimit', () => {
184184
},
185185
});
186186
let state = flow.init({ ctx: flow.ctx(2) });
187-
expect(state.ctx.turn).toBe(0);
187+
expect(state.ctx.turn).toBe(1);
188188
state = flow.processMove(state, makeMove('move', null, '0').payload);
189-
expect(state.ctx.turn).toBe(0);
189+
expect(state.ctx.turn).toBe(1);
190190
state = flow.processGameEvent(state, gameEvent('endTurn'));
191-
expect(state.ctx.turn).toBe(0);
192-
state = flow.processMove(state, makeMove('move', null, '0').payload);
193191
expect(state.ctx.turn).toBe(1);
192+
state = flow.processMove(state, makeMove('move', null, '0').payload);
193+
expect(state.ctx.turn).toBe(2);
194194

195195
state = flow.processGameEvent(state, gameEvent('endPhase', { next: 'B' }));
196196

197197
expect(state.ctx.phase).toBe('B');
198-
expect(state.ctx.turn).toBe(2);
199-
state = flow.processMove(state, makeMove('move', null, '0').payload);
200198
expect(state.ctx.turn).toBe(3);
199+
state = flow.processMove(state, makeMove('move', null, '0').payload);
200+
expect(state.ctx.turn).toBe(4);
201201
}
202202
});
203203

@@ -541,21 +541,21 @@ test('endTurn is not called twice in one move', () => {
541541

542542
expect(state.ctx.phase).toBe('A');
543543
expect(state.ctx.currentPlayer).toBe('0');
544-
expect(state.ctx.turn).toBe(0);
544+
expect(state.ctx.turn).toBe(1);
545545

546546
state = flow.processMove(state, makeMove().payload);
547547

548548
expect(state.ctx.phase).toBe('A');
549549
expect(state.ctx.currentPlayer).toBe('1');
550-
expect(state.ctx.turn).toBe(1);
550+
expect(state.ctx.turn).toBe(2);
551551

552552
state.G.endPhase = true;
553553

554554
state = flow.processMove(state, makeMove().payload);
555555

556556
expect(state.ctx.phase).toBe('B');
557557
expect(state.ctx.currentPlayer).toBe('0');
558-
expect(state.ctx.turn).toBe(2);
558+
expect(state.ctx.turn).toBe(3);
559559
});
560560

561561
describe('endPhase returns to previous phase', () => {

src/core/reducer.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ test('victory', () => {
130130
test('endTurn', () => {
131131
{
132132
let state = reducer(initialState, gameEvent('endTurn'));
133-
expect(state.ctx.turn).toBe(1);
133+
expect(state.ctx.turn).toBe(2);
134134
}
135135

136136
{
137137
const reducer = CreateGameReducer({ game, multiplayer: true });
138138
let state = reducer(initialState, gameEvent('endTurn'));
139-
expect(state.ctx.turn).toBe(0);
139+
expect(state.ctx.turn).toBe(1);
140140
}
141141
});
142142

@@ -209,7 +209,7 @@ test('deltalog', () => {
209209
action: actionA,
210210
_stateID: 0,
211211
phase: '',
212-
turn: 0,
212+
turn: 1,
213213
},
214214
]);
215215
state = reducer(state, actionB);
@@ -218,7 +218,7 @@ test('deltalog', () => {
218218
action: actionB,
219219
_stateID: 1,
220220
phase: '',
221-
turn: 0,
221+
turn: 1,
222222
},
223223
]);
224224
state = reducer(state, actionC);
@@ -227,7 +227,7 @@ test('deltalog', () => {
227227
action: actionC,
228228
_stateID: 2,
229229
phase: '',
230-
turn: 0,
230+
turn: 1,
231231
},
232232
]);
233233
});

src/master/master.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe('update', () => {
121121
phase: '',
122122
playOrder: ['0', '1'],
123123
playOrderPos: 0,
124-
turn: 0,
124+
turn: 1,
125125
},
126126
},
127127
_redo: [],
@@ -136,7 +136,7 @@ describe('update', () => {
136136
phase: '',
137137
playOrder: ['0', '1'],
138138
playOrderPos: 1,
139-
turn: 1,
139+
turn: 2,
140140
},
141141
});
142142

0 commit comments

Comments
 (0)