add index to pit
This commit is contained in:
parent
5a4caca9a4
commit
4e5ce48b31
@ -35,9 +35,9 @@ export class Board {
|
|||||||
for (let index = 0; index < this.totalPitCount(); index++) {
|
for (let index = 0; index < this.totalPitCount(); index++) {
|
||||||
const pitType = this.getPitTypeByIndex(index);
|
const pitType = this.getPitTypeByIndex(index);
|
||||||
if (pitType === 'player1Pit' || pitType === 'player2Pit') {
|
if (pitType === 'player1Pit' || pitType === 'player2Pit') {
|
||||||
pitArray[index] = new Pit(initialStoneCountInPits);
|
pitArray[index] = new Pit(index, initialStoneCountInPits);
|
||||||
} else if (pitType === 'player1Bank' || pitType === 'player2Bank') {
|
} else if (pitType === 'player1Bank' || pitType === 'player2Bank') {
|
||||||
pitArray[index] = new Bank(0);
|
pitArray[index] = new Bank(index, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pitArray;
|
return pitArray;
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
export class Pit {
|
export class Pit {
|
||||||
|
index: number;
|
||||||
stoneCount: number;
|
stoneCount: number;
|
||||||
|
|
||||||
constructor(stoneCount = 0) {
|
constructor(index: number, stoneCount = 0) {
|
||||||
|
this.index = index;
|
||||||
this.stoneCount = stoneCount;
|
this.stoneCount = stoneCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,8 +21,8 @@ export class Pit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Bank extends Pit {
|
export class Bank extends Pit {
|
||||||
constructor(stoneCount = 0) {
|
constructor(index: number, stoneCount = 0) {
|
||||||
super(stoneCount);
|
super(index, stoneCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
override get isBank(): boolean {
|
override get isBank(): boolean {
|
||||||
|
|||||||
@ -1,6 +1,23 @@
|
|||||||
import { Board } from '../src/core/Board';
|
import { Board } from '../src/core/Board';
|
||||||
|
|
||||||
describe('Board Test', () => {
|
describe('Board Test', () => {
|
||||||
|
test('test pit index', () => {
|
||||||
|
const board = new Board(6, 4);
|
||||||
|
expect(board.pits[0].index).toBe(0);
|
||||||
|
expect(board.pits[1].index).toBe(1);
|
||||||
|
expect(board.pits[2].index).toBe(2);
|
||||||
|
expect(board.pits[3].index).toBe(3);
|
||||||
|
expect(board.pits[4].index).toBe(4);
|
||||||
|
expect(board.pits[5].index).toBe(5);
|
||||||
|
expect(board.pits[6].index).toBe(6);
|
||||||
|
expect(board.pits[7].index).toBe(7);
|
||||||
|
expect(board.pits[8].index).toBe(8);
|
||||||
|
expect(board.pits[9].index).toBe(9);
|
||||||
|
expect(board.pits[10].index).toBe(10);
|
||||||
|
expect(board.pits[11].index).toBe(11);
|
||||||
|
expect(board.pits[12].index).toBe(12);
|
||||||
|
expect(board.pits[13].index).toBe(13);
|
||||||
|
});
|
||||||
test('test getPitTypeByIndex', () => {
|
test('test getPitTypeByIndex', () => {
|
||||||
const board = new Board(6, 4);
|
const board = new Board(6, 4);
|
||||||
expect(board.getPitTypeByIndex(0)).toBe('player1Pit');
|
expect(board.getPitTypeByIndex(0)).toBe('player1Pit');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user