From: Benjamin Auder Date: Wed, 12 Dec 2018 16:44:33 +0000 (+0100) Subject: Implement 'isAttackedBy' logic in Ultima; but is that required? X-Git-Url: https://git.auder.net/img/css/pieces/DESCRIPTION?a=commitdiff_plain;h=7aea79424d0c596e0a34e960c83847cc12b89e32;p=vchess.git Implement 'isAttackedBy' logic in Ultima; but is that required? --- diff --git a/public/javascripts/variants/Ultima.js b/public/javascripts/variants/Ultima.js index d6676436..b3679f71 100644 --- a/public/javascripts/variants/Ultima.js +++ b/public/javascripts/variants/Ultima.js @@ -370,35 +370,130 @@ class UltimaRules extends ChessRules isAttackedByPawn([x,y], colors) { // Square (x,y) must be surrounded by two enemy pieces, - // and one of them at least should be a pawn + // and one of them at least should be a pawn. + const dirs = [ [1,0],[0,1],[1,1],[-1,1] ]; + const [sizeX,sizeY] = VariantRules.size; + for (let dir of dirs) + { + const [i1,j1] = [x-dir[0],y-dir[1]]; //"before" + const [i2,j2] = [x+dir[0],y+dir[1]]; //"after" + if (i1>=0 && i1=0 && i2=0 && j1=0 && j2=0 && i0=0 && j0=0 && i=0 && j=0 && i=0 && j call the appropriate isAttackedBy... (exception of immobilizers) - // Other exception: a chameleon cannot attack a chameleon (seemingly...) + // We cheat a little here: since this function is used exclusively for king, + // it's enough to check the immediate surrounding of the square. + const V = VariantRules; + const adjacentSteps = V.steps[V.ROOK].concat(V.steps[V.BISHOP]); + const [sizeX,sizeY] = V.size; + for (let step of adjacentSteps) + { + const [i,j] = [x+step[0],y+step[1]]; + if (i>=0 && i=0 && j=0 && sq2[0]=0 && sq2[1]