どこでも置けるモード実装
This commit is contained in:
		
							parent
							
								
									8b0162a458
								
							
						
					
					
						commit
						c8bf30d0d8
					
				
					 5 changed files with 27 additions and 7 deletions
				
			
		| 
						 | 
					@ -30,6 +30,7 @@ export interface IGame {
 | 
				
			||||||
		map: string[];
 | 
							map: string[];
 | 
				
			||||||
		bw: string | number;
 | 
							bw: string | number;
 | 
				
			||||||
		is_llotheo: boolean;
 | 
							is_llotheo: boolean;
 | 
				
			||||||
 | 
							can_put_everywhere: boolean;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,7 +125,8 @@ export default function(request: websocket.request, connection: websocket.connec
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				//#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理
 | 
									//#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理
 | 
				
			||||||
				const o = new Othello(map, {
 | 
									const o = new Othello(map, {
 | 
				
			||||||
					isLlotheo: freshGame.settings.is_llotheo
 | 
										isLlotheo: freshGame.settings.is_llotheo,
 | 
				
			||||||
 | 
										canPutEverywhere: freshGame.settings.can_put_everywhere
 | 
				
			||||||
				});
 | 
									});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (o.isEnded) {
 | 
									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;
 | 
							if (!game.user1_id.equals(user._id) && !game.user2_id.equals(user._id)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const o = new Othello(game.settings.map, {
 | 
							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 => {
 | 
							game.logs.forEach(log => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ export type MapPixel = 'null' | 'empty';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type Options = {
 | 
					export type Options = {
 | 
				
			||||||
	isLlotheo: boolean;
 | 
						isLlotheo: boolean;
 | 
				
			||||||
 | 
						canPutEverywhere: boolean;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -26,23 +27,29 @@ export default class Othello {
 | 
				
			||||||
	 * ゲームを初期化します
 | 
						 * ゲームを初期化します
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	constructor(map: string[], opts: Options) {
 | 
						constructor(map: string[], opts: Options) {
 | 
				
			||||||
 | 
							//#region Options
 | 
				
			||||||
		this.opts = opts;
 | 
							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.mapWidth = map[0].length;
 | 
				
			||||||
		this.mapHeight = map.length;
 | 
							this.mapHeight = map.length;
 | 
				
			||||||
		const mapData = map.join('');
 | 
							const mapData = map.join('');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Parse map data
 | 
					 | 
				
			||||||
		this.board = mapData.split('').map(d => {
 | 
							this.board = mapData.split('').map(d => {
 | 
				
			||||||
			if (d == '-') return null;
 | 
								if (d == '-') return null;
 | 
				
			||||||
			if (d == 'b') return 'black';
 | 
								if (d == 'b') return 'black';
 | 
				
			||||||
			if (d == 'w') return 'white';
 | 
								if (d == 'w') return 'white';
 | 
				
			||||||
			return undefined;
 | 
								return undefined;
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		this.map = mapData.split('').map(d => {
 | 
							this.map = mapData.split('').map(d => {
 | 
				
			||||||
			if (d == '-' || d == 'b' || d == 'w') return 'empty';
 | 
								if (d == '-' || d == 'b' || d == 'w') return 'empty';
 | 
				
			||||||
			return 'null';
 | 
								return 'null';
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
							//#endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Init stats
 | 
							// Init stats
 | 
				
			||||||
		this.stats = [{
 | 
							this.stats = [{
 | 
				
			||||||
| 
						 | 
					@ -175,14 +182,21 @@ export default class Othello {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * 指定のマスに石を打つことができるかどうか(相手の石を1つでも反転させられるか)を取得します
 | 
						 * 指定のマスに石を打つことができるかどうかを取得します
 | 
				
			||||||
	 * @param color 自分の色
 | 
						 * @param color 自分の色
 | 
				
			||||||
	 * @param pos 位置
 | 
						 * @param pos 位置
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public canPut(color: Color, pos: number): boolean {
 | 
						public canPut(color: Color, pos: number): boolean {
 | 
				
			||||||
		// 既に石が置いてある場所には打てない
 | 
							// 既に石が置いてある場所には打てない
 | 
				
			||||||
		if (this.get(pos) !== null) return false;
 | 
							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;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,7 +89,8 @@ export default Vue.extend({
 | 
				
			||||||
		logPos(v) {
 | 
							logPos(v) {
 | 
				
			||||||
			if (!this.game.is_ended) return;
 | 
								if (!this.game.is_ended) return;
 | 
				
			||||||
			this.o = new Othello(this.game.settings.map, {
 | 
								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) => {
 | 
								this.logs.forEach((log, i) => {
 | 
				
			||||||
				if (i < v) {
 | 
									if (i < v) {
 | 
				
			||||||
| 
						 | 
					@ -102,7 +103,8 @@ export default Vue.extend({
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	created() {
 | 
						created() {
 | 
				
			||||||
		this.o = new Othello(this.game.settings.map, {
 | 
							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 => {
 | 
							this.game.logs.forEach(log => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -26,6 +26,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	<div class="rules">
 | 
						<div class="rules">
 | 
				
			||||||
		<mk-switch v-model="game.settings.is_llotheo" @change="updateSettings" text="石の少ない方が勝ち(ロセオ)"/>
 | 
							<mk-switch v-model="game.settings.is_llotheo" @change="updateSettings" text="石の少ない方が勝ち(ロセオ)"/>
 | 
				
			||||||
 | 
							<mk-switch v-model="game.settings.can_put_everywhere" @change="updateSettings" text="どこでも置けるモード"/>
 | 
				
			||||||
		<div>
 | 
							<div>
 | 
				
			||||||
			<el-radio v-model="game.settings.bw" label="random" @change="updateSettings">ランダム</el-radio>
 | 
								<el-radio v-model="game.settings.bw" label="random" @change="updateSettings">ランダム</el-radio>
 | 
				
			||||||
			<el-radio v-model="game.settings.bw" :label="1" @change="updateSettings">{{ game.user1.name }}が黒</el-radio>
 | 
								<el-radio v-model="game.settings.bw" :label="1" @change="updateSettings">{{ game.user1.name }}が黒</el-radio>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue