refactor : Board.move

This commit is contained in:
Halit Aksoy 2022-05-08 12:49:51 +03:00
parent a4afaf88b0
commit 2af530fe5c

View File

@ -97,21 +97,23 @@ export class Board {
} }
const stepCount = pit.stoneCount; const stepCount = pit.stoneCount;
this.pits[index].stoneCount = 0; this.pits[index].stoneCount = 0;
this.fireOnGameMoveStart(index); const startIndex = stepCount === 1 ? index + 1 : index;
if (stepCount === 1) { this.moveInternal(startIndex, stepCount);
this.fireOnGameMove(index); }
this.getNextPitCircularly(index).increaseStone();
const nextPitIndex = this.getNextPitIndexCircularly(index); private moveInternal(startIndex: number, stepCount: number) {
this.fireOnGameMove(nextPitIndex); this.fireOnGameMoveStart(startIndex);
this.fireOnGameMoveEnd(nextPitIndex); for (let i = startIndex; i < startIndex + stepCount; i++) {
} else { this.onGameMoveStep(i);
for (let i = 0; i < stepCount; i++) {
const pit = this.getPitCircularly(index + i);
pit.increaseStone();
this.fireOnGameMove(index + i);
}
this.fireOnGameMoveEnd(index + stepCount - 1);
} }
const stopIndex = startIndex + stepCount - 1;
this.fireOnGameMoveEnd(stopIndex);
}
public onGameMoveStep(index: number) {
const pit = this.pits[this.getPitIndexCircularly(index)];
pit.increaseStone();
this.fireOnGameMove(index);
} }
public getNextPitCircularly(currentPitIndex: number) { public getNextPitCircularly(currentPitIndex: number) {