Merge branch 'game_logic'

This commit is contained in:
Sorrel Bri 2020-04-17 17:17:18 -07:00
commit e53a8f4f2a
10 changed files with 23095 additions and 23900 deletions

View file

@ -43,8 +43,8 @@ jobs:
- node_modules
key:
v1-dependencies-{{ checksum "package-lock.json" }}
# - run: npm install react
# - run: npm install react-dom
- run: npm install react
- run: npm install react-dom
# ! temporary fix for deprecated package: minimist
- run: npm audit --audit-level=moderate

30598
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
"private": true,
"scripts": {
"test": "lerna run test",
"bootstrap": "lerna bootstrap"
"bootstrap": "lerna bootstrap --hoist"
},
"dependencies": {
"react": "^16.13.1",

File diff suppressed because it is too large Load diff

View file

@ -6,16 +6,16 @@
"@mars/heroku-js-runtime-env": "^3.0.2",
"@testing-library/user-event": "^7.1.2",
"node-sass": "^4.13.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.1.2",
"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": {
"start": "REACT_APP_ENVIRONMENT='development' react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "CI=true react-scripts test",
"eject": "react-scripts eject",
"flow": "./node_modules/.bin/flow",
"predeploy": "REACT_APP_ENVIRONMENT=production npm run build",

View file

@ -3,7 +3,7 @@ import { render } from '@testing-library/react';
import FormError from './FormError';
test('renders FormError without crashing', () => {
const { getByTestId } = render(<FormError />);
const { getByTestId } = render(<FormError error={''}/>);
const FormErrorSpan = getByTestId('FormError');
expect(FormErrorSpan).toBeInTheDocument();
});

View file

@ -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 ], [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
constructor(gameData, gameRecord) {
this.winner = gameData.winner || null,
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.komi = gameData.komi || 6.5, // komi depends on handicap stones + player rank
this.handicap = gameData.handicap || 0,
this.boardSize = gameData.boardSize || 19,
this.playerState = gameData.playerState || {
this.winner = gameData.winner || null,
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.komi = gameData.komi || 6.5, // komi depends on handicap stones + player rank
this.handicap = gameData.handicap || 0,
this.boardSize = gameData.boardSize || 19,
this.groups = {},
this.boardState = [],
this.gameRecord = gameRecord || [],
this.playerState = gameData.playerState || {
bCaptures: 0,
wCaptures: 0,
bScore: 0,
wScore: 0
},
this.gameRecord = gameRecord || [],
this.groups = {},
this.boardState = []
}
}
initGame = () => {
this.winner = null;
this.pass = null;
this.turn = this.handicap ? -1 : 1;
this.pass = null;
this.turn = this.handicap ? -1 : 1;
this.initBoard();
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 {
constructor(x, y, Game) {

View 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();
})
})

View file

@ -32,10 +32,8 @@ describe('game services', () => {
gameServices.initGame({ id: 1, handicap:4 });
const afterMoveOne = gameServices.makeMove({ id: 1 }, { player: 'white', pos: { x: 4, y: 3 } });
afterMoveOne.should.not.eql(fourHandicapBoard);
console.log (afterMoveOne)
done();
})
})