projects
/
vchess.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
c605216
)
Add a soft timer to avoid spending much more than 5 seconds on a move
author
Benjamin Auder
<benjamin.auder@somewhere>
Tue, 27 Nov 2018 09:15:28 +0000
(10:15 +0100)
committer
Benjamin Auder
<benjamin.auder@somewhere>
Tue, 27 Nov 2018 09:15:28 +0000
(10:15 +0100)
TODO
patch
|
blob
|
blame
|
history
public/javascripts/base_rules.js
patch
|
blob
|
blame
|
history
public/javascripts/components/game.js
patch
|
blob
|
blame
|
history
public/javascripts/variants/Grand.js
patch
|
blob
|
blame
|
history
public/javascripts/variants/Wildebeest.js
patch
|
blob
|
blame
|
history
diff --git
a/TODO
b/TODO
index
372fb25
..
23b3412
100644
(file)
--- a/
TODO
+++ b/
TODO
@@
-1,4
+1,2
@@
For animation, moves should contains "moving" and "fading" maybe...
For animation, moves should contains "moving" and "fading" maybe...
-Depth 2 or 3 depending on variant and if we detect smartphone or not?
-(static get SEARCH_DEPTH() { return 2; })
-Sur page d'accueil lien "contact" avec mail + instrus en cas de bug
+(But it's really just for Magnetic chess)
diff --git
a/public/javascripts/base_rules.js
b/public/javascripts/base_rules.js
index
d4315c7
..
26c7447
100644
(file)
--- a/
public/javascripts/base_rules.js
+++ b/
public/javascripts/base_rules.js
@@
-800,9
+800,14
@@
class ChessRules
return VariantRules.INFINITY;
}
return VariantRules.INFINITY;
}
+ static get SEARCH_DEPTH() {
+ return 3; //2 for high branching factor, 4 for small (Loser chess)
+ }
+
// Assumption: at least one legal move
getComputerMove(moves1) //moves1 might be precomputed (Magnetic chess)
{
// Assumption: at least one legal move
getComputerMove(moves1) //moves1 might be precomputed (Magnetic chess)
{
+ this.shouldReturn = false;
const maxeval = VariantRules.INFINITY;
const color = this.turn;
if (!moves1)
const maxeval = VariantRules.INFINITY;
const color = this.turn;
if (!moves1)
@@
-834,21
+839,32
@@
class ChessRules
}
moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); });
}
moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); });
+ let candidates = [0]; //indices of candidates moves
+ for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
+ candidates.push(j);
+ let currentBest = moves1[_.sample(candidates, 1)];
+
// Skip depth 3 if we found a checkmate (or if we are checkmated in 1...)
// Skip depth 3 if we found a checkmate (or if we are checkmated in 1...)
- if (Math.abs(moves1[0].eval) < VariantRules.THRESHOLD_MATE)
+ if (VariantRules.SEARCH_DEPTH >= 3
+ && Math.abs(moves1[0].eval) < VariantRules.THRESHOLD_MATE)
{
// TODO: show current analyzed move for depth 3, allow stopping eval (return moves1[0])
for (let i=0; i<moves1.length; i++)
{
{
// TODO: show current analyzed move for depth 3, allow stopping eval (return moves1[0])
for (let i=0; i<moves1.length; i++)
{
+ if (this.shouldReturn)
+ return currentBest; //depth-2, minimum
this.play(moves1[i]);
// 0.1 * oldEval : heuristic to avoid some bad moves (not all...)
this.play(moves1[i]);
// 0.1 * oldEval : heuristic to avoid some bad moves (not all...)
- moves1[i].eval = 0.1*moves1[i].eval + this.alphabeta(2, -maxeval, maxeval);
+ moves1[i].eval = 0.1*moves1[i].eval +
+ this.alphabeta(VariantRules.SEARCH_DEPTH-1, -maxeval, maxeval);
this.undo(moves1[i]);
}
moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); });
}
this.undo(moves1[i]);
}
moves1.sort( (a,b) => { return (color=="w" ? 1 : -1) * (b.eval - a.eval); });
}
+ else
+ return currentBest;
- let candidates = [0]; //indices of candidates moves
+ candidates = [0];
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; }));
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; }));
diff --git
a/public/javascripts/components/game.js
b/public/javascripts/components/game.js
index
b0fde5e
..
1b216ef
100644
(file)
--- a/
public/javascripts/components/game.js
+++ b/
public/javascripts/components/game.js
@@
-649,6
+649,13
@@
Vue.component('my-game', {
},
playComputerMove: function() {
const timeStart = Date.now();
},
playComputerMove: function() {
const timeStart = Date.now();
+ const nbMoves = this.vr.moves.length; //using played moves to know if search finished
+ setTimeout(
+ () => {
+ const L = this.vr.moves.length;
+ if (nbMoves == L || !this.vr.moves[L-1].notation) //move search didn't finish
+ this.vr.shouldReturn = true;
+ }, 5000);
const compMove = this.vr.getComputerMove();
// (first move) HACK: avoid selecting elements before they appear on page:
const delay = Math.max(500-(Date.now()-timeStart), 0);
const compMove = this.vr.getComputerMove();
// (first move) HACK: avoid selecting elements before they appear on page:
const delay = Math.max(500-(Date.now()-timeStart), 0);
diff --git
a/public/javascripts/variants/Grand.js
b/public/javascripts/variants/Grand.js
index
faf7f63
..
f4e325d
100644
(file)
--- a/
public/javascripts/variants/Grand.js
+++ b/
public/javascripts/variants/Grand.js
@@
-202,6
+202,8
@@
class GrandRules extends ChessRules
);
}
);
}
+ static get SEARCH_DEPTH() { return 2; }
+
// TODO: this function could be generalized and shared better
static GenRandInitFen()
{
// TODO: this function could be generalized and shared better
static GenRandInitFen()
{
diff --git
a/public/javascripts/variants/Wildebeest.js
b/public/javascripts/variants/Wildebeest.js
index
5f706cf
..
330db3f
100644
(file)
--- a/
public/javascripts/variants/Wildebeest.js
+++ b/
public/javascripts/variants/Wildebeest.js
@@
-155,6
+155,8
@@
class GrandRules extends ChessRules
);
}
);
}
+ static get SEARCH_DEPTH() { return 2; }
+
// TODO:
static GenRandInitFen()
{
// TODO:
static GenRandInitFen()
{