From: Benjamin Auder Date: Sat, 28 Mar 2020 20:02:47 +0000 (+0100) Subject: Fix Horde variant + a bug when socket is not ready in Hall and Game send() method X-Git-Url: https://git.auder.net/images/assets/js/parser.js?a=commitdiff_plain;h=5a187b07e221493931cf089bf85ef6db41d8b775;p=vchess.git Fix Horde variant + a bug when socket is not ready in Hall and Game send() method --- diff --git a/client/src/variants/Horde.js b/client/src/variants/Horde.js index e61803b3..6305c412 100644 --- a/client/src/variants/Horde.js +++ b/client/src/variants/Horde.js @@ -39,13 +39,27 @@ export class HordeRules extends ChessRules { if (randomness == 2) randomness--; const fen = ChessRules.GenRandInitFen(randomness); return ( - // 27 first chars are 3 rows + 3 slashes - fen.substr(0, 27) + // 20 first chars are 3 rows + 3 slashes + fen.substr(0, 20) // En passant available, but no castle: .concat("1PP2PP1/PPPPPPPP/PPPPPPPP/PPPPPPPP/PPPPPPPP w 0 -") ); } + filterValid(moves) { + if (this.turn == 'w') return moves; + return super.filterValid(moves); + } + + getCheckSquares(color) { + if (color == 'w') return []; + return ( + this.underCheck('b') + ? [JSON.parse(JSON.stringify(this.kingPos['b']))] + : [] + ); + } + getCurrentScore() { if (this.turn == 'w') { // Do I have any unit remaining? If not, I lost. diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue index fe55f743..19033f50 100644 --- a/client/src/views/Game.vue +++ b/client/src/views/Game.vue @@ -372,7 +372,7 @@ export default { } }, send: function(code, obj) { - if (!!this.conn) + if (!!this.conn && this.conn.readyState == 1) this.conn.send(JSON.stringify(Object.assign({ code: code }, obj))); }, isConnected: function(index) { diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue index 57557d49..ab5108e5 100644 --- a/client/src/views/Hall.vue +++ b/client/src/views/Hall.vue @@ -502,7 +502,7 @@ export default { document.getElementById("cadence").focus(); }, send: function(code, obj) { - if (!!this.conn) { + if (!!this.conn && this.conn.readyState == 1) { this.conn.send(JSON.stringify(Object.assign({ code: code }, obj))); } },