1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-27 14:28:53 +09:00
This commit is contained in:
syuilo 2018-03-15 14:09:38 +09:00
parent 1a8d6e0a25
commit c662726259
2 changed files with 16 additions and 19 deletions

View File

@ -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;

View File

@ -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;