X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fbase_rules.js;h=bb2edc43a0ab0dee402651f4d57edb65c5ab3101;hp=98c27af7d48b9cdfad2012a930db19a51a242e7d;hb=e27329232b83700d63c8fb52af6f4c2eec9a569c;hpb=c75838d9d5b52d1fbd3e419c5073ef0cfb95f40a diff --git a/client/src/base_rules.js b/client/src/base_rules.js index 98c27af7..bb2edc43 100644 --- a/client/src/base_rules.js +++ b/client/src/base_rules.js @@ -1,7 +1,10 @@ // (Orthodox) Chess rules are defined in ChessRules class. // Variants generally inherit from it, and modify some parts. -class PiPo //Piece+Position +import { ArrayFun } from "@/utils/array"; +import { random, sample, shuffle } from "@/utils/alea"; + +export const PiPo = class PiPo //Piece+Position { // o: {piece[p], color[c], posX[x], posY[y]} constructor(o) @@ -14,7 +17,7 @@ class PiPo //Piece+Position } // TODO: for animation, moves should contains "moving" and "fading" maybe... -class Move +export const Move = class Move { // o: {appear, vanish, [start,] [end,]} // appear,vanish = arrays of PiPo @@ -29,7 +32,7 @@ class Move } // NOTE: x coords = top to bottom; y = left to right (from white player perspective) -class ChessRules +export const ChessRules = class ChessRules { ////////////// // MISC UTILS @@ -236,7 +239,7 @@ class ChessRules // Shuffle pieces on first and last rank for (let c of ["w","b"]) { - let positions = range(8); + let positions = ArrayFun.range(8); // Get random squares for bishops let randIndex = 2 * random(4); @@ -374,7 +377,7 @@ class ChessRules static GetBoard(position) { const rows = position.split("/"); - let board = doubleArray(V.size.x, V.size.y, ""); + let board = ArrayFun.init(V.size.x, V.size.y, ""); for (let i=0; i= V.THRESHOLD_MATE);