なんかもうめっちゃ変えた

This commit is contained in:
syuilo
2018-03-09 18:11:10 +09:00
parent caea9c91b9
commit 910ccf1804
7 changed files with 425 additions and 307 deletions

View File

@@ -1,5 +1,3 @@
import { Map } from './maps';
export type Color = 'black' | 'white';
export type MapPixel = 'null' | 'empty';
@@ -11,12 +9,14 @@ export type Options = {
* オセロエンジン
*/
export default class Othello {
public map: Map;
public mapData: MapPixel[];
public map: MapPixel[];
public mapWidth: number;
public mapHeight: number;
public board: Color[];
public turn: Color = 'black';
public opts: Options;
public prevPos = -1;
public stats: Array<{
b: number;
w: number;
@@ -25,18 +25,21 @@ export default class Othello {
/**
* ゲームを初期化します
*/
constructor(map: Map, opts: Options) {
this.map = map;
constructor(map: string[], opts: Options) {
this.opts = opts;
this.mapWidth = map[0].length;
this.mapHeight = map.length;
const mapData = map.join('');
// Parse map data
this.board = this.map.data.split('').map(d => {
this.board = mapData.split('').map(d => {
if (d == '-') return null;
if (d == 'b') return 'black';
if (d == 'w') return 'white';
return undefined;
});
this.mapData = this.map.data.split('').map(d => {
this.map = mapData.split('').map(d => {
if (d == '-' || d == 'b' || d == 'w') return 'empty';
return 'null';
});
@@ -48,8 +51,6 @@ export default class Othello {
}];
}
public prevPos = -1;
/**
* 黒石の数
*/
@@ -79,13 +80,13 @@ export default class Othello {
}
public transformPosToXy(pos: number): number[] {
const x = pos % this.map.size;
const y = Math.floor(pos / this.map.size);
const x = pos % this.mapWidth;
const y = Math.floor(pos / this.mapHeight);
return [x, y];
}
public transformXyToPos(x: number, y: number): number {
return x + (y * this.map.size);
return x + (y * this.mapHeight);
}
/**
@@ -145,8 +146,8 @@ export default class Othello {
* @param pos 位置
*/
public mapDataGet(pos: number): MapPixel {
if (pos < 0 || pos >= this.mapData.length) return 'null';
return this.mapData[pos];
if (pos < 0 || pos >= this.map.length) return 'null';
return this.map[pos];
}
/**
@@ -188,7 +189,7 @@ export default class Othello {
const found = [];
while (true) {
const [x, y] = fn(i);
if (x < 0 || y < 0 || x >= this.map.size || y >= this.map.size) break;
if (x < 0 || y < 0 || x >= this.mapWidth || y >= this.mapHeight) break;
const pos = this.transformXyToPos(x, y);
const pixel = this.mapDataGet(pos);
if (pixel == 'null') break;

View File

@@ -11,438 +11,502 @@
export type Map = {
name?: string;
category?: string;
size: number;
data: string;
author?: string;
data: string[];
};
export const fourfour: Map = {
name: '4x4',
category: '4x4',
size: 4,
data:
'----' +
'-wb-' +
'-bw-' +
data: [
'----',
'-wb-',
'-bw-',
'----'
]
};
export const sixsix: Map = {
name: '6x6',
category: '6x6',
size: 6,
data:
'------' +
'------' +
'--wb--' +
'--bw--' +
'------' +
data: [
'------',
'------',
'--wb--',
'--bw--',
'------',
'------'
]
};
export const roundedSixsix: Map = {
name: '6x6 rounded',
category: '6x6',
size: 6,
data:
' ---- ' +
'------' +
'--wb--' +
'--bw--' +
'------' +
author: 'syuilo',
data: [
' ---- ',
'------',
'--wb--',
'--bw--',
'------',
' ---- '
]
};
export const roundedSixsix2: Map = {
name: '6x6 rounded 2',
category: '6x6',
size: 6,
data:
' -- ' +
' ---- ' +
'--wb--' +
'--bw--' +
' ---- ' +
author: 'syuilo',
data: [
' -- ',
' ---- ',
'--wb--',
'--bw--',
' ---- ',
' -- '
]
};
export const eighteight: Map = {
name: '8x8',
category: '8x8',
size: 8,
data:
'--------' +
'--------' +
'--------' +
'---wb---' +
'---bw---' +
'--------' +
'--------' +
data: [
'--------',
'--------',
'--------',
'---wb---',
'---bw---',
'--------',
'--------',
'--------'
]
};
export const roundedEighteight: Map = {
name: '8x8 rounded',
category: '8x8',
size: 8,
data:
' ------ ' +
'--------' +
'--------' +
'---wb---' +
'---bw---' +
'--------' +
'--------' +
author: 'syuilo',
data: [
' ------ ',
'--------',
'--------',
'---wb---',
'---bw---',
'--------',
'--------',
' ------ '
]
};
export const roundedEighteight2: Map = {
name: '8x8 rounded 2',
category: '8x8',
size: 8,
data:
' ---- ' +
' ------ ' +
'--------' +
'---wb---' +
'---bw---' +
'--------' +
' ------ ' +
author: 'syuilo',
data: [
' ---- ',
' ------ ',
'--------',
'---wb---',
'---bw---',
'--------',
' ------ ',
' ---- '
]
};
export const roundedEighteight3: Map = {
name: '8x8 rounded 3',
category: '8x8',
size: 8,
data:
' -- ' +
' ---- ' +
' ------ ' +
'---wb---' +
'---bw---' +
' ------ ' +
' ---- ' +
author: 'syuilo',
data: [
' -- ',
' ---- ',
' ------ ',
'---wb---',
'---bw---',
' ------ ',
' ---- ',
' -- '
]
};
export const eighteightWithNotch: Map = {
name: '8x8 with notch',
category: '8x8',
size: 8,
data:
'--- ---' +
'--------' +
'--------' +
' --wb-- ' +
' --bw-- ' +
'--------' +
'--------' +
author: 'syuilo',
data: [
'--- ---',
'--------',
'--------',
' --wb-- ',
' --bw-- ',
'--------',
'--------',
'--- ---'
]
};
export const eighteightWithSomeHoles: Map = {
name: '8x8 with some holes',
category: '8x8',
size: 8,
data:
'--- ----' +
'----- --' +
'-- -----' +
'---wb---' +
'---bw- -' +
' -------' +
'--- ----' +
author: 'syuilo',
data: [
'--- ----',
'----- --',
'-- -----',
'---wb---',
'---bw- -',
' -------',
'--- ----',
'--------'
]
};
export const circle: Map = {
name: 'Circle',
category: '8x8',
size: 8,
data:
' -- ' +
' ------ ' +
' ------ ' +
'---wb---' +
'---bw---' +
' ------ ' +
' ------ ' +
author: 'syuilo',
data: [
' -- ',
' ------ ',
' ------ ',
'---wb---',
'---bw---',
' ------ ',
' ------ ',
' -- '
]
};
export const face: Map = {
name: 'Face',
export const smile: Map = {
name: 'Smile',
category: '8x8',
size: 8,
data:
' ------ ' +
'--------' +
'-- -- --' +
'---wb---' +
'-- bw --' +
'--- ---' +
'--------' +
author: 'syuilo',
data: [
' ------ ',
'--------',
'-- -- --',
'---wb---',
'-- bw --',
'--- ---',
'--------',
' ------ '
]
};
export const window: Map = {
name: 'Window',
category: '8x8',
size: 8,
data:
'--------' +
'- -- -' +
'- -- -' +
'---wb---' +
'---bw---' +
'- -- -' +
'- -- -' +
author: 'syuilo',
data: [
'--------',
'- -- -',
'- -- -',
'---wb---',
'---bw---',
'- -- -',
'- -- -',
'--------'
]
};
export const reserved: Map = {
name: 'Reserved',
category: '8x8',
size: 8,
data:
'w------b' +
'--------' +
'--------' +
'---wb---' +
'---bw---' +
'--------' +
'--------' +
author: 'Aya',
data: [
'w------b',
'--------',
'--------',
'---wb---',
'---bw---',
'--------',
'--------',
'b------w'
]
};
export const x: Map = {
name: 'X',
category: '8x8',
size: 8,
data:
'w------b' +
'-w----b-' +
'--w--b--' +
'---wb---' +
'---bw---' +
'--b--w--' +
'-b----w-' +
author: 'Aya',
data: [
'w------b',
'-w----b-',
'--w--b--',
'---wb---',
'---bw---',
'--b--w--',
'-b----w-',
'b------w'
]
};
export const minesweeper: Map = {
name: 'Minesweeper',
category: '8x8',
author: 'syuilo',
data: [
'b-b--w-w',
'-w-wb-b-',
'w-b--w-b',
'-b-wb-w-',
'-w-bw-b-',
'b-w--b-w',
'-b-bw-w-',
'w-w--b-b'
]
};
export const tenthtenth: Map = {
name: '10x10',
category: '10x10',
size: 10,
data:
'----------' +
'----------' +
'----------' +
'----------' +
'----wb----' +
'----bw----' +
'----------' +
'----------' +
'----------' +
data: [
'----------',
'----------',
'----------',
'----------',
'----wb----',
'----bw----',
'----------',
'----------',
'----------',
'----------'
]
};
export const hole: Map = {
name: 'The Hole',
category: '10x10',
size: 10,
data:
'----------' +
'----------' +
'--wb--wb--' +
'--bw--bw--' +
'---- ----' +
'---- ----' +
'--wb--wb--' +
'--bw--bw--' +
'----------' +
author: 'syuilo',
data: [
'----------',
'----------',
'--wb--wb--',
'--bw--bw--',
'---- ----',
'---- ----',
'--wb--wb--',
'--bw--bw--',
'----------',
'----------'
]
};
export const grid: Map = {
name: 'Grid',
category: '10x10',
size: 10,
data:
'----------' +
'- - -- - -' +
'----------' +
'- - -- - -' +
'----wb----' +
'----bw----' +
'- - -- - -' +
'----------' +
'- - -- - -' +
author: 'syuilo',
data: [
'----------',
'- - -- - -',
'----------',
'- - -- - -',
'----wb----',
'----bw----',
'- - -- - -',
'----------',
'- - -- - -',
'----------'
]
};
export const cross: Map = {
name: 'Cross',
category: '10x10',
size: 10,
data:
' ---- ' +
' ---- ' +
' ---- ' +
'----------' +
'----wb----' +
'----bw----' +
'----------' +
' ---- ' +
' ---- ' +
author: 'Aya',
data: [
' ---- ',
' ---- ',
' ---- ',
'----------',
'----wb----',
'----bw----',
'----------',
' ---- ',
' ---- ',
' ---- '
]
};
export const charX: Map = {
name: 'Char X',
category: '10x10',
author: 'syuilo',
data: [
'--- ---',
'---- ----',
'----------',
' -------- ',
' --wb-- ',
' --bw-- ',
' -------- ',
'----------',
'---- ----',
'--- ---'
]
};
export const charY: Map = {
name: 'Char Y',
category: '10x10',
author: 'syuilo',
data: [
'--- ---',
'---- ----',
'----------',
' -------- ',
' --wb-- ',
' --bw-- ',
' ------ ',
' ------ ',
' ------ ',
' ------ '
]
};
export const walls: Map = {
name: 'Walls',
category: '10x10',
size: 10,
data:
' bbbbbbbb ' +
'w--------w' +
'w--------w' +
'w--------w' +
'w---wb---w' +
'w---bw---w' +
'w--------w' +
'w--------w' +
'w--------w' +
author: 'Aya',
data: [
' bbbbbbbb ',
'w--------w',
'w--------w',
'w--------w',
'w---wb---w',
'w---bw---w',
'w--------w',
'w--------w',
'w--------w',
' bbbbbbbb '
]
};
export const checker: Map = {
name: 'Checker',
category: '10x10',
size: 10,
data:
'----------' +
'----------' +
'----------' +
'---wbwb---' +
'---bwbw---' +
'---wbwb---' +
'---bwbw---' +
'----------' +
'----------' +
author: 'Aya',
data: [
'----------',
'----------',
'----------',
'---wbwb---',
'---bwbw---',
'---wbwb---',
'---bwbw---',
'----------',
'----------',
'----------'
]
};
export const sixeight: Map = {
name: '6x8',
category: 'special',
size: 8,
data:
' ------ ' +
' ------ ' +
' ------ ' +
' --wb-- ' +
' --bw-- ' +
' ------ ' +
' ------ ' +
' ------ '
data: [
'------',
'------',
'------',
'--wb--',
'--bw--',
'------',
'------',
'------'
]
};
export const spark: Map = {
name: 'Spark',
category: 'special',
size: 10,
data:
' - - ' +
'----------' +
' -------- ' +
' -------- ' +
' ---wb--- ' +
' ---bw--- ' +
' -------- ' +
' -------- ' +
'----------' +
author: 'syuilo',
data: [
' - - ',
'----------',
' -------- ',
' -------- ',
' ---wb--- ',
' ---bw--- ',
' -------- ',
' -------- ',
'----------',
' - - '
]
};
export const islands: Map = {
name: 'Islands',
category: 'special',
size: 10,
data:
'-------- ' +
'---wb--- ' +
'---bw--- ' +
'-------- ' +
' - - ' +
' - - ' +
' --------' +
' --------' +
' --------' +
author: 'syuilo',
data: [
'-------- ',
'---wb--- ',
'---bw--- ',
'-------- ',
' - - ',
' - - ',
' --------',
' --------',
' --------',
' --------'
]
};
export const iphonex: Map = {
name: 'iPhone X',
category: 'special',
size: 12,
data:
' -- -- ' +
' -------- ' +
' -------- ' +
' -------- ' +
' -------- ' +
' ---wb--- ' +
' ---bw--- ' +
' -------- ' +
' -------- ' +
' -------- ' +
' -------- ' +
' ------ '
author: 'syuilo',
data: [
' -- -- ',
'--------',
'--------',
'--------',
'--------',
'---wb---',
'---bw---',
'--------',
'--------',
'--------',
'--------',
' ------ '
]
};
export const bigBoard: Map = {
name: 'Big board',
category: 'special',
size: 16,
data:
'----------------' +
'----------------' +
'----------------' +
'----------------' +
'----------------' +
'----------------' +
'----------------' +
'-------wb-------' +
'-------bw-------' +
'----------------' +
'----------------' +
'----------------' +
'----------------' +
'----------------' +
'----------------' +
data: [
'----------------',
'----------------',
'----------------',
'----------------',
'----------------',
'----------------',
'----------------',
'-------wb-------',
'-------bw-------',
'----------------',
'----------------',
'----------------',
'----------------',
'----------------',
'----------------',
'----------------'
]
};
export const twoBoard: Map = {
name: 'Two board',
category: 'special',
size: 17,
data:
'-------- --------' +
'-------- --------' +
'-------- --------' +
'---wb--- ---wb---' +
'---bw--- ---bw---' +
'-------- --------' +
'-------- --------' +
'-------- --------' +
' ' +
' ' +
' ' +
' ' +
' ' +
' ' +
' ' +
' ' +
' '
author: 'Aya',
data: [
'-------- --------',
'-------- --------',
'-------- --------',
'---wb--- ---wb---',
'---bw--- ---bw---',
'-------- --------',
'-------- --------',
'-------- --------'
]
};