From 5a953429fde4975174ab40daf3152586c0089ef7 Mon Sep 17 00:00:00 2001 From: Yuki Takenaka Date: Thu, 21 Oct 2021 18:54:06 +0900 Subject: [PATCH] =?UTF-8?q?=E9=96=A2=E6=95=B0=E5=90=8D=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 2 +- src/model/othello.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index e6e86c2..131018c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,7 +11,7 @@ import { StoneCreator } from './model/stone'; const io = new IO(prompt); const othello = new Othello(board, new StoneCreator, new PlayerCreator, io); - othello.init(); + othello.start(); } catch (e) { const _e = e as Error; console.error(_e.message); diff --git a/src/model/othello.ts b/src/model/othello.ts index 52ab637..c0eb8c3 100644 --- a/src/model/othello.ts +++ b/src/model/othello.ts @@ -40,7 +40,7 @@ export class Othello { this.turnPlayer = this.player1; } - public init = async () => { + public start = async () => { try { const answer = await this.io.selectBoardSize(); this.board.init(answer); @@ -60,8 +60,9 @@ export class Othello { this.io.message(`先行は${this.turnPlayer.name}です`); // 2連続パスか盤面が一杯になるまで - while (this.pass < 2 && !this.board.isFull) { - await this.turn(); + while (this.pass < 2 && !this.board.isFull()) { + await this.playTurn(); + this.changeTurn(); } this.end(); @@ -89,7 +90,7 @@ export class Othello { this.turnPlayer = this.turnPlayer === this.player1 ? this.player2 : this.player1; }; - private turn = async () => { + private playTurn = async () => { this.io.showBoard(this.board); this.io.message(`${this.turnPlayer.name}の番`); @@ -117,7 +118,6 @@ export class Othello { console.log(`\n${_e.message}\n`); } } - this.changeTurn(); return; } } @@ -127,7 +127,6 @@ export class Othello { this.pass++; this.io.message(`${this.turnPlayer.name}は置けないのでパス`); - this.changeTurn(); }; // 全方向を見て裏返せる石を探す