From c8bf30d0d8d8d88ab738f6377ad9b65c961b5d4f Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 10 Mar 2018 18:22:54 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=A9=E3=81=93=E3=81=A7=E3=82=82=E7=BD=AE?= =?UTF-8?q?=E3=81=91=E3=82=8B=E3=83=A2=E3=83=BC=E3=83=89=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/models/othello-game.ts | 1 + src/api/stream/othello-game.ts | 6 ++++-- src/common/othello/core.ts | 20 ++++++++++++++++--- .../common/views/components/othello.game.vue | 6 ++++-- .../common/views/components/othello.room.vue | 1 + 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/api/models/othello-game.ts b/src/api/models/othello-game.ts index 82c004210..b9d33007b 100644 --- a/src/api/models/othello-game.ts +++ b/src/api/models/othello-game.ts @@ -30,6 +30,7 @@ export interface IGame { map: string[]; bw: string | number; is_llotheo: boolean; + can_put_everywhere: boolean; }; } diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts index cc936805b..05f244f76 100644 --- a/src/api/stream/othello-game.ts +++ b/src/api/stream/othello-game.ts @@ -125,7 +125,8 @@ export default function(request: websocket.request, connection: websocket.connec //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理 const o = new Othello(map, { - isLlotheo: freshGame.settings.is_llotheo + isLlotheo: freshGame.settings.is_llotheo, + canPutEverywhere: freshGame.settings.can_put_everywhere }); if (o.isEnded) { @@ -166,7 +167,8 @@ export default function(request: websocket.request, connection: websocket.connec if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return; const o = new Othello(game.settings.map, { - isLlotheo: game.settings.is_llotheo + isLlotheo: game.settings.is_llotheo, + canPutEverywhere: game.settings.can_put_everywhere }); game.logs.forEach(log => { diff --git a/src/common/othello/core.ts b/src/common/othello/core.ts index fc432b2ce..851f1b79c 100644 --- a/src/common/othello/core.ts +++ b/src/common/othello/core.ts @@ -3,6 +3,7 @@ export type MapPixel = 'null' | 'empty'; export type Options = { isLlotheo: boolean; + canPutEverywhere: boolean; }; /** @@ -26,23 +27,29 @@ export default class Othello { * ゲームを初期化します */ constructor(map: string[], opts: Options) { + //#region Options this.opts = opts; + if (this.opts.isLlotheo == null) this.opts.isLlotheo = false; + if (this.opts.canPutEverywhere == null) this.opts.canPutEverywhere = false; + //#endregion + //#region Parse map data this.mapWidth = map[0].length; this.mapHeight = map.length; const mapData = map.join(''); - // Parse map data this.board = mapData.split('').map(d => { if (d == '-') return null; if (d == 'b') return 'black'; if (d == 'w') return 'white'; return undefined; }); + this.map = mapData.split('').map(d => { if (d == '-' || d == 'b' || d == 'w') return 'empty'; return 'null'; }); + //#endregion // Init stats this.stats = [{ @@ -175,14 +182,21 @@ export default class Othello { } /** - * 指定のマスに石を打つことができるかどうか(相手の石を1つでも反転させられるか)を取得します + * 指定のマスに石を打つことができるかどうかを取得します * @param color 自分の色 * @param pos 位置 */ public canPut(color: Color, pos: number): boolean { // 既に石が置いてある場所には打てない if (this.get(pos) !== null) return false; - return this.effects(color, pos).length !== 0; + + if (this.opts.canPutEverywhere) { + // 挟んでなくても置けるモード + return this.mapDataGet(pos) == 'empty'; + } else { + // 相手の石を1つでも反転させられるか + return this.effects(color, pos).length !== 0; + } } /** diff --git a/src/web/app/common/views/components/othello.game.vue b/src/web/app/common/views/components/othello.game.vue index 26612daea..fa3ed8d9a 100644 --- a/src/web/app/common/views/components/othello.game.vue +++ b/src/web/app/common/views/components/othello.game.vue @@ -89,7 +89,8 @@ export default Vue.extend({ logPos(v) { if (!this.game.is_ended) return; this.o = new Othello(this.game.settings.map, { - isLlotheo: this.game.settings.is_llotheo + isLlotheo: this.game.settings.is_llotheo, + canPutEverywhere: this.game.settings.can_put_everywhere }); this.logs.forEach((log, i) => { if (i < v) { @@ -102,7 +103,8 @@ export default Vue.extend({ created() { this.o = new Othello(this.game.settings.map, { - isLlotheo: this.game.settings.is_llotheo + isLlotheo: this.game.settings.is_llotheo, + canPutEverywhere: this.game.settings.can_put_everywhere }); this.game.logs.forEach(log => { diff --git a/src/web/app/common/views/components/othello.room.vue b/src/web/app/common/views/components/othello.room.vue index 745074b17..b7c28ae67 100644 --- a/src/web/app/common/views/components/othello.room.vue +++ b/src/web/app/common/views/components/othello.room.vue @@ -26,6 +26,7 @@
+
ランダム {{ game.user1.name }}が黒