Skip to content

Commit

Permalink
isFull関数の追加
Browse files Browse the repository at this point in the history
  • Loading branch information
takenaka committed Oct 21, 2021
1 parent e3eb71a commit 699e69c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/model/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IBoard {
canPutStone: (coodinate: Coodinate) => boolean;
getStone: (coodinate: Coodinate) => IStone | null;
countStone: (state: StoneState) => number;
isFull: () => boolean;
init: (number: number) => void;
}

Expand Down Expand Up @@ -94,4 +95,12 @@ export class Board implements IBoard {

return count;
};

public isFull = () => {
if (this.countStone('white') + this.countStone('black') < this.size ** 2) {
return false
}

return true;
}
}
7 changes: 1 addition & 6 deletions src/model/othello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class Othello {
private readonly io: IIO;
private turnPlayer: IPlayer;
private pass = 0;
private countStone = 0;

constructor(board: IBoard, stoneCreator: IStoneCreator, playerCreator: IPlayerCreator, io: IIO) {
this.board = board;
Expand Down Expand Up @@ -61,7 +60,7 @@ export class Othello {
this.io.message(`先行は${this.turnPlayer.name}です`);

// 2連続パスか盤面が一杯になるまで
while (this.pass < 2 && this.countStone < this.board.size ** 2) {
while (this.pass < 2 && !this.board.isFull) {
await this.turn();
}

Expand All @@ -84,10 +83,6 @@ export class Othello {
const stone = this.board.getStone(flipableStone);
stone?.flip();
});

const countWhiteStone = this.board.countStone('white');
const countBlackStone = this.board.countStone('black');
this.countStone = countWhiteStone + countBlackStone;
};

private changeTurn = () => {
Expand Down

0 comments on commit 699e69c

Please sign in to comment.