Merge branch 'game_logic'
This commit is contained in:
commit
e53a8f4f2a
10 changed files with 23095 additions and 23900 deletions
|
@ -43,8 +43,8 @@ jobs:
|
||||||
- node_modules
|
- node_modules
|
||||||
key:
|
key:
|
||||||
v1-dependencies-{{ checksum "package-lock.json" }}
|
v1-dependencies-{{ checksum "package-lock.json" }}
|
||||||
# - run: npm install react
|
- run: npm install react
|
||||||
# - run: npm install react-dom
|
- run: npm install react-dom
|
||||||
|
|
||||||
# ! temporary fix for deprecated package: minimist
|
# ! temporary fix for deprecated package: minimist
|
||||||
- run: npm audit --audit-level=moderate
|
- run: npm audit --audit-level=moderate
|
||||||
|
|
30598
package-lock.json
generated
30598
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "lerna run test",
|
"test": "lerna run test",
|
||||||
"bootstrap": "lerna bootstrap"
|
"bootstrap": "lerna bootstrap --hoist"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
|
|
16277
packages/play-node-go/package-lock.json
generated
16277
packages/play-node-go/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -6,16 +6,16 @@
|
||||||
"@mars/heroku-js-runtime-env": "^3.0.2",
|
"@mars/heroku-js-runtime-env": "^3.0.2",
|
||||||
"@testing-library/user-event": "^7.1.2",
|
"@testing-library/user-event": "^7.1.2",
|
||||||
"node-sass": "^4.13.0",
|
"node-sass": "^4.13.0",
|
||||||
"react": "^16.13.1",
|
|
||||||
"react-dom": "^16.13.1",
|
|
||||||
"react-router-dom": "^5.1.2",
|
"react-router-dom": "^5.1.2",
|
||||||
"react-scripts": "^3.4.0",
|
"react-scripts": "^3.4.0",
|
||||||
"socket.io-client": "^2.3.0"
|
"socket.io-client": "^2.3.0",
|
||||||
|
"react": "^16.13.1",
|
||||||
|
"react-dom": "^16.13.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "REACT_APP_ENVIRONMENT='development' react-scripts start",
|
"start": "REACT_APP_ENVIRONMENT='development' react-scripts start",
|
||||||
"build": "react-scripts build",
|
"build": "react-scripts build",
|
||||||
"test": "react-scripts test",
|
"test": "CI=true react-scripts test",
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"flow": "./node_modules/.bin/flow",
|
"flow": "./node_modules/.bin/flow",
|
||||||
"predeploy": "REACT_APP_ENVIRONMENT=production npm run build",
|
"predeploy": "REACT_APP_ENVIRONMENT=production npm run build",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
|
||||||
import FormError from './FormError';
|
import FormError from './FormError';
|
||||||
|
|
||||||
test('renders FormError without crashing', () => {
|
test('renders FormError without crashing', () => {
|
||||||
const { getByTestId } = render(<FormError />);
|
const { getByTestId } = render(<FormError error={''}/>);
|
||||||
const FormErrorSpan = getByTestId('FormError');
|
const FormErrorSpan = getByTestId('FormError');
|
||||||
expect(FormErrorSpan).toBeInTheDocument();
|
expect(FormErrorSpan).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
|
@ -38,30 +38,63 @@ const HANDI_REC = {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// index represents handicap placement for different board-sizes, eg handiPlace['9][1] = { (3, 3), (7, 7) }
|
||||||
|
// last array in each property also used for hoshi rendering
|
||||||
|
const HANDI_PLACE = {
|
||||||
|
'9' : [
|
||||||
|
0, 0,
|
||||||
|
[[ 7, 3 ], [ 3, 7 ] ],
|
||||||
|
[ [ 7, 7 ], [ 7, 3 ], [ 3, 7 ] ],
|
||||||
|
[ [ 3, 3 ], [ 7, 7 ], [ 3, 7 ], [ 7, 3 ] ]
|
||||||
|
],
|
||||||
|
'13' : [
|
||||||
|
0, 0,
|
||||||
|
[ [ 4, 10 ], [ 10, 4 ] ],
|
||||||
|
[ [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
[ [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
[ [ 7, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
[ [ 7, 4 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
[ [ 7, 7 ], [ 7, 4 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
[ [ 10, 7 ], [ 7, 4 ], [ 7, 10 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
[ [ 7, 7 ], [ 10, 7 ], [ 7, 4 ], [ 7, 10 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
||||||
|
],
|
||||||
|
'19' : [
|
||||||
|
0, 0,
|
||||||
|
[ [ 4, 16 ], [ 16, 4 ] ],
|
||||||
|
[ [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
[ [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
[ [ 10, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
[ [ 10, 4 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
[ [ 10, 10 ], [ 10, 4 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
[ [ 16, 10 ], [ 10, 4 ], [ 10, 16 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
[ [ 10, 10 ], [ 16, 10 ], [ 10, 4 ], [ 10, 16 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
constructor(gameData, gameRecord) {
|
constructor(gameData, gameRecord) {
|
||||||
this.winner = gameData.winner || null,
|
this.winner = gameData.winner || null,
|
||||||
this.turn = gameData.turn || 1, // turn logic depends on handicap stones
|
this.turn = gameData.turn || 1, // turn logic depends on handicap stones
|
||||||
this.pass = gameData.pass || 0, // -1 represents state in which resignation has been submitted, not confirmed
|
this.pass = gameData.pass || 0, // -1 represents state in which resignation has been submitted, not confirmed
|
||||||
this.komi = gameData.komi || 6.5, // komi depends on handicap stones + player rank
|
this.komi = gameData.komi || 6.5, // komi depends on handicap stones + player rank
|
||||||
this.handicap = gameData.handicap || 0,
|
this.handicap = gameData.handicap || 0,
|
||||||
this.boardSize = gameData.boardSize || 19,
|
this.boardSize = gameData.boardSize || 19,
|
||||||
this.playerState = gameData.playerState || {
|
this.groups = {},
|
||||||
|
this.boardState = [],
|
||||||
|
this.gameRecord = gameRecord || [],
|
||||||
|
this.playerState = gameData.playerState || {
|
||||||
bCaptures: 0,
|
bCaptures: 0,
|
||||||
wCaptures: 0,
|
wCaptures: 0,
|
||||||
bScore: 0,
|
bScore: 0,
|
||||||
wScore: 0
|
wScore: 0
|
||||||
},
|
}
|
||||||
this.gameRecord = gameRecord || [],
|
|
||||||
|
|
||||||
this.groups = {},
|
|
||||||
this.boardState = []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initGame = () => {
|
initGame = () => {
|
||||||
this.winner = null;
|
this.winner = null;
|
||||||
this.pass = null;
|
this.pass = null;
|
||||||
this.turn = this.handicap ? -1 : 1;
|
this.turn = this.handicap ? -1 : 1;
|
||||||
|
|
||||||
this.initBoard();
|
this.initBoard();
|
||||||
return this.getBoardState();
|
return this.getBoardState();
|
||||||
}
|
}
|
||||||
|
@ -139,38 +172,6 @@ class Game {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// index represents handicap placement for different board-sizes, eg handiPlace['9][1] = { (3, 3), (7, 7) }
|
|
||||||
// last array in each property also used for hoshi rendering
|
|
||||||
const HANDI_PLACE = {
|
|
||||||
'9' : [
|
|
||||||
0, 0,
|
|
||||||
[[ 7, 3 ], [ 3, 7 ] ],
|
|
||||||
[ [ 7, 7 ], [ 7, 3 ], [ 3, 7 ] ],
|
|
||||||
[ [ 3, 3 ], [ 7, 7 ], [ 3, 7 ], [ 7, 3 ] ]
|
|
||||||
],
|
|
||||||
'13' : [
|
|
||||||
0, 0,
|
|
||||||
[ [ 4, 10 ], [ 10, 4 ] ],
|
|
||||||
[ [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
[ [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
[ [ 7, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
[ [ 7, 4 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
[ [ 7, 7 ], [ 7, 4 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
[ [ 10, 7 ], [ 7, 4 ], [ 7, 10 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
[ [ 7, 7 ], [ 10, 7 ], [ 7, 4 ], [ 7, 10 ], [ 4, 7 ], [ 4, 4 ], [ 10, 10 ], [ 4, 10 ], [ 10, 4] ],
|
|
||||||
],
|
|
||||||
'19' : [
|
|
||||||
0, 0,
|
|
||||||
[ [ 4, 16 ], [ 16, 4 ] ],
|
|
||||||
[ [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
[ [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
[ [ 10, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
[ [ 10, 4 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
[ [ 10, 10 ], [ 10, 4 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
[ [ 16, 10 ], [ 10, 4 ], [ 10, 16 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
[ [ 10, 10 ], [ 16, 10 ], [ 10, 4 ], [ 10, 16 ], [ 4, 10 ], [ 4, 4 ], [ 16, 16 ], [ 4, 16 ], [ 16, 4] ],
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
class Point {
|
class Point {
|
||||||
constructor(x, y, Game) {
|
constructor(x, y, Game) {
|
||||||
|
|
9
packages/server/test/Game.spec.js
Normal file
9
packages/server/test/Game.spec.js
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
const chai = require('chai');
|
||||||
|
const should = chai.should();
|
||||||
|
const Game = require('../services/Game');
|
||||||
|
|
||||||
|
describe('Game', () => {
|
||||||
|
it('init Game', done => {
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
|
@ -32,10 +32,8 @@ describe('game services', () => {
|
||||||
gameServices.initGame({ id: 1, handicap:4 });
|
gameServices.initGame({ id: 1, handicap:4 });
|
||||||
const afterMoveOne = gameServices.makeMove({ id: 1 }, { player: 'white', pos: { x: 4, y: 3 } });
|
const afterMoveOne = gameServices.makeMove({ id: 1 }, { player: 'white', pos: { x: 4, y: 3 } });
|
||||||
afterMoveOne.should.not.eql(fourHandicapBoard);
|
afterMoveOne.should.not.eql(fourHandicapBoard);
|
||||||
console.log (afterMoveOne)
|
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue