Skip to content

Commit 10ef457

Browse files
committed
retire Game(). call it internally instead.
1 parent 063dbcb commit 10ef457

28 files changed

Lines changed: 353 additions & 388 deletions

packages/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* https://opensource.org/licenses/MIT.
77
*/
88

9-
import Game from '../src/core/game.js';
9+
import { Game } from '../src/core/game.js';
1010
import {
1111
InitializeGame,
1212
CreateGameReducer,

src/ai/bot.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* https://opensource.org/licenses/MIT.
77
*/
88

9-
import Game from '../core/game';
109
import { InitializeGame } from '../core/reducer';
1110
import { MAKE_MOVE, GAME_EVENT } from '../core/action-types';
1211
import { makeMove } from '../core/action-creators';
1312
import { Simulate, Bot, RandomBot, MCTSBot } from './bot';
13+
import { Game } from '../core/game';
1414

1515
function IsVictory(cells) {
1616
const positions = [
@@ -141,7 +141,7 @@ describe('MCTSBot', () => {
141141
});
142142

143143
test('game that never ends', () => {
144-
const game = Game({});
144+
const game = {};
145145
const state = InitializeGame({ game });
146146
const bot = new MCTSBot({ seed: 'test', game, enumerate: () => [] });
147147
const { state: endState } = Simulate({ game, bots: bot, state });

src/client/client.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { createStore, compose, applyMiddleware } from 'redux';
1010
import * as Actions from '../core/action-types';
1111
import * as ActionCreators from '../core/action-creators';
12+
import { Game } from '../core/game';
1213
import { error } from '../core/logger';
1314
import { SocketIO } from './transport/socketio';
1415
import { Local, LocalMaster } from './transport/local';
@@ -92,15 +93,15 @@ class _ClientImpl {
9293
credentials,
9394
enhancer,
9495
}) {
95-
this.game = game;
96+
this.game = Game(game);
9697
this.playerID = playerID;
9798
this.gameID = gameID;
9899
this.credentials = credentials;
99100
this.multiplayer = multiplayer;
100101
this.subscribeCallback = () => {};
101102

102103
this.reducer = CreateGameReducer({
103-
game,
104+
game: this.game,
104105
numPlayers,
105106
multiplayer,
106107
});
@@ -124,7 +125,7 @@ class _ClientImpl {
124125

125126
let initialState = null;
126127
if (multiplayer === undefined) {
127-
initialState = InitializeGame({ game, numPlayers });
128+
initialState = InitializeGame({ game: this.game, numPlayers });
128129
}
129130

130131
this.reset = () => {
@@ -252,24 +253,25 @@ class _ClientImpl {
252253
}
253254

254255
if (multiplayer.local === true) {
255-
if (localMaster_ === null || localMaster_.game !== game) {
256-
localMaster_ = new LocalMaster(game);
256+
if (localMaster_ === null || localMaster_.config !== game) {
257+
localMaster_ = new LocalMaster(this.game);
258+
localMaster_.config = game;
257259
}
258260

259261
this.transport = new Local({
260262
master: localMaster_,
261263
store: this.store,
262264
gameID: gameID,
263265
playerID: playerID,
264-
gameName: game.name,
266+
gameName: this.game.name,
265267
numPlayers,
266268
});
267269
} else if (multiplayer.server !== undefined) {
268270
this.transport = new SocketIO({
269271
store: this.store,
270272
gameID: gameID,
271273
playerID: playerID,
272-
gameName: game.name,
274+
gameName: this.game.name,
273275
numPlayers,
274276
server: multiplayer.server,
275277
socketOpts,

src/client/client.test.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import { createStore } from 'redux';
1010
import { InitializeGame, CreateGameReducer } from '../core/reducer';
1111
import { Client, createMoveDispatchers } from './client';
12+
import { Game } from '../core/game';
1213
import { Local } from './transport/local';
1314
import { SocketIO } from './transport/socketio';
1415
import { update, sync, makeMove, gameEvent } from '../core/action-creators';
15-
import Game from '../core/game';
1616
import { RandomBot } from '../ai/bot';
1717
import { error } from '../core/logger';
1818

@@ -23,11 +23,11 @@ jest.mock('../core/logger', () => ({
2323

2424
test('move api', () => {
2525
const client = Client({
26-
game: Game({
26+
game: {
2727
moves: {
2828
A: (G, ctx, arg) => ({ arg }),
2929
},
30-
}),
30+
},
3131
});
3232

3333
expect(client.getState().G).toEqual({});
@@ -39,7 +39,7 @@ describe('namespaced moves', () => {
3939
let client;
4040
beforeAll(() => {
4141
client = Client({
42-
game: Game({
42+
game: {
4343
moves: {
4444
A: () => 'A',
4545
},
@@ -52,7 +52,7 @@ describe('namespaced moves', () => {
5252
},
5353
},
5454
},
55-
}),
55+
},
5656
});
5757
});
5858

@@ -88,13 +88,13 @@ describe('namespaced moves', () => {
8888

8989
test('isActive', () => {
9090
const client = Client({
91-
game: Game({
91+
game: {
9292
moves: {
9393
A: (G, ctx, arg) => ({ arg }),
9494
},
9595

9696
endIf: G => G.arg == 42,
97-
}),
97+
},
9898
});
9999

100100
expect(client.getState().G).toEqual({});
@@ -106,7 +106,7 @@ test('isActive', () => {
106106

107107
describe('step', () => {
108108
const client = Client({
109-
game: Game({
109+
game: {
110110
setup: () => ({ moved: false }),
111111

112112
moves: {
@@ -118,7 +118,7 @@ describe('step', () => {
118118
endIf(G) {
119119
if (G.moved) return true;
120120
},
121-
}),
121+
},
122122

123123
ai: {
124124
bot: RandomBot,
@@ -134,7 +134,7 @@ describe('step', () => {
134134

135135
test('does not crash on empty action', () => {
136136
const client = Client({
137-
game: Game({}),
137+
game: {},
138138

139139
ai: {
140140
bot: RandomBot,
@@ -153,7 +153,7 @@ describe('multiplayer', () => {
153153

154154
beforeAll(() => {
155155
client = Client({
156-
game: Game({ moves: { A: () => {} } }),
156+
game: { moves: { A: () => {} } },
157157
multiplayer: { server: host + ':' + port },
158158
});
159159
client.connect();
@@ -185,7 +185,7 @@ describe('multiplayer', () => {
185185

186186
beforeAll(() => {
187187
client = Client({
188-
game: Game({}),
188+
game: {},
189189
multiplayer: true,
190190
});
191191
client.connect();
@@ -203,7 +203,7 @@ describe('multiplayer', () => {
203203

204204
beforeAll(() => {
205205
spec = {
206-
game: Game({ moves: { A: (G, ctx) => ({ A: ctx.playerID }) } }),
206+
game: { moves: { A: (G, ctx) => ({ A: ctx.playerID }) } },
207207
multiplayer: { local: true },
208208
};
209209

@@ -255,7 +255,7 @@ describe('multiplayer', () => {
255255

256256
beforeAll(() => {
257257
client = Client({
258-
game: Game({ moves: { A: () => {} } }),
258+
game: { moves: { A: () => {} } },
259259
multiplayer: { transport: CustomTransport },
260260
});
261261
});
@@ -274,7 +274,7 @@ describe('multiplayer', () => {
274274
describe('invalid spec', () => {
275275
test('logs error', () => {
276276
Client({
277-
game: Game({ moves: { A: () => {} } }),
277+
game: { moves: { A: () => {} } },
278278
multiplayer: { blah: true },
279279
});
280280
expect(error).toHaveBeenCalledWith('invalid multiplayer spec');
@@ -292,11 +292,11 @@ test('accepts enhancer for store', () => {
292292
};
293293
};
294294
const client = Client({
295-
game: Game({
295+
game: {
296296
moves: {
297297
A: (G, ctx, arg) => ({ arg }),
298298
},
299-
}),
299+
},
300300
enhancer: spyEnhancer,
301301
});
302302

@@ -307,7 +307,7 @@ test('accepts enhancer for store', () => {
307307

308308
describe('event dispatchers', () => {
309309
test('default', () => {
310-
const game = Game({});
310+
const game = {};
311311
const client = Client({ game });
312312
expect(Object.keys(client.events)).toEqual(['endTurn']);
313313
expect(client.getState().ctx.turn).toBe(0);
@@ -316,11 +316,11 @@ describe('event dispatchers', () => {
316316
});
317317

318318
test('all events', () => {
319-
const game = Game({
319+
const game = {
320320
endPhase: true,
321321
endGame: true,
322322
setActionPlayers: true,
323-
});
323+
};
324324
const client = Client({ game });
325325
expect(Object.keys(client.events)).toEqual([
326326
'endTurn',
@@ -334,10 +334,10 @@ describe('event dispatchers', () => {
334334
});
335335

336336
test('no events', () => {
337-
const game = Game({
337+
const game = {
338338
endPhase: false,
339339
endTurn: false,
340-
});
340+
};
341341
const client = Client({ game });
342342
expect(Object.keys(client.events)).toEqual([]);
343343
});
@@ -418,11 +418,11 @@ describe('log handling', () => {
418418

419419
beforeEach(() => {
420420
client = Client({
421-
game: Game({
421+
game: {
422422
moves: {
423423
A: () => ({}),
424424
},
425-
}),
425+
},
426426
});
427427
});
428428

src/client/debug/debug.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import React from 'react';
1010
import { stringify } from 'flatted';
1111
import { Client } from '../client';
1212
import { sync } from '../../core/action-creators';
13-
import Game from '../../core/game';
1413
import { createStore } from 'redux';
1514
import { Debug } from './debug';
1615
import Mousetrap from 'mousetrap';
@@ -147,11 +146,11 @@ describe('log', () => {
147146

148147
test('hover', () => {
149148
const overrideGameState = jest.fn();
150-
const game = Game({
149+
const game = {
151150
moves: {
152151
A: (G, ctx, arg) => ({ arg }),
153152
},
154-
});
153+
};
155154

156155
const client = Client({ game });
157156
client.moves.A(42);

src/client/log/log.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import React from 'react';
1010
import { Client } from '../client';
1111
import { makeMove, automaticGameEvent } from '../../core/action-creators';
12-
import Game from '../../core/game';
1312
import { GameLog } from './log';
1413
import { InitializeGame, CreateGameReducer } from '../../core/reducer';
1514
import Enzyme from 'enzyme';
@@ -18,13 +17,13 @@ import Adapter from 'enzyme-adapter-react-16';
1817
Enzyme.configure({ adapter: new Adapter() });
1918

2019
describe('layout', () => {
21-
const game = Game({
20+
const game = {
2221
startingPhase: 'A',
2322
phases: {
2423
A: { next: 'B' },
2524
B: { next: 'A' },
2625
},
27-
});
26+
};
2827
const reducer = CreateGameReducer({ game });
2928
const state = InitializeGame({ game });
3029

@@ -73,7 +72,7 @@ describe('time travel', () => {
7372
let hoverState;
7473

7574
beforeAll(() => {
76-
const game = Game({
75+
const game = {
7776
moves: {
7877
A: (G, ctx, arg) => {
7978
return { arg };
@@ -83,7 +82,7 @@ describe('time travel', () => {
8382
turn: {
8483
endIf: G => G && G.arg == 42,
8584
},
86-
});
85+
};
8786

8887
client = Client({ game });
8988
const initialState = client.getState()._initial;
@@ -157,12 +156,12 @@ describe('time travel', () => {
157156
});
158157

159158
describe('pinning', () => {
160-
const game = Game({
159+
const game = {
161160
moves: {
162161
A: () => ({ A: true }),
163162
B: () => ({ B: true }),
164163
},
165-
});
164+
};
166165

167166
const reducer = CreateGameReducer({ game });
168167
let state = InitializeGame({ game });
@@ -242,7 +241,7 @@ describe('pinning', () => {
242241
});
243242

244243
describe('payload', () => {
245-
const game = Game({});
244+
const game = {};
246245
const reducer = CreateGameReducer({ game });
247246
const state = InitializeGame({ game });
248247

0 commit comments

Comments
 (0)