// Variants generally inherit from it, and modify some parts.
import { ArrayFun } from "@/utils/array";
-import { random, sample, shuffle } from "@/utils/alea";
+import { randInt, sample, shuffle } from "@/utils/alea";
export const PiPo = class PiPo //Piece+Position
{
let positions = ArrayFun.range(8);
// Get random squares for bishops
- let randIndex = 2 * random(4);
+ let randIndex = 2 * randInt(4);
const bishop1Pos = positions[randIndex];
// The second bishop must be on a square of different color
- let randIndex_tmp = 2 * random(4) + 1;
+ let randIndex_tmp = 2 * randInt(4) + 1;
const bishop2Pos = positions[randIndex_tmp];
// Remove chosen squares
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
// Get random squares for knights
- randIndex = random(6);
+ randIndex = randInt(6);
const knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(5);
+ randIndex = randInt(5);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
// Get random square for queen
- randIndex = random(4);
+ randIndex = randInt(4);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
candidates.push(j);
let currentBest = moves1[sample(candidates)];
- // From here, depth >= 3: may take a while, so we control time
- const timeStart = Date.now();
-
// 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++)
{
if (Date.now()-timeStart >= 5000) //more than 5 seconds
candidates = [0];
for (let j=1; j<moves1.length && moves1[j].eval == moves1[0].eval; j++)
candidates.push(j);
- return moves1[sample(candidates)];
+ return moves1[candidates[randInt(candidates.length)]];
}
alphabeta(depth, alpha, beta)
.toUpperCase();
}
-export function random (min, max)
+export function randInt(min, max)
{
if (!max)
{
let cpArr = arr.map(e => e);
for (let index = 0; index < n; index++)
{
- const rand = random(index, n);
+ const rand = randInt(index, arr.length);
const temp = cpArr[index];
cpArr[index] = cpArr[rand];
cpArr[rand] = temp;
// Get random squares for bishops, but avoid corners; because,
// if an antiking blocks a cornered bishop, it can never be checkmated
- let randIndex = 2 * random(1,4);
+ let randIndex = 2 * randInt(1,4);
const bishop1Pos = positions[randIndex];
- let randIndex_tmp = 2 * random(3) + 1;
+ let randIndex_tmp = 2 * randInt(3) + 1;
const bishop2Pos = positions[randIndex_tmp];
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
- randIndex = random(6);
+ randIndex = randInt(6);
const knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(5);
+ randIndex = randInt(5);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(4);
+ randIndex = randInt(4);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
const rook2Pos = positions[2];
// Random squares for antikings
- antikingPos[c] = random(8);
+ antikingPos[c] = randInt(8);
pieces[c][rook1Pos] = 'r';
pieces[c][knight1Pos] = 'n';
let positions = range(8);
// Get random squares for every piece, totally freely
- let randIndex = random(8);
+ let randIndex = randInt(8);
const bishop1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(7);
+ randIndex = randInt(7);
const bishop2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(6);
+ randIndex = randInt(6);
const knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(5);
+ randIndex = randInt(5);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(4);
+ randIndex = randInt(4);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(3);
+ randIndex = randInt(3);
const kingPos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(2);
+ randIndex = randInt(2);
const rookPos = positions[randIndex];
positions.splice(randIndex, 1);
const immobilizerPos = positions[0];
let positions = range(10);
// Get random squares for bishops
- let randIndex = 2 * random(5);
+ let randIndex = 2 * randInt(5);
let bishop1Pos = positions[randIndex];
// The second bishop must be on a square of different color
- let randIndex_tmp = 2 * random(5) + 1;
+ let randIndex_tmp = 2 * randInt(5) + 1;
let bishop2Pos = positions[randIndex_tmp];
// Remove chosen squares
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
// Get random squares for knights
- randIndex = random(8);
+ randIndex = randInt(8);
let knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(7);
+ randIndex = randInt(7);
let knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
// Get random square for queen
- randIndex = random(6);
+ randIndex = randInt(6);
let queenPos = positions[randIndex];
positions.splice(randIndex, 1);
// ...random square for marshall
- randIndex = random(5);
+ randIndex = randInt(5);
let marshallPos = positions[randIndex];
positions.splice(randIndex, 1);
// ...random square for cardinal
- randIndex = random(4);
+ randIndex = randInt(4);
let cardinalPos = positions[randIndex];
positions.splice(randIndex, 1);
let positions = range(8);
// Get random squares for bishops
- let randIndex = 2 * random(4);
+ let randIndex = 2 * randInt(4);
let bishop1Pos = positions[randIndex];
// The second bishop must be on a square of different color
- let randIndex_tmp = 2 * random(4) + 1;
+ let randIndex_tmp = 2 * randInt(4) + 1;
let bishop2Pos = positions[randIndex_tmp];
// Remove chosen squares
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
// Get random squares for knights
- randIndex = random(6);
+ randIndex = randInt(6);
let knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(5);
+ randIndex = randInt(5);
let knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
// Get random square for queen
- randIndex = random(4);
+ randIndex = randInt(4);
let queenPos = positions[randIndex];
positions.splice(randIndex, 1);
// Random square for king (no castle)
- randIndex = random(3);
+ randIndex = randInt(3);
let kingPos = positions[randIndex];
positions.splice(randIndex, 1);
{
let positions = range(8);
- let randIndex = random(8);
+ let randIndex = randInt(8);
const kingPos = positions[randIndex];
positions.splice(randIndex, 1);
else if (kingPos == V.size.y-1)
knight1Pos = V.size.y-2;
else
- knight1Pos = kingPos + (Math.random() < 0.5 ? 1 : -1);
+ knight1Pos = kingPos + (Math.randInt() < 0.5 ? 1 : -1);
// Search for knight1Pos index in positions and remove it
const knight1Index = positions.indexOf(knight1Pos);
positions.splice(knight1Index, 1);
// King+knight1 are on two consecutive squares: one light, one dark
- randIndex = 2 * random(3);
+ randIndex = 2 * randInt(3);
const bishop1Pos = positions[randIndex];
- let randIndex_tmp = 2 * random(3) + 1;
+ let randIndex_tmp = 2 * randInt(3) + 1;
const bishop2Pos = positions[randIndex_tmp];
positions.splice(Math.max(randIndex,randIndex_tmp), 1);
positions.splice(Math.min(randIndex,randIndex_tmp), 1);
- randIndex = random(4);
+ randIndex = randInt(4);
const knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(3);
+ randIndex = randInt(3);
const queenPos = positions[randIndex];
positions.splice(randIndex, 1);
positions.splice(idx, 1);
}
- let randIndex = random(7);
+ let randIndex = randInt(7);
let knight1Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(6);
+ randIndex = randInt(6);
let knight2Pos = positions[randIndex];
positions.splice(randIndex, 1);
- randIndex = random(5);
+ randIndex = randInt(5);
let queenPos = positions[randIndex];
positions.splice(randIndex, 1);
// Random square for wildebeest
- randIndex = random(4);
+ randIndex = randInt(4);
let wildebeestPos = positions[randIndex];
positions.splice(randIndex, 1);
h3#abortBoxTitle.section {{ st.tr["Terminate game?"] }}
button(@click="abortGame") {{ st.tr["Sorry I have to go"] }}
button(@click="abortGame") {{ st.tr["Game seems over"] }}
+ button(@click="abortGame") {{ st.tr["Opponent is gone"] }}
BaseGame(:game="game" :vr="vr" ref="basegame"
@newmove="processMove" @gameover="gameOver")
div Names: {{ game.players[0].name }} - {{ game.players[1].name }}