summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAya Morisawa <AyaMorisawa4869@gmail.com>2018-09-06 03:02:52 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-09-06 03:02:52 +0900
commit498094b3c7d4fb80bf01fd2668c8244411a8a9fa (patch)
tree85d2a382382cf4bde330edb69e450a5153f35cf1 /src
parentResolve #2631 (#2632) (diff)
downloadmisskey-498094b3c7d4fb80bf01fd2668c8244411a8a9fa.tar.gz
misskey-498094b3c7d4fb80bf01fd2668c8244411a8a9fa.tar.bz2
misskey-498094b3c7d4fb80bf01fd2668c8244411a8a9fa.zip
Refactor reversi engine (#2633)
* Refactor reversi engine * Add puttablePlaces
Diffstat (limited to 'src')
-rw-r--r--src/games/reversi/core.ts19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/games/reversi/core.ts b/src/games/reversi/core.ts
index 34eb03becb..9199efa092 100644
--- a/src/games/reversi/core.ts
+++ b/src/games/reversi/core.ts
@@ -1,4 +1,4 @@
-import { count } from "../../prelude/array";
+import { count, countIf } from "../../prelude/array";
// MISSKEY REVERSI ENGINE
@@ -90,8 +90,8 @@ export default class Reversi {
//#endregion
// ゲームが始まった時点で片方の色の石しかないか、始まった時点で勝敗が決定するようなマップの場合がある
- if (this.canPutSomewhere(BLACK).length == 0) {
- if (this.canPutSomewhere(WHITE).length == 0) {
+ if (!this.canPutSomewhere(BLACK)) {
+ if (!this.canPutSomewhere(WHITE)) {
this.turn = null;
} else {
this.turn = WHITE;
@@ -172,9 +172,9 @@ export default class Reversi {
private calcTurn() {
// ターン計算
- if (this.canPutSomewhere(!this.prevColor).length > 0) {
+ if (this.canPutSomewhere(!this.prevColor)) {
this.turn = !this.prevColor;
- } else if (this.canPutSomewhere(this.prevColor).length > 0) {
+ } else if (this.canPutSomewhere(this.prevColor)) {
this.turn = this.prevColor;
} else {
this.turn = null;
@@ -206,11 +206,18 @@ export default class Reversi {
/**
* 打つことができる場所を取得します
*/
- public canPutSomewhere(color: Color): number[] {
+ public puttablePlaces(color: Color): number[] {
return Array.from(this.board.keys()).filter(i => this.canPut(color, i));
}
/**
+ * 打つことができる場所があるかどうかを取得します
+ */
+ public canPutSomewhere(color: Color): boolean {
+ return this.puttablePlaces(color).length > 0;
+ }
+
+ /**
* 指定のマスに石を打つことができるかどうかを取得します
* @param color 自分の色
* @param pos 位置