Skip to content
Snippets Groups Projects
Commit c6627262 authored by syuilo's avatar syuilo
Browse files

Refactor

parent 1a8d6e0a
No related branches found
No related tags found
No related merge requests found
......@@ -135,7 +135,7 @@ function onGameStarted(g) {
}
function onSet(x) {
o.put(x.color, x.pos, true);
o.put(x.color, x.pos);
if (x.next === botColor) {
think();
......@@ -157,17 +157,17 @@ function think() {
*/
const dive = (o: Othello, pos: number, alpha = -Infinity, beta = Infinity, depth = 0): number => {
// 試し打ち
const undo = o.put(o.turn, pos, true);
o.put(o.turn, pos);
const key = o.board.toString();
let cache = db[key];
if (cache) {
if (alpha >= cache.upper) {
o.undo(undo);
o.undo();
return cache.upper;
}
if (beta <= cache.lower) {
o.undo(undo);
o.undo();
return cache.lower;
}
alpha = Math.max(alpha, cache.lower);
......@@ -199,7 +199,7 @@ function think() {
}
// 巻き戻し
o.undo(undo);
o.undo();
// 接待なら自分が負けた方が高スコア
return isSettai
......@@ -225,7 +225,7 @@ function think() {
});
// 巻き戻し
o.undo(undo);
o.undo();
// ロセオならスコアを反転
if (game.settings.is_llotheo) score = -score;
......@@ -257,7 +257,7 @@ function think() {
}
// 巻き戻し
o.undo(undo);
o.undo();
if (value <= alpha) {
cache.upper = value;
......
......@@ -50,6 +50,8 @@ export default class Othello {
public prevPos = -1;
public prevColor: Color = null;
private logs: Undo[] = [];
/**
* ゲームを初期化します
*/
......@@ -138,13 +140,7 @@ export default class Othello {
* @param color 石の色
* @param pos 位置
*/
public put(color: Color, pos: number, fast = false): Undo {
if (!fast && !this.canPut(color, pos)) {
console.warn('can not put this position:', pos, color);
console.warn(this.board);
return null;
}
public put(color: Color, pos: number) {
this.prevPos = pos;
this.prevColor = color;
......@@ -160,14 +156,14 @@ export default class Othello {
const turn = this.turn;
this.calcTurn();
return {
this.logs.push({
color,
pos,
effects,
turn
};
});
this.calcTurn();
}
private calcTurn() {
......@@ -181,7 +177,8 @@ export default class Othello {
}
}
public undo(undo: Undo) {
public undo() {
const undo = this.logs.pop();
this.prevColor = undo.color;
this.prevPos = undo.pos;
this.board[undo.pos] = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment