X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fvariants%2FKoth.js;fp=client%2Fsrc%2Fvariants%2FKoth.js;h=e286862d9c360b8e8505a9ff1e1d4be4b5b5cbe6;hb=236485b53993f2adfd588022e2899a39491fc825;hp=0000000000000000000000000000000000000000;hpb=59e74176f5e2e828ce0b81c2ead6f8cdb0654f69;p=vchess.git diff --git a/client/src/variants/Koth.js b/client/src/variants/Koth.js new file mode 100644 index 00000000..e286862d --- /dev/null +++ b/client/src/variants/Koth.js @@ -0,0 +1,48 @@ +import { ChessRules } from "@/base_rules"; + +export class KothRules extends ChessRules { + filterValid(moves) { + if (moves.length == 0) return []; + const color = this.turn; + const oppCol = V.GetOppCol(color); + return moves.filter(m => { + this.play(m); + // Giving check is forbidden as well: + const res = !this.underCheck(color) && !this.underCheck(oppCol); + this.undo(m); + return res; + }); + } + + getCurrentScore() { + // Turn has changed: + const color = V.GetOppCol(this.turn); + if ( + [3,4].includes(this.kingPos[color][0]) && + [3,4].includes(this.kingPos[color][1]) + ) { + // The middle is reached! + return color == "w" ? "1-0" : "0-1"; + } + if (this.atLeastOneMove()) return "*"; + // Stalemate (will probably never happen) + return "1/2"; + } + + evalPosition() { + // Count material: + let evaluation = super.evalPosition(); + // Ponder with king position: + return ( + evaluation/5 + + ( + Math.abs(this.kingPos["w"][0] - 3.5) + + Math.abs(this.kingPos["w"][1] - 3.5) + ) / 2 - + ( + Math.abs(this.kingPos["b"][0] - 3.5) + + Math.abs(this.kingPos["b"][1] - 3.5) + ) / 2 + ); + } +};