From 40735ce76bbe727eb9c87475d71e19506e5aad0d Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Thu, 6 Sep 2018 19:28:52 +0900 Subject: [PATCH 1/9] Fix bug (#2638) --- src/games/reversi/core.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/games/reversi/core.ts b/src/games/reversi/core.ts index 9199efa09..481b5b0f7 100644 --- a/src/games/reversi/core.ts +++ b/src/games/reversi/core.ts @@ -110,7 +110,7 @@ export default class Reversi { * 白石の数 */ public get whiteCount() { - return count(BLACK, this.board); + return count(WHITE, this.board); } /** From a1b026239e8d38ae1c25bdeb59086551bbac0397 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 6 Sep 2018 19:55:20 +0900 Subject: [PATCH 2/9] fix(package): update @types/ws to version 6.0.1 (#2636) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 60c6a0978..3aa41cd50 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "@types/webpack": "4.4.11", "@types/webpack-stream": "3.2.10", "@types/websocket": "0.0.40", - "@types/ws": "6.0.0", + "@types/ws": "6.0.1", "animejs": "2.2.0", "autosize": "4.0.2", "autwh": "0.1.0", From 5dd2feba9bf12598eb240e3ece1844124392917d Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Thu, 6 Sep 2018 19:55:29 +0900 Subject: [PATCH 3/9] fix(package): update @types/minio to version 7.0.0 (#2626) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3aa41cd50..811a60814 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "@types/koa-send": "4.1.1", "@types/koa-views": "2.0.3", "@types/koa__cors": "2.2.3", - "@types/minio": "6.0.2", + "@types/minio": "7.0.0", "@types/mkdirp": "0.5.2", "@types/mocha": "5.2.3", "@types/mongodb": "3.1.4", From f428372869461cf350c0e0cd21c41312a3e0f56f Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Thu, 6 Sep 2018 20:06:16 +0900 Subject: [PATCH 4/9] Refactor effects function (#2639) --- src/games/reversi/core.ts | 90 +++++++++++++-------------------------- tslint.json | 1 + 2 files changed, 30 insertions(+), 61 deletions(-) diff --git a/src/games/reversi/core.ts b/src/games/reversi/core.ts index 481b5b0f7..e2a2289f1 100644 --- a/src/games/reversi/core.ts +++ b/src/games/reversi/core.ts @@ -238,87 +238,55 @@ export default class Reversi { /** * 指定のマスに石を置いた時の、反転させられる石を取得します * @param color 自分の色 - * @param pos 位置 + * @param initPos 位置 */ - public effects(color: Color, pos: number): number[] { + public effects(color: Color, initPos: number): number[] { const enemyColor = !color; - // ひっくり返せる石(の位置)リスト - let stones: number[] = []; + const diffVectors: [number, number][] = [ + [ 0, -1], // 上 + [ +1, -1], // 右上 + [ +1, 0], // 右 + [ +1, +1], // 右下 + [ 0, +1], // 下 + [ -1, +1], // 左下 + [ -1, 0], // 左 + [ -1, -1] // 左上 + ]; - const initPos = pos; - - // 走査 - const iterate = (fn: (i: number) => number[]) => { - let i = 1; - const found = []; + const effectsInLine = ([dx, dy]: [number, number]): number[] => { + const nextPos = (x: number, y: number): [number, number] => [x + dx, y + dy]; + const found: number[] = []; // 挟めるかもしれない相手の石を入れておく配列 + let [x, y] = this.transformPosToXy(initPos); while (true) { - let [x, y] = fn(i); - // 座標が指し示す位置がボード外に出たとき if (this.opts.loopedBoard) { - if (x < 0 ) x = this.mapWidth - ((-x) % this.mapWidth); - if (y < 0 ) y = this.mapHeight - ((-y) % this.mapHeight); - if (x >= this.mapWidth ) x = x % this.mapWidth; - if (y >= this.mapHeight) y = y % this.mapHeight; + x = ((x % this.mapWidth) + this.mapWidth) % this.mapWidth; + y = ((y % this.mapHeight) + this.mapHeight) % this.mapHeight; - // for debug - //if (x < 0 || y < 0 || x >= this.mapWidth || y >= this.mapHeight) { - // console.log(x, y); - //} - - // 一周して自分に帰ってきたら if (this.transformXyToPos(x, y) == initPos) { - // ↓のコメントアウトを外すと、「現時点で自分の石が隣接していないが、 - // そこに置いたとするとループして最終的に挟んだことになる」というケースを有効化します。(Test4のマップで違いが分かります) - // このケースを有効にした方が良いのか無効にした方が良いのか判断がつかなかったためとりあえず無効としておきます - // (あと無効な方がゲームとしておもしろそうだった) - stones = stones.concat(found); - break; + // 盤面の境界でループし、自分が石を置く位置に戻ってきたとき、挟めるようにしている (ref: Test4のマップ) + return found; } } else { - if (x == -1 || y == -1 || x == this.mapWidth || y == this.mapHeight) break; + if (x == -1 || y == -1 || x == this.mapWidth || y == this.mapHeight) { + return []; // 挟めないことが確定 (盤面外に到達) + } } const pos = this.transformXyToPos(x, y); - - //#region 「配置不能」マスに当たった場合走査終了 - const pixel = this.mapDataGet(pos); - if (pixel == 'null') break; - //#endregion - - // 石取得 + if (this.mapDataGet(pos) === 'null') return []; // 挟めないことが確定 (配置不可能なマスに到達) const stone = this.board[pos]; + if (stone === null) return []; // 挟めないことが確定 (石が置かれていないマスに到達) + if (stone === enemyColor) found.push(pos); // 挟めるかもしれない (相手の石を発見) + if (stone === color) return found; // 挟めることが確定 (対となる自分の石を発見) - // 石が置かれていないマスなら走査終了 - if (stone === null) break; - - // 相手の石なら「ひっくり返せるかもリスト」に入れておく - if (stone === enemyColor) found.push(pos); - - // 自分の石なら「ひっくり返せるかもリスト」を「ひっくり返せるリスト」に入れ、走査終了 - if (stone === color) { - stones = stones.concat(found); - break; - } - - i++; + [x, y] = nextPos(x, y); } }; - const [x, y] = this.transformPosToXy(pos); - - iterate(i => [x , y - i]); // 上 - iterate(i => [x + i, y - i]); // 右上 - iterate(i => [x + i, y ]); // 右 - iterate(i => [x + i, y + i]); // 右下 - iterate(i => [x , y + i]); // 下 - iterate(i => [x - i, y + i]); // 左下 - iterate(i => [x - i, y ]); // 左 - iterate(i => [x - i, y - i]); // 左上 - - return stones; + return [].concat(...diffVectors.map(effectsInLine)); } /** diff --git a/tslint.json b/tslint.json index ae0df46b9..1adc0a2ae 100644 --- a/tslint.json +++ b/tslint.json @@ -17,6 +17,7 @@ "no-empty":false, "ordered-imports": [false], "arrow-parens": false, + "array-type": false, "object-literal-shorthand": false, "object-literal-key-quotes": false, "triple-equals": [false], From 3cace734c70c752c57ed9a0057aef4d7ef788528 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Thu, 6 Sep 2018 21:31:15 +0900 Subject: [PATCH 5/9] Add concat function (#2640) --- src/client/app/desktop/views/pages/welcome.vue | 5 +++-- src/client/app/mobile/views/pages/welcome.vue | 5 +++-- src/games/reversi/core.ts | 4 ++-- src/prelude/array.ts | 8 ++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/client/app/desktop/views/pages/welcome.vue b/src/client/app/desktop/views/pages/welcome.vue index 0138fde27..7409f6c9b 100644 --- a/src/client/app/desktop/views/pages/welcome.vue +++ b/src/client/app/desktop/views/pages/welcome.vue @@ -85,6 +85,7 @@