diff --git a/src/core/Board.ts b/src/core/Board.ts index cdb17c6..0e383c1 100644 --- a/src/core/Board.ts +++ b/src/core/Board.ts @@ -35,9 +35,9 @@ export class Board { for (let index = 0; index < this.totalPitCount(); index++) { const pitType = this.getPitTypeByIndex(index); if (pitType === 'player1Pit' || pitType === 'player2Pit') { - pitArray[index] = new Pit(initialStoneCountInPits); + pitArray[index] = new Pit(index, initialStoneCountInPits); } else if (pitType === 'player1Bank' || pitType === 'player2Bank') { - pitArray[index] = new Bank(0); + pitArray[index] = new Bank(index, 0); } } return pitArray; diff --git a/src/core/Pit.ts b/src/core/Pit.ts index 5081e1b..a95aa68 100644 --- a/src/core/Pit.ts +++ b/src/core/Pit.ts @@ -1,7 +1,9 @@ export class Pit { + index: number; stoneCount: number; - constructor(stoneCount = 0) { + constructor(index: number, stoneCount = 0) { + this.index = index; this.stoneCount = stoneCount; } @@ -19,8 +21,8 @@ export class Pit { } export class Bank extends Pit { - constructor(stoneCount = 0) { - super(stoneCount); + constructor(index: number, stoneCount = 0) { + super(index, stoneCount); } override get isBank(): boolean { diff --git a/tests/Board.test.ts b/tests/Board.test.ts index f2e8df0..85ca668 100644 --- a/tests/Board.test.ts +++ b/tests/Board.test.ts @@ -1,6 +1,23 @@ import { Board } from '../src/core/Board'; 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', () => { const board = new Board(6, 4); expect(board.getPitTypeByIndex(0)).toBe('player1Pit');