fix game rule issues
This commit is contained in:
parent
c970c7c7fa
commit
9902404ca8
@ -5,6 +5,7 @@ export class GRLastStoneInBank implements GameRule {
|
|||||||
onGameMoveStart(game: MancalaGame, index: number): void {}
|
onGameMoveStart(game: MancalaGame, index: number): void {}
|
||||||
onGameMove(game: MancalaGame, index: number): void {}
|
onGameMove(game: MancalaGame, index: number): void {}
|
||||||
onGameMoveEnd(game: MancalaGame, index: number): void {
|
onGameMoveEnd(game: MancalaGame, index: number): void {
|
||||||
|
index = game.board.getPitIndexCircularly(index);
|
||||||
const pitType = game.board.getPitTypeByIndex(index);
|
const pitType = game.board.getPitTypeByIndex(index);
|
||||||
if (
|
if (
|
||||||
(pitType === 'player1Bank' && game.isTurnPlayer1()) ||
|
(pitType === 'player1Bank' && game.isTurnPlayer1()) ||
|
||||||
|
|||||||
@ -5,30 +5,31 @@ export class GRLastStoneInEmptyPit implements GameRule {
|
|||||||
onGameMoveStart(game: MancalaGame, index: number): void {}
|
onGameMoveStart(game: MancalaGame, index: number): void {}
|
||||||
onGameMove(game: MancalaGame, index: number): void {}
|
onGameMove(game: MancalaGame, index: number): void {}
|
||||||
onGameMoveEnd(game: MancalaGame, index: number): void {
|
onGameMoveEnd(game: MancalaGame, index: number): void {
|
||||||
|
index = game.board.getPitIndexCircularly(index);
|
||||||
const pit = game.board.pits[index];
|
const pit = game.board.pits[index];
|
||||||
const pitType = game.board.getPitTypeByIndex(index);
|
const pitType = game.board.getPitTypeByIndex(index);
|
||||||
if (pit.stoneCount === 1) {
|
if (pit.stoneCount === 1) {
|
||||||
if (pitType === 'player1Pit' && game.isTurnPlayer1()) {
|
if (pitType === 'player1Pit' && game.isTurnPlayer1()) {
|
||||||
const oppositePit =
|
const oppositePit =
|
||||||
game.board.pits[this.getOppositePitIndex(game, index)];
|
game.board.pits[game.board.getOppositePitIndex(index)];
|
||||||
const player1BankIndex = game.board.pits[game.board.player1BankIndex()];
|
if (oppositePit.stoneCount > 0) {
|
||||||
player1BankIndex.stoneCount += 1 + oppositePit.stoneCount;
|
const player1BankIndex =
|
||||||
oppositePit.stoneCount = 0;
|
game.board.pits[game.board.player1BankIndex()];
|
||||||
pit.stoneCount = 0;
|
player1BankIndex.stoneCount += 1 + oppositePit.stoneCount;
|
||||||
|
oppositePit.stoneCount = 0;
|
||||||
|
pit.stoneCount = 0;
|
||||||
|
}
|
||||||
} else if (pitType === 'player2Pit' && game.isTurnPlayer2()) {
|
} else if (pitType === 'player2Pit' && game.isTurnPlayer2()) {
|
||||||
const oppositePit =
|
const oppositePit =
|
||||||
game.board.pits[this.getOppositePitIndex(game, index)];
|
game.board.pits[game.board.getOppositePitIndex(index)];
|
||||||
const player2BankIndex = game.board.pits[game.board.player2BankIndex()];
|
if (oppositePit.stoneCount > 0) {
|
||||||
player2BankIndex.stoneCount += 1 + oppositePit.stoneCount;
|
const player2BankIndex =
|
||||||
oppositePit.stoneCount = 0;
|
game.board.pits[game.board.player2BankIndex()];
|
||||||
pit.stoneCount = 0;
|
player2BankIndex.stoneCount += 1 + oppositePit.stoneCount;
|
||||||
|
oppositePit.stoneCount = 0;
|
||||||
|
pit.stoneCount = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getOppositePitIndex(game: MancalaGame, index: number) {
|
|
||||||
return game.board.getPitIndexCircularly(
|
|
||||||
index + game.board.totalPitCount() / 2
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user