projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Better margin on smartphones for preset challenges
[vchess.git]
/
client
/
src
/
base_rules.js
diff --git
a/client/src/base_rules.js
b/client/src/base_rules.js
index
aec119a
..
2bfdc99
100644
(file)
--- a/
client/src/base_rules.js
+++ b/
client/src/base_rules.js
@@
-197,14
+197,10
@@
export const ChessRules = class ChessRules {
const move = moveOrSquare;
const s = move.start,
e = move.end;
const move = moveOrSquare;
const s = move.start,
e = move.end;
- // NOTE: next conditions are first for Crazyhouse, and last for Checkered
- // TODO: Checkered exceptions are too weird and should move in its own file.
if (
if (
- move.vanish.length > 0 &&
Math.abs(s.x - e.x) == 2 &&
s.y == e.y &&
Math.abs(s.x - e.x) == 2 &&
s.y == e.y &&
- move.vanish[0].p == V.PAWN &&
- ["w", "b"].includes(move.vanish[0].c)
+ move.appear[0].p == V.PAWN
) {
return {
x: (s.x + e.x) / 2,
) {
return {
x: (s.x + e.x) / 2,
@@
-645,7
+641,6
@@
export const ChessRules = class ChessRules {
const firstRank = color == "w" ? sizeX - 1 : 0;
const startRank = color == "w" ? sizeX - 2 : 1;
const lastRank = color == "w" ? 0 : sizeX - 1;
const firstRank = color == "w" ? sizeX - 1 : 0;
const startRank = color == "w" ? sizeX - 2 : 1;
const lastRank = color == "w" ? 0 : sizeX - 1;
- const pawnColor = this.getColor(x, y); //can be different for checkered
// NOTE: next condition is generally true (no pawn on last rank)
if (x + shiftX >= 0 && x + shiftX < sizeX) {
// NOTE: next condition is generally true (no pawn on last rank)
if (x + shiftX >= 0 && x + shiftX < sizeX) {
@@
-658,7
+653,7
@@
export const ChessRules = class ChessRules {
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y], {
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y], {
- c:
pawnC
olor,
+ c:
c
olor,
p: piece
})
);
p: piece
})
);
@@
-683,7
+678,7
@@
export const ChessRules = class ChessRules {
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y + shiftY], {
for (let piece of finalPieces) {
moves.push(
this.getBasicMove([x, y], [x + shiftX, y + shiftY], {
- c:
pawnC
olor,
+ c:
c
olor,
p: piece
})
);
p: piece
})
);
@@
-1001,7
+996,7
@@
export const ChessRules = class ChessRules {
// After move is played, update variables + flags
updateVariables(move) {
let piece = undefined;
// After move is played, update variables + flags
updateVariables(move) {
let piece = undefined;
- // TODO: update variables before move is played, and just use this.turn
?
+ // TODO: update variables before move is played, and just use this.turn?
// (doesn't work in general, think MarseilleChess)
let c = undefined;
if (move.vanish.length >= 1) {
// (doesn't work in general, think MarseilleChess)
let c = undefined;
if (move.vanish.length >= 1) {
@@
-1133,16
+1128,18
@@
export const ChessRules = class ChessRules {
getComputerMove() {
const maxeval = V.INFINITY;
const color = this.turn;
getComputerMove() {
const maxeval = V.INFINITY;
const color = this.turn;
- // Some variants may show a bigger moves list to the human (Switching),
- // thus the argument "computer" below (which is generally ignored)
let moves1 = this.getAllValidMoves();
if (moves1.length == 0)
// TODO: this situation should not happen
return null;
let moves1 = this.getAllValidMoves();
if (moves1.length == 0)
// TODO: this situation should not happen
return null;
- // Rank moves using a min-max at depth 2
+ // Rank moves using a min-max at depth 2
(if search_depth >= 2!)
for (let i = 0; i < moves1.length; i++) {
for (let i = 0; i < moves1.length; i++) {
+ if (V.SEARCH_DEPTH == 1) {
+ moves1[i].eval = this.evalPosition();
+ continue;
+ }
// Initial self evaluation is very low: "I'm checkmated"
moves1[i].eval = (color == "w" ? -1 : 1) * maxeval;
this.play(moves1[i]);
// Initial self evaluation is very low: "I'm checkmated"
moves1[i].eval = (color == "w" ? -1 : 1) * maxeval;
this.play(moves1[i]);
@@
-1190,19
+1187,9
@@
export const ChessRules = class ChessRules {
});
// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; }));
});
// console.log(moves1.map(m => { return [this.getNotation(m), m.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[candidates[randInt(candidates.length)]];
-
// Skip depth 3+ if we found a checkmate (or if we are checkmated in 1...)
if (V.SEARCH_DEPTH >= 3 && Math.abs(moves1[0].eval) < V.THRESHOLD_MATE) {
// Skip depth 3+ if we found a checkmate (or if we are checkmated in 1...)
if (V.SEARCH_DEPTH >= 3 && Math.abs(moves1[0].eval) < V.THRESHOLD_MATE) {
- // From here, depth >= 3: may take a while, so we control time
- const timeStart = Date.now();
for (let i = 0; i < moves1.length; i++) {
for (let i = 0; i < moves1.length; i++) {
- if (Date.now() - timeStart >= 5000)
- //more than 5 seconds
- return currentBest; //depth 2 at least
this.play(moves1[i]);
// 0.1 * oldEval : heuristic to avoid some bad moves (not all...)
moves1[i].eval =
this.play(moves1[i]);
// 0.1 * oldEval : heuristic to avoid some bad moves (not all...)
moves1[i].eval =
@@
-1213,10
+1200,9
@@
export const ChessRules = 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);
});
- } else return currentBest;
-// console.log(moves1.map(m => { return [this.getNotation(m), m.eval]; }));
+ }
- candidates = [0];
+
let
candidates = [0];
for (let j = 1; j < moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
return moves1[candidates[randInt(candidates.length)]];
for (let j = 1; j < moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
return moves1[candidates[randInt(candidates.length)]];