From: Benjamin Auder Date: Tue, 5 Feb 2019 23:25:09 +0000 (+0100) Subject: Play against computer almost OK: need to fix Board component X-Git-Url: https://git.auder.net/css/vendor/img/doc/html/up.jpg?a=commitdiff_plain;h=e27329232b83700d63c8fb52af6f4c2eec9a569c;p=vchess.git Play against computer almost OK: need to fix Board component --- diff --git a/client/package-lock.json b/client/package-lock.json index fe7eae3d..020d47e0 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -11774,6 +11774,16 @@ "errno": "~0.1.7" } }, + "worker-loader": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/worker-loader/-/worker-loader-2.0.0.tgz", + "integrity": "sha512-tnvNp4K3KQOpfRnD20m8xltE3eWh89Ye+5oj7wXEEHKac1P4oZ6p9oTj8/8ExqoSBnk9nu5Pr4nKfQ1hn2APJw==", + "dev": true, + "requires": { + "loader-utils": "^1.0.0", + "schema-utils": "^0.4.0" + } + }, "wrap-ansi": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", diff --git a/client/package.json b/client/package.json index 7f51be97..62781668 100644 --- a/client/package.json +++ b/client/package.json @@ -24,7 +24,8 @@ "pug-plain-loader": "^1.0.0", "raw-loader": "^1.0.0", "sass-loader": "^7.0.1", - "vue-template-compiler": "^2.5.21" + "vue-template-compiler": "^2.5.21", + "worker-loader": "^2.0.0" }, "eslintConfig": { "root": true, 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); diff --git a/client/src/components/Board.vue b/client/src/components/Board.vue index 51632312..32738829 100644 --- a/client/src/components/Board.vue +++ b/client/src/components/Board.vue @@ -1,13 +1,17 @@