caasinehc

Chess 2

Jan 18th, 2021 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.30 KB | None | 0 0
  1. Icebox$sProject{"name":"Chess","lastModified":1567381492691,"files":{"html":"{\"name\":\"index\",\"lastModified\":1567381492691,\"data\":\"<body>\\r\\n\\t<h1>Chess</h1>\\r\\n</body>\"}","css":["{\"name\":\"style\",\"lastModified\":1567381492694,\"data\":\"body$s{\\r\\n\\tbackground-color:$sgray;\\r\\n\\tfont-family:$s\\\"Arial\\\";\\r\\n}\"}"],"js":["{\"name\":\"code\",\"lastModified\":1567381492695,\"data\":\"/*\\n$s*$sChess\\n$s*$sa1.0.0\\n$s*$sBy$sIsaac$sChen\\n$s*$s1/15/2021\\n$s*/\\n\\n//$sConstants\\nconst$sRANKS$s=$s8;\\nconst$sFILES$s=$s8;\\nconst$sCOLOR_LIGHT$s=$s\\\"#F2DAB6\\\";\\nconst$sCOLOR_DARK$s=$s\\\"#B38662\\\";\\nconst$sTEAMS$s=$s{\\n\\tBLACK:$s\\\"black\\\",\\n\\tWHITE:$s\\\"white\\\"\\n};\\n\\n//$sPiece$ssprites\\nconst$sCHESSMEN_CBURNETT_SRC$s=$s\\\"https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Chess_Pieces_Sprite.svg/640px-Chess_Pieces_Sprite.svg.png\\\";\\nconst$sSPRITES$s=$screateImg(CHESSMEN_CBURNETT_SRC);\\n\\n//$sRepresents$sthe$scoordinates$sof$sa$schess$spiece\\nclass$sTilePos$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$sTilePos\\n\\t$s*$s\\n\\t$s*$s@param$srank$sa$spositive$sinteger$srepresenting$sthe$srank$s(column)\\n\\t$s*$s@param$sfile$sa$spositive$sinteger$srepresenting$sthe$sfile$s(row)\\n\\t$s*/\\n\\tconstructor(rank,$sfile)$s{\\n\\t\\tif(!Number.isInteger(rank)$s||$s!Number.isInteger(file)$s||$srank$s<$s1$s$s||$sfile$s<$s1)$s{\\n\\t\\t\\tthrow$snew$sError(\\\"Error$sin$sTilePos():$sboth$srank$sand$sfile$smust$sbe$spositive$sintegers!\\\");\\n\\t\\t}\\n\\t\\t\\n\\t\\tthis.rank$s=$srank;\\n\\t\\tthis.file$s=$sfile;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$swhether$sor$snot$sthis$sTilePos$sand$sanother$sare$sthe$ssame\\n\\t$s*$s@return$swhether$sor$snot$sthis$sTilePos$sand$sanother$sare$sthe$ssame\\n\\t$s*/\\n\\tequals(other)$s{\\n\\t\\treturn$sother$sinstanceof$sTilePos$s&&$sthis.rank$s===$sother.rank$s&&$sthis.file$s===$sother.file;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$sa$scopy$sof$sthis$sTilePos\\n\\t$s*$s@return$sa$scopy$sof$sthis$sTilePos\\n\\t$s*/\\n\\tcopy()$s{\\n\\t\\treturn$snew$sTilePos(this.rank,$sthis.file);\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$sthe$stile$sas$sa$sformatted$sstring$s(\\\"f3\\\",$sfor$sexample)\\n\\t$s*$s\\n\\t$s*$s@return$sthe$stile$sas$sa$sformatted$sstring$s(\\\"f3\\\",$sfor$sexample)\\n\\t$s*/\\n\\ttoString()$s{\\n\\t\\tconst$sfileStr$s=$sthis.file$s>$s26$s?$s`$${this.file},$s`$s:$s\\\"abcdefghijklmnopqrstuvwxyz\\\"[this.file$s-$s1];\\n\\t\\treturn$sfileStr$s+$sthis.rank;\\n\\t}\\n}\\n\\n//$sRepresents$sa$schess$spiece\\nclass$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$schess$spiece\\n\\t$s*$s\\n\\t$s*$s@param$sname$sthe$sname$sof$sthe$schess$spiece\\n\\t$s*$s@param$svalue$sthe$svalue$sof$sthe$schess$spiece,$sin$spawns\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(name,$svalue,$scolor,$spos)$s{\\n\\t\\tthis.name$s=$sname;\\n\\t\\tthis.value$s=$svalue;\\n\\t\\tthis.color$s=$scolor;\\n\\t\\tthis.pos$s=$spos;\\n\\t\\tthis.dragging$s=$sfalse;\\n\\t\\tthis.dragX$s=$s0;\\n\\t\\tthis.dragY$s=$s0;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\treturn$sfalse;\\n\\t}\\n\\t\\n\\trender()$s{\\n\\t\\tthrow$snew$sError(\\\"Error$sin$sPiece.render():$sthe$sdefault$srender()$sshould$salways$sbe$soverridden!\\\");\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$sa$sstring$srepresenting$sthis$spiece\\n\\t$s*/\\n\\ttoString()$s{\\n\\t\\tconst$scolorStr$s=$sthis.color.charAt(0).toUpperCase()$s+$sthis.color.slice(1);\\n\\t\\treturn$s`$${colorStr}$s$${this.name}`;\\n\\t}\\n}\\n\\n/**\\n$s*$sRenders$sa$spiece's$ssprite$son$sthe$sboard\\n$s*$s\\n$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n$s*/\\nPiece.renderSprite$s=$sfunction(x,$sy,$sw,$sh,$sspriteX,$sspriteY)$s{\\n\\t\\t//$sFind$sthis$ssprite$son$sthe$swhole$ssprite$simage$s(by$sx,$sy,$swidth,$sand$sheight)\\n\\t\\tconst$sclipX$s=$sSPRITES.width$s$s/$s6$s*$sspriteX;\\n\\t\\tconst$sclipY$s=$sSPRITES.height$s/$s2$s*$sspriteY;\\n\\t\\tconst$sclipW$s=$sSPRITES.width$s$s/$s6;\\n\\t\\tconst$sclipH$s=$sSPRITES.height$s/$s2;\\n\\t\\t\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\timage(SPRITES,$sx,$sy,$sw,$sh,$sclipX,$sclipY,$sclipW,$sclipH);\\n};\\n\\n//$sThe$sking\\nclass$sKing$sextends$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$sking$spiece\\n\\t$s*$s\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"King\\\",$s0,$scolor,$spos);\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\tif(boardState.tileOccupied(target)$s&&$sboardState.getPiece(target).color$s===$sthis.color)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sTODO$sCheck$sthat$swe$swouldn't$sput$sourselves$sin$scheck\\n\\t\\t\\n\\t\\t//$sTODO$sCheck$sthat$spieces$saren't$sin$sthe$sway\\n\\t\\t\\n\\t\\t//$sIf$sthe$srank$sand$sfile$sdistance$sare$sboth$sat$smost$s1,$swe$scan$smove$sthere\\n\\t\\tconst$sdistX$s=$sabs(this.pos.rank$s-$starget.rank);\\n\\t\\tconst$sdistY$s=$sabs(this.pos.file$s-$starget.file);\\n\\t\\treturn$sdistX$s<=$s1$s&&$sdistY$s<=$s1;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthis$spiece$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\tPiece.renderSprite(x,$sy,$sw,$sh,$s0,$sthis.color$s===$sTEAMS.WHITE$s?$s0$s:$s1);\\n\\t}\\n}\\n\\n//$sThe$squeen\\nclass$sQueen$sextends$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$squeen$spiece\\n\\t$s*$s\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"Queen\\\",$s9,$scolor,$spos);\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\t//$sIf$sthe$stile$sis$soccupied$sby$sour$sown$spiece,$swe$scan't$smove$sthere.\\n\\t\\tif(boardState.tileOccupied(target)$s&&$sboardState.getPiece(target).color$s===$sthis.color)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sCheck$sthat$sthe$starget$sis$son$sa$sdiagonal\\n\\t\\tconst$sdistX$s=$sabs(this.pos.rank$s-$starget.rank);\\n\\t\\tconst$sdistY$s=$sabs(this.pos.file$s-$starget.file);\\n\\t\\tif(distX$s!==$sdistY$s&&$sdistX$s!==$s0$s&&$sdistY$s!==$s0)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sTravel$salong$sa$spath$sfrom$sthe$scurrent$stile$sto$sthe$starget$stile,\\n\\t\\t//$sensuring$sno$spieces$sare$sblocking$sthe$spath\\n\\t\\tconst$sdeltaX$s=$ssign(target.file$s-$sthis.pos.file);\\n\\t\\tconst$sdeltaY$s=$ssign(target.rank$s-$sthis.pos.rank);\\n\\t\\tlet$scurrentTile$s=$snew$sTilePos(this.pos.rank$s+$sdeltaY,$sthis.pos.file$s+$sdeltaX);\\n\\t\\twhile(!currentTile.equals(target))$s{\\n\\t\\t\\t//$sIf$sthere's$sa$spiece$son$sthe$scurrent$stile,$sthen$sthat$spiece$sis\\n\\t\\t\\t//$sblocking$sthe$spath$sand$swe$scan't$smove$sto$starget.\\n\\t\\t\\tif(boardState.tileOccupied(currentTile))$sreturn$sfalse;\\n\\t\\t\\t\\n\\t\\t\\t//$sOtherwise,$scontinue$salong$sthe$spath\\n\\t\\t\\tcurrentTile$s=$snew$sTilePos(currentTile.rank$s+$sdeltaY,$scurrentTile.file$s+$sdeltaX);\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$swe$smade$sit$sall$sthe$sway$sto$sthe$starget$swithout$srunning$sinto$sa$spiece,\\n\\t\\t//$sthen$swe$scan$smove$sthere!$sIt$smust$sbe$seither$sempty$sor$san$senemy$spiece.\\n\\t\\treturn$strue;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthis$spiece$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\tPiece.renderSprite(x,$sy,$sw,$sh,$s1,$sthis.color$s===$sTEAMS.WHITE$s?$s0$s:$s1);\\n\\t}\\n}\\n\\n//$sThe$sbishop\\nclass$sBishop$sextends$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$sbishop$spiece\\n\\t$s*$s\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"Bishop\\\",$s3,$scolor,$spos);\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\t//$sIf$sthe$stile$sis$soccupied$sby$sour$sown$spiece,$swe$scan't$smove$sthere.\\n\\t\\tif(boardState.tileOccupied(target)$s&&$sboardState.getPiece(target).color$s===$sthis.color)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sCheck$sthat$sthe$starget$sis$son$sa$sdiagonal\\n\\t\\tconst$sdistX$s=$sabs(this.pos.rank$s-$starget.rank);\\n\\t\\tconst$sdistY$s=$sabs(this.pos.file$s-$starget.file);\\n\\t\\tif(distX$s!==$sdistY)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sTravel$salong$sa$spath$sfrom$sthe$scurrent$stile$sto$sthe$starget$stile,\\n\\t\\t//$sensuring$sno$spieces$sare$sblocking$sthe$spath\\n\\t\\tconst$sdeltaX$s=$ssign(target.file$s-$sthis.pos.file);\\n\\t\\tconst$sdeltaY$s=$ssign(target.rank$s-$sthis.pos.rank);\\n\\t\\tlet$scurrentTile$s=$snew$sTilePos(this.pos.rank$s+$sdeltaY,$sthis.pos.file$s+$sdeltaX);\\n\\t\\twhile(!currentTile.equals(target))$s{\\n\\t\\t\\t//$sIf$sthere's$sa$spiece$son$sthe$scurrent$stile,$sthen$sthat$spiece$sis\\n\\t\\t\\t//$sblocking$sthe$spath$sand$swe$scan't$smove$sto$starget.\\n\\t\\t\\tif(boardState.tileOccupied(currentTile))$sreturn$sfalse;\\n\\t\\t\\t\\n\\t\\t\\t//$sOtherwise,$scontinue$salong$sthe$spath\\n\\t\\t\\tcurrentTile$s=$snew$sTilePos(currentTile.rank$s+$sdeltaY,$scurrentTile.file$s+$sdeltaX);\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$swe$smade$sit$sall$sthe$sway$sto$sthe$starget$swithout$srunning$sinto$sa$spiece,\\n\\t\\t//$sthen$swe$scan$smove$sthere!$sIt$smust$sbe$seither$sempty$sor$san$senemy$spiece.\\n\\t\\treturn$strue;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthis$spiece$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\tPiece.renderSprite(x,$sy,$sw,$sh,$s2,$sthis.color$s===$sTEAMS.WHITE$s?$s0$s:$s1);\\n\\t}\\n}\\n\\n//$sThe$sbishop\\nclass$sKnight$sextends$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$sknight$spiece\\n\\t$s*$s\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"Knight\\\",$s3,$scolor,$spos);\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\tif(boardState.tileOccupied(target)$s&&$sboardState.getPiece(target).color$s===$sthis.color)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sTODO$sCheck$sthat$spieces$saren't$sin$sthe$sway\\n\\t\\t\\n\\t\\t//$sTODO\\n\\t\\tconst$sdistX$s=$sabs(this.pos.rank$s-$starget.rank);\\n\\t\\tconst$sdistY$s=$sabs(this.pos.file$s-$starget.file);\\n\\t\\treturn$sdistX$s===$s2$s&&$sdistY$s===$s1$s||$sdistX$s===$s1$s&&$sdistY$s===$s2;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthis$spiece$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\tPiece.renderSprite(x,$sy,$sw,$sh,$s3,$sthis.color$s===$sTEAMS.WHITE$s?$s0$s:$s1);\\n\\t}\\n}\\n\\n//$sThe$srook\\nclass$sRook$sextends$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$srook$spiece\\n\\t$s*$s\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"Rook\\\",$s5,$scolor,$spos);\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\t//$sIf$sthe$stile$sis$soccupied$sby$sour$sown$spiece,$swe$scan't$smove$sthere.\\n\\t\\tif(boardState.tileOccupied(target)$s&&$sboardState.getPiece(target).color$s===$sthis.color)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sCheck$sthat$sthe$starget$sis$son$sthe$ssame$srank/file\\n\\t\\tconst$sdistX$s=$sabs(this.pos.rank$s-$starget.rank);\\n\\t\\tconst$sdistY$s=$sabs(this.pos.file$s-$starget.file);\\n\\t\\tif(distX$s!==$s0$s&&$sdistY$s!==$s0)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sTravel$salong$sa$spath$sfrom$sthe$scurrent$stile$sto$sthe$starget$stile,\\n\\t\\t//$sensuring$sno$spieces$sare$sblocking$sthe$spath\\n\\t\\tconst$sdeltaX$s=$ssign(target.file$s-$sthis.pos.file);\\n\\t\\tconst$sdeltaY$s=$ssign(target.rank$s-$sthis.pos.rank);\\n\\t\\tlet$scurrentTile$s=$snew$sTilePos(this.pos.rank$s+$sdeltaY,$sthis.pos.file$s+$sdeltaX);\\n\\t\\twhile(!currentTile.equals(target))$s{\\n\\t\\t\\t//$sIf$sthere's$sa$spiece$son$sthe$scurrent$stile,$sthen$sthat$spiece$sis\\n\\t\\t\\t//$sblocking$sthe$spath$sand$swe$scan't$smove$sto$starget.\\n\\t\\t\\tif(boardState.tileOccupied(currentTile))$sreturn$sfalse;\\n\\t\\t\\t\\n\\t\\t\\t//$sOtherwise,$scontinue$salong$sthe$spath\\n\\t\\t\\tcurrentTile$s=$snew$sTilePos(currentTile.rank$s+$sdeltaY,$scurrentTile.file$s+$sdeltaX);\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$swe$smade$sit$sall$sthe$sway$sto$sthe$starget$swithout$srunning$sinto$sa$spiece,\\n\\t\\t//$sthen$swe$scan$smove$sthere!\\n\\t\\treturn$strue;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthis$spiece$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\tPiece.renderSprite(x,$sy,$sw,$sh,$s4,$sthis.color$s===$sTEAMS.WHITE$s?$s0$s:$s1);\\n\\t}\\n}\\n\\n//$sThe$spawn\\nclass$sPawn$sextends$sPiece$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$spawn$spiece\\n\\t$s*$s\\n\\t$s*$s@param$scolor$sthe$scolor$steam$sthat$sthe$spiece$sbelongs$sto.$sEither$s\\\"white\\\"$sor$s\\\"black\\\"\\n\\t$s*$s@param$spos$sthe$sposition$sof$sthe$schess$spiece$son$sthe$sboard,$sas$sa$sTilePos\\n\\t$s*/\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"Pawn\\\",$s1,$scolor,$spos);\\n\\t\\t\\n\\t\\tthis.enPassantable$s=$sfalse;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sTakes$sin$sa$starget$sposition$sand$sboard$sstate,$sand$sreturns$swhether$sor$snot\\n\\t$s*$sthe$spiece$scan$smove$sto$sthe$starget$stile.\\n\\t$s*$s\\n\\t$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$starget$stile$sto$smove$sto\\n\\t$s*$s@param$sboardState$sa$sBoardState$srepresenting$sthe$sstate$sof$sthe$sboard$sthat\\n\\t$s*$s$s$s$s$s$s$s$sthis$spiece$sexists$sin\\n\\t$s*$s@return$swhether$sor$snot$sthe$spiece$scan$smove$sto$sthe$starget$stile\\n\\t$s*$s\\n\\t$s*/\\n\\tcanMove(target,$sboardState)$s{\\n\\t\\t//$sIf$sthe$stile$sis$soccupied$sby$sour$sown$spiece,$swe$scan't$smove$sthere.\\n\\t\\tif(boardState.tileOccupied(target)$s&&$sboardState.getPiece(target).color$s===$sthis.color)$sreturn$sfalse;\\n\\t\\t\\n\\t\\t//$sFigure$sout$swhether$swe're$sgoing$sup$sor$sdown$s(depends$son$sour$scolor)\\n\\t\\t//$sThere's$san$sinsensitive$sjoke$sthere$ssomewhere...\\n\\t\\tconst$stravelDir$s=$sthis.color$s===$sTEAMS.WHITE$s?$s1$s:$s-1;\\n\\t\\t\\n\\t\\t//$sFind$sthe$sx$sdistance$sand$sy$sdelta\\n\\t\\tconst$sdistX$s=$sabs(target.file$s-$sthis.pos.file);\\n\\t\\tconst$sdeltaY$s=$starget.rank$s-$sthis.pos.rank;\\n\\t\\t\\n\\t\\t//$sIf$swe're$strying$sto$smove$sforward$sby$sone...\\n\\t\\tif(distX$s===$s0$s&&$sdeltaY$s===$stravelDir)$s{\\n\\t\\t\\t//$sWe$scan$smove$sthere,$sas$slong$sas$sit$sisn't$soccupied\\n\\t\\t\\treturn$s!boardState.tileOccupied(target);\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$swe're$strying$sto$smove$sforward$sby$stwo...\\n\\t\\telse$sif(distX$s===$s0$s&&$sdeltaY$s===$stravelDir$s*$s2)$s{\\n\\t\\t\\t//$sWe$scan$smove$sthere,$sas$slong$sas$sit$sisn't$soccupied,$swe're$son$sthe\\n\\t\\t\\t//$sstarting$srank,$sand$sthe$stile$sbetween$sisn't$soccupied\\n\\t\\t\\tconst$sstartingRank$s=$sthis.color$s===$sTEAMS.WHITE$s?$s2$s:$sboardState.RANKS$s-$s1;\\n\\t\\t\\treturn$s(\\n\\t\\t\\t\\t$s$s$s!boardState.tileOccupied(target)\\n\\t\\t\\t\\t&&$sthis.pos.rank$s===$sstartingRank\\n\\t\\t\\t\\t&&$s!boardState.tileOccupied(new$sTilePos(this.pos.rank$s+$stravelDir,$sthis.pos.file))\\n\\t\\t\\t);\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$swe're$strying$sto$smove$sdiagonally$sby$sone...\\n\\t\\telse$sif(distX$s===$s1$s&&$sdeltaY$s===$stravelDir)$s{\\n\\t\\t\\t//$sWe$scan$smove$sthere,$sas$slong$sas$sit$sis$soccupied$sby$san$senemy$spiece\\n\\t\\t\\tif(\\n\\t\\t\\t\\t$s$s$sboardState.tileOccupied(target)\\n\\t\\t\\t\\t&&$sboardState.getPiece(target).color$s!==$sthis.color\\n\\t\\t\\t)$sreturn$strue;\\n\\t\\t\\t\\n\\t\\t\\t//$sTODO$simplement$scapturing$sen$spassant\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sOtherwise,$sthe$spawn$scan't$sgo$sthere.\\n\\t\\treturn$sfalse;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthis$spiece$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$srendered$spiece\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$srendered$spiece\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sDraw$sthe$ssprite,$sclipping$sto$sonly$sthis$spiece\\n\\t\\tPiece.renderSprite(x,$sy,$sw,$sh,$s5,$sthis.color$s===$sTEAMS.WHITE$s?$s0$s:$s1);\\n\\t}\\n}\\n\\n//$sRepresents$sthe$sstate$sof$sa$schessboard\\nclass$sBoardState$s{\\n\\tconstructor(ranks,$sfiles)$s{\\n\\t\\tthis.RANKS$s=$sranks;\\n\\t\\tthis.FILES$s=$sfiles;\\n\\t$s\\t\\n\\t\\tthis.tiles$s=$s[];\\n\\t\\t\\n\\t\\tif(this.RANKS$s===$s8$s&&$sthis.FILES$s===$s8)$sthis.initBoard();\\n\\t\\telse$sthis.clearBoard();\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sInitializes$sthe$sboard$swith$sno$spieces\\n\\t$s*/\\n\\t$sclearBoard()$s{\\n\\t\\tfor(let$sfile$s=$s0;$sfile$s<$sthis.FILES;$sfile++)$s{\\n\\t\\t\\tthis.tiles[file]$s=$s[];\\n\\t\\t\\tfor(let$srank$s=$s0;$srank$s<$sthis.RANKS;$srank++)$s{\\n\\t\\t\\t\\tthis.tiles[file][rank]$s=$sundefined;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t$s}\\n\\t\\n\\t/**\\n\\t$s*$sInitializes$sthe$sboard$swith$sthe$sstandard$sstarting$schess$slayout.$sMust$sbe\\n\\t$s*$san$s8x8$sboard!\\n\\t$s*/\\n\\t$sinitBoard()$s{\\n\\t$s\\tif(this.RANKS$s!==$s8$s||$sthis.FILES$s!==$s8)$s{\\n\\t$s\\t\\tthrow$snew$sError(\\\"Error$sin$sBoardState.initBoard():$sCannot$sset$sup$sthe$sboard$son$sa$snon-standard$ssize!$s(board$smust$sbe$s8x8!)\\\");\\n\\t$s\\t}\\n\\t$s\\t\\n\\t$s\\tthis.clearBoard();\\n\\t$s\\t\\n\\t$s\\t//$sWhite$spieces\\n\\t$s\\tthis.setPiece(new$sRook$s$s$s(TEAMS.WHITE,$snew$sTilePos(1,$s1)));\\n\\t$s\\tthis.setPiece(new$sKnight$s(TEAMS.WHITE,$snew$sTilePos(1,$s2)));\\n\\t$s\\tthis.setPiece(new$sBishop$s(TEAMS.WHITE,$snew$sTilePos(1,$s3)));\\n\\t$s\\tthis.setPiece(new$sQueen$s$s(TEAMS.WHITE,$snew$sTilePos(1,$s4)));\\n\\t$s\\tthis.setPiece(new$sKing$s$s$s(TEAMS.WHITE,$snew$sTilePos(1,$s5)));\\n\\t$s\\tthis.setPiece(new$sBishop$s(TEAMS.WHITE,$snew$sTilePos(1,$s6)));\\n\\t$s\\tthis.setPiece(new$sKnight$s(TEAMS.WHITE,$snew$sTilePos(1,$s7)));\\n\\t$s\\tthis.setPiece(new$sRook$s$s$s(TEAMS.WHITE,$snew$sTilePos(1,$s8)));\\n\\t$s\\t//$sPawns\\n\\t$s\\tfor(let$sfile$s=$s0;$sfile$s<$sthis.FILES;$sfile++)$s{\\n\\t$s\\t\\tthis.setPiece(new$sPawn(TEAMS.WHITE,$snew$sTilePos(2,$sfile$s+$s1)));\\n\\t$s\\t}\\n\\t$s\\t\\n\\t$s\\t//$sBlack$spieces\\n\\t$s\\tthis.setPiece(new$sRook$s$s$s(TEAMS.BLACK,$snew$sTilePos(8,$s1)));\\n\\t$s\\tthis.setPiece(new$sKnight$s(TEAMS.BLACK,$snew$sTilePos(8,$s2)));\\n\\t$s\\tthis.setPiece(new$sBishop$s(TEAMS.BLACK,$snew$sTilePos(8,$s3)));\\n\\t$s\\tthis.setPiece(new$sQueen$s$s(TEAMS.BLACK,$snew$sTilePos(8,$s4)));\\n\\t$s\\tthis.setPiece(new$sKing$s$s$s(TEAMS.BLACK,$snew$sTilePos(8,$s5)));\\n\\t$s\\tthis.setPiece(new$sBishop$s(TEAMS.BLACK,$snew$sTilePos(8,$s6)));\\n\\t$s\\tthis.setPiece(new$sKnight$s(TEAMS.BLACK,$snew$sTilePos(8,$s7)));\\n\\t$s\\tthis.setPiece(new$sRook$s$s$s(TEAMS.BLACK,$snew$sTilePos(8,$s8)));\\n\\t$s\\t//$sPawns\\n\\t$s\\tfor(let$sfile$s=$s0;$sfile$s<$sthis.FILES;$sfile++)$s{\\n\\t$s\\t\\tthis.setPiece(new$sPawn(TEAMS.BLACK,$snew$sTilePos(7,$sfile$s+$s1)));\\n\\t$s\\t}\\n\\t$s}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$swhether$sor$snot$sa$stile$sis$soccupied$sby$sa$spiece\\n\\t$s*$s\\n\\t$s*$s@param$stile$sa$sTilePos$srepresenting$sthe$stile$sto$slook$sfor$sa$spiece$son\\n\\t$s*$s@return$swhether$sor$snot$sa$stile$sis$soccupied$sby$sa$spiece\\n\\t$s*/\\n\\ttileOccupied(tile)$s{\\n\\t\\tif(tile.rank$s>$sthis.RANKS$s||$stile.file$s>$sthis.FILES)$s{\\n\\t\\t\\tthrow$snew$sError(\\\"Error$sin$sBoardState.tileOccupied():$scannot$scheck$sa$stile$soutside$sthe$sboard!\\\");\\n\\t\\t}\\n\\t\\t\\n\\t\\treturn$sthis.tiles[tile.file$s-$s1][tile.rank$s-$s1]$s!==$sundefined;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRemoves$sany$spieces$sfrom$sthe$sgiven$stile\\n\\t$s*$s\\n\\t$s*$s@param$stile$sa$sTilePos$srepresenting$sthe$stile$sto$sclear$spieces$sfrom\\n\\t$s*/\\n\\tclearTile(tile)$s{\\n\\t\\tthis.tiles[tile.file$s-$s1][tile.rank$s-$s1]$s=$sundefined;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sSets$sthe$spiece$son$sa$sgiven$stile$sto$sthe$sprovided$spiece\\n\\t$s*$s\\n\\t$s*$s@param$spiece$sthe$spiece$sto$sput$son$sthe$sgiven$stile\\n\\t$s*/\\n\\tsetPiece(piece)$s{\\n\\t\\t//$sIf$sthe$spiece$sisn't$sof$stype$sPiece,$sthrow$san$serror\\n\\t\\tif(!(piece$sinstanceof$sPiece))$s{\\n\\t\\t\\tthrow$snew$sError(\\\"Error$sin$sBoardState.setPiece():$spiece$smust$sbe$sof$stype$s'Piece'!\\\");\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sOtherwise,$sset$sthe$spiece$son$sthe$sgiven$stile\\n\\t\\tthis.tiles[piece.pos.file$s-$s1][piece.pos.rank$s-$s1]$s=$spiece;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$sthe$spiece$son$sthe$sgiven$stile,$sor$sundefined$sif$sthere$sis$sno$spiece\\n\\t$s*$s\\n\\t$s*$s@param$stile$sa$sTilePos$srepresenting$sthe$stile$sto$sget$sthe$spiece$son\\n\\t$s*$s@return$sthe$spiece$son$sthe$sgiven$stile,$sor$sundefined$sif$sthere$sis$sno$spiece\\n\\t$s*/\\n\\tgetPiece(tile)$s{\\n\\t\\t//$sIf$sthe$stile$sisn't$soccupied,$sreturn$sundefined\\n\\t\\tif(!this.tileOccupied(tile))$sreturn$sundefined;\\n\\t\\t\\n\\t\\t//$sOtherwise,$sreturn$sthe$spiece$son$sthe$sgiven$stile\\n\\t\\treturn$sthis.tiles[tile.file$s-$s1][tile.rank$s-$s1];\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sall$sthe$spieces$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$sboard\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$sboard\\n\\t$s*$s@param$sw$sthe$swidth$sof$sthe$sboard\\n\\t$s*$s@param$sh$sthe$sheight$sof$sthe$sboard\\n\\t$s*/\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\t//$sFigure$sout$sthe$swidth$sand$sheight$sof$seach$stile\\n\\t\\tconst$stileW$s=$sw$s/$sthis.FILES;\\n\\t\\tconst$stileH$s=$sh$s/$sthis.RANKS;\\n\\t\\t\\n\\t\\t//$sSave$sthe$spiece$swe're$scurrently$sdrawing,$sand$srender$sit$slast$sso$sit's$son\\n\\t\\t//$stop$sof$sthe$sother$spieces\\n\\t\\tlet$sdraggedPiece$s=$sundefined;\\n\\t\\t\\n\\t\\t//$sLoop$sthrough$seach$stile,$srendering$sthe$spiece$son$sit$s(if$sthere$sis$sone)\\n\\t\\tfor(let$sfile$s=$s0;$sfile$s<$sthis.FILES;$sfile++)$s{\\n\\t\\t\\tfor(let$srank$s=$s0;$srank$s<$sthis.RANKS;$srank++)$s{\\n\\t\\t\\t\\tconst$stile$s=$snew$sTilePos(rank$s+$s1,$sfile$s+$s1);\\n\\t\\t\\t\\t\\n\\t\\t\\t\\t//$sIf$sthere$sis$sa$spiece$son$sthe$stile,$srender$sit!\\n\\t\\t\\t\\tif(this.tileOccupied(tile))$s{\\n\\t\\t\\t\\t\\tconst$spiece$s=$sthis.getPiece(tile);\\n\\t\\t\\t\\t\\t\\n\\t\\t\\t\\t\\t//$sIf$sthe$spiece$sis$sbeing$sdragged,$swait$sto$srender$sit$slast\\n\\t\\t\\t\\t\\tif(piece.dragging)$s{\\n\\t\\t\\t\\t\\t\\tdraggedPiece$s=$spiece;\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\t\\n\\t\\t\\t\\t\\telse$s{\\n\\t\\t\\t\\t\\t\\t//$sFigure$sout$swhere$sto$srender$sthe$spiece\\n\\t\\t\\t\\t\\t\\tconst$stileX$s=$sx$s+$sfile$s*$stileW;\\n\\t\\t\\t\\t\\t\\tconst$stileY$s=$sy$s+$sh$s-$s(rank$s*$stileH)$s-$stileH;\\n\\t\\t\\t\\t\\t\\t\\n\\t\\t\\t\\t\\t\\t//$sRender$sthe$spiece\\n\\t\\t\\t\\t\\t\\tpiece.render(tileX,$stileY,$stileW,$stileH);\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sRender$sthe$spiece$swe're$sdragging,$sif$sit$sexists\\n\\t\\tif(draggedPiece$s!==$sundefined)$s{\\n\\t\\t\\t//$sFigure$sout$swhere$sto$srender$sthe$spiece\\n\\t\\t\\tconst$stileX$s=$sdraggedPiece.dragX$s-$stileW$s/$s2;\\n\\t\\t\\tconst$stileY$s=$sdraggedPiece.dragY$s-$stileH$s/$s2;\\n\\t\\t\\t\\n\\t\\t\\t//$sRender$sthe$spiece\\n\\t\\t\\tdraggedPiece.render(tileX,$stileY,$stileW,$stileH);\\n\\t\\t}\\n\\t}\\n}\\n\\n//$sRepresents$sa$schess$sboard\\nclass$sBoard$s{\\n\\t/**\\n\\t$s*$sCreates$sa$snew$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sranks$sthe$snumber$sof$sranks$s(rows)$sthe$sboard$shas\\n\\t$s*$s@param$sfiles$sthe$snumber$sof$sfiles$s(columns)$sthe$sboard$shas\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$sboard\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$sboard\\n\\t$s*$s@param$swidth$sthe$swidth$sof$sthe$sboard\\n\\t$s*$s@param$sheight$sthe$sheight$sof$sthe$sboard\\n\\t$s*/\\n\\tconstructor(ranks,$sfiles,$sx,$sy,$swidth,$sheight)$s{\\n\\t\\tthis.RANKS$s=$sranks;\\n\\t\\tthis.FILES$s=$sfiles;\\n\\t\\tthis.x$s=$sx;\\n\\t\\tthis.y$s=$sy;\\n\\t\\tthis.width$s=$swidth;\\n\\t\\tthis.height$s=$sheight;\\n\\t\\t\\n\\t\\tthis.boardState$s=$snew$sBoardState(this.RANKS,$sthis.FILES);\\n\\t\\tthis.draggedPiece$s=$sundefined;\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$swhether$sor$snot$sthe$sgiven$sx,$sy$sis$son$sthe$sboard\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sto$scheck\\n\\t$s*$s@param$sy$sthe$sy$sposition$sto$scheck\\n\\t$s*/\\n\\tonBoard(x,$sy)$s{\\n\\t\\treturn$sx$s>$sthis.x$s&&$sx$s<$sthis.x$s+$sthis.width$s&&$sy$s>$sthis.y$s&&$sy$s<$sthis.y$s+$sthis.height;\\n\\t$s}\\n\\t\\n\\t/**\\n\\t$s*$sReturns$sa$sTilePos$srepresenting$sthe$stile$sat$sthe$sgiven$sx,$sy\\n\\t$s*$s\\n\\t$s*$s@param$sx$sthe$sx$sposition$sof$sthe$stile\\n\\t$s*$s@param$sy$sthe$sy$sposition$sof$sthe$stile\\n\\t$s*/\\n\\ttileAt(x,$sy)$s{\\n\\t\\tif(!this.onBoard(x,$sy))$s{\\n\\t\\t\\tthrow$snew$sError(\\\"Error$sat$sBoard.tileAt():$sx$sand$sy$smust$sbe$swithin$sthe$sbounds$sof$sthe$sboard!\\\");\\n\\t\\t}\\n\\t\\t\\n\\t\\tconst$stileW$s=$sthis.width$s$s/$sthis.FILES;\\n\\t\\tconst$stileH$s=$sthis.height$s/$sthis.RANKS;\\n\\t\\tconst$sfile$s=$sfloor((x$s-$sthis.x)$s/$stileW)$s+$s1;\\n\\t\\tconst$srank$s=$sfloor((this.height$s-$s(y$s-$sthis.y))$s/$stileH)$s+$s1;\\n\\t\\t\\n\\t\\treturn$snew$sTilePos(rank,$sfile);\\n\\t$s}\\n\\t$s\\n\\t$s/**\\n\\t$s$s*$sMoves$sa$spiece$sto$sthe$starget$stile\\n\\t$s$s*$s\\n\\t$s$s*$s@param$spiece$sthe$spiece$sto$smove$s(Piece$sobject)\\n\\t$s$s*$s@param$starget$sa$sTilePos$srepresenting$sthe$sposition$sfor$sthe$spiece$sto$smove$sto\\n\\t$s$s*/\\n\\t$smovePiece(piece,$starget)$s{\\n\\t$s\\t//$sEnsure$sthe$sarguments$sare$sthe$scorrect$stype,$sand$sthe$spiece$scan$smove$sto$sthe$starget\\n\\t$s\\tif(!(piece$sinstanceof$sPiece))$s{\\n\\t$s\\t\\tthrow$snew$sError(\\\"Error$sin$sBoard.movePiece():$spiece$smust$sbe$sof$stype$sPiece!\\\");\\n\\t$s\\t}\\n\\t$s\\tif(!(target$sinstanceof$sTilePos))$s{\\n\\t$s\\t\\tthrow$snew$sError(\\\"Error$sin$sBoard.movePiece():$spos$smust$sbe$sof$stype$sTilePos!\\\");\\n\\t$s\\t}\\n\\t$s\\tif(!(piece.canMove(target,$sthis.boardState)))$s{\\n\\t$s\\t\\tthrow$snew$sError(\\\"Error$sin$sBoard.movePiece():$sThe$spiece$scannot$slegally$smove$sto$starget!\\\");\\n\\t$s\\t}\\n\\t$s\\t\\n\\t$s\\t//$sRemove$sthe$spiece$sfrom$sthe$sold$stile$s(we$sstill$shave$sa$sreference$sto$sthe\\n\\t$s\\t//$spiece$sin$sthe$svariable$spiece)\\n\\t$s\\tthis.boardState.clearTile(piece.pos);\\n\\t$s\\t\\n\\t$s\\t//$sTODO$sHandle$scaptures\\n\\t$s\\t\\n\\t$s\\t//$sUpdate$sthe$spiece's$spos\\n\\t$s\\tpiece.pos$s=$starget.copy();\\n\\t$s\\t//$sTODO$sEn$spassant$sand$scastling\\n\\t$s\\t\\n\\t$s\\t//$sSet$sthe$starget$sto$sthe$spiece\\n\\t$s\\tthis.boardState.setPiece(piece);\\n\\t$s}\\n\\t$s\\n\\t$s/**\\n\\t$s$s*$sHandles$sthe$smouse$sdown$sevent$s(when$sthe$suser$spresses$sthe$smouse$sbutton$sdown)\\n\\t$s$s*/\\n\\tonMouseDown(x,$sy,$sbtn,$skeys)$s{\\n\\t\\t//$sFind$swhich$stile$swas$sclicked\\n\\t\\tconst$sclickedTile$s=$sthis.tileAt(x,$sy);\\n\\t\\t\\n\\t\\t//$sIf$sit$swas$sa$sleft$sclick,$sdo$sleft$sclick$sstuff!\\n\\t\\tif(btn$s===$s\\\"left\\\")$s{\\n\\t\\t\\t//$sIf$sthey$sclicked$son$sa$spiece,$sstart$sdragging$sthe$spiece\\n\\t\\t\\tif(this.boardState.tileOccupied(clickedTile))$s{\\n\\t\\t\\t\\tthis.draggedPiece$s=$sthis.boardState.getPiece(clickedTile);\\n\\t\\t\\t\\tthis.draggedPiece.dragging$s=$strue;\\n\\t\\t\\t\\tthis.draggedPiece.dragX$s=$sx;\\n\\t\\t\\t\\tthis.draggedPiece.dragY$s=$sy;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$sit$swas$sa$sright$sclick,$sdo$sright$sclick$sstuff\\n\\t\\telse$sif(btn$s===$s\\\"right\\\")$s{\\n\\t\\t\\t//$sTODO$sImplement$sdrawing$sarrows$sand$shighlighting$ssquares\\n\\t\\t\\tconst$shighlightColor$s=$s(\\n\\t\\t\\t\\tkeys.shift$s?$s(keys.alt$s?$scolors.YELLOW$s:$scolors.RED$s$s$s)\\n\\t\\t\\t\\t$s$s$s$s$s$s$s$s$s$s$s:$s(keys.alt$s?$scolors.BLUE$s$s$s:$scolors.FOREST)\\n\\t\\t\\t);\\n\\t\\t}\\n\\t}\\n\\t$s\\n\\t$s/**\\n\\t$s$s*$sHandles$sthe$smouse$sup$sevent$s(when$sthe$suser$sreleases$sthe$smouse$sbutton$sup)\\n\\t$s$s*/\\n\\tonMouseUp(x,$sy,$sbtn,$skeys)$s{\\n\\t\\t//$sIf$sit$swas$sa$sleft$sbutton$sup,$sdo$sleft$sbutton$sup$sstuff!\\n\\t\\tif(btn$s===$s\\\"left\\\")$s{\\n\\t\\t\\t//$sIf$swe're$sdragging,$stry$sto$smove$sthe$spiece$sand$sstop$sdragging\\n\\t\\t\\tif(this.draggedPiece$s!==$sundefined)$s{\\n\\t\\t\\t\\t//$sIf$swe$scan,$smove$sthe$spiece$sto$sthe$stile$sthe$smouse$swas$sreleased$son\\n\\t\\t\\t\\tconst$stile$s=$sthis.tileAt(x,$sy);\\n\\t\\t\\t\\tif(this.draggedPiece.canMove(tile,$sthis.boardState))$s{\\n\\t\\t\\t\\t\\tthis.movePiece(this.draggedPiece,$stile);\\n\\t\\t\\t\\t}\\n\\t\\t\\t\\t\\n\\t\\t\\t\\t//$sStop$sdragging\\n\\t\\t\\t\\tthis.draggedPiece.dragging$s=$sfalse;\\n\\t\\t\\t\\tthis.draggedPiece.dragX$s=$s0;\\n\\t\\t\\t\\tthis.draggedPiece.dragY$s=$s0;\\n\\t\\t\\t\\tthis.draggedPiece$s=$sundefined;\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sIf$sit$swas$sa$sright$sbutton$sup,$sdo$sright$sbutton$sup$sstuff\\n\\t\\telse$sif(btn$s===$s\\\"right\\\")$s{\\n\\t\\t\\t//$sTODO\\n\\t\\t}\\n\\t}\\n\\t$s\\n\\t$s/**\\n\\t$s$s*$sHandles$sthe$smouse$smove$sevent$s(when$sthe$suser$smoves$sthe$smouse)\\n\\t$s$s*/\\n\\tonMouseMove(x,$sy,$sbtn,$skeys)$s{\\n\\t\\t//$sIf$swe're$sdragging$sa$spiece,$supdate$sit\\n\\t\\tif(this.draggedPiece$s!==$sundefined)$s{\\n\\t\\t\\tthis.draggedPiece.dragX$s=$sx;\\n\\t\\t\\tthis.draggedPiece.dragY$s=$sy;\\n\\t\\t}\\n\\t}\\n\\t\\n\\t/**\\n\\t$s*$sRenders$sthe$sboard$sto$sthe$sscreen\\n\\t$s*/\\n\\trender()$s{\\n\\t\\tconst$stileW$s=$sthis.width$s$s/$sthis.FILES;\\n\\t\\tconst$stileH$s=$sthis.height$s/$sthis.RANKS;\\n\\t\\t\\n\\t\\t//$sRender$sall$sthe$stiles\\n\\t\\tfor(let$srank$s=$s0;$srank$s<$sthis.RANKS;$srank++)$s{\\n\\t\\t\\tfor(let$sfile$s=$s0;$sfile$s<$sthis.FILES;$sfile++)$s{\\n\\t\\t\\t\\tconst$scolor$s=$srank$s%$s2$s!=$sfile$s%$s2$s?$sCOLOR_DARK$s:$sCOLOR_LIGHT;\\n\\t\\t\\t\\t\\n\\t\\t\\t\\tfill(color);\\n\\t\\t\\t\\tnoStroke();\\n\\t\\t\\t\\trect(this.x$s+$sfile$s*$stileW,$sthis.y$s+$srank$s*$stileH,$stileW,$stileH);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sRender$slegal$smoves$sif$sdragging\\n\\t\\tif(this.draggedPiece$s!==$sundefined)$s{\\n\\t\\t\\t//$sLoop$sthrough$severy$stile,$sdrawing$san$soverlay$sif$sit's$sa$slegal$smove\\n\\t\\t\\tfor(let$srank$s=$s0;$srank$s<$sboard.RANKS;$srank++)$s{\\n\\t\\t\\t\\tfor(let$sfile$s=$s0;$sfile$s<$sboard.FILES;$sfile++)$s{\\n\\t\\t\\t\\t\\tlet$sloopTile$s=$snew$sTilePos(rank$s+$s1,$sfile$s+$s1);\\n\\t\\t\\t\\t\\tif(this.draggedPiece.canMove(loopTile,$sthis.boardState))$s{\\n\\t\\t\\t\\t\\t\\toverlayRectAtTile(loopTile,$scolors.CYAN$s+$s\\\"80\\\");\\n\\t\\t\\t\\t\\t}\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sRender$sthe$spieces\\n\\t\\tthis.boardState.render(this.x,$sthis.y,$sthis.width,$sthis.height);\\n\\t}\\n}\\n\\n//$sIsland$sof$smisfit$svariables\\nlet$sboard;\\n\\n/**\\n$s*$sOverlays$sa$scolored$srectangle$son$sthe$sgiven$stile\\n$s*$s\\n$s*$s@param$stile$sthe$stile$sto$soverlay$sa$srectangle$son\\n$s*$s@param$scolor$sthe$scolor$sof$sthe$soverlay$srectangle\\n$s*/\\nfunction$soverlayRectAtTile(tile,$scolor)$s{\\n\\tconst$stileW$s=$sboard.width$s$s/$sboard.FILES;\\n\\tconst$stileH$s=$sboard.height$s/$sboard.RANKS;\\n\\t\\n\\tfill(color);\\n\\trect((tile.file$s-$s1)$s*$stileW,$sheight$s-$stile.rank$s*$stileH,$stileW,$stileH);\\n}\\n\\n//$sEvent$shandling\\nmouse.down$s=$sfunction(e,$stype)$s{\\n\\tconst$smodifiers$s=$s{\\n\\t\\tctrl:$se.ctrlKey,\\n\\t\\talt:$se.altKey,\\n\\t\\tshift:$se.shiftKey,\\n\\t\\tmeta:$se.metaKey\\n\\t};\\n\\t\\n\\tboard.onMouseDown(e.offsetX,$se.offsetY,$stype,$smodifiers);\\n};\\n\\nmouse.up$s=$sfunction(e,$stype)$s{\\n\\tconst$smodifiers$s=$s{\\n\\t\\tctrl:$se.ctrlKey,\\n\\t\\talt:$se.altKey,\\n\\t\\tshift:$se.shiftKey,\\n\\t\\tmeta:$se.metaKey\\n\\t};\\n\\t\\n\\tboard.onMouseUp(e.offsetX,$se.offsetY,$stype,$smodifiers);\\n};\\n\\nmouse.move$s=$sfunction(e)$s{\\n\\tconst$smodifiers$s=$s{\\n\\t\\tctrl:$se.ctrlKey,\\n\\t\\talt:$se.altKey,\\n\\t\\tshift:$se.shiftKey,\\n\\t\\tmeta:$se.metaKey\\n\\t};\\n\\t\\n\\tboard.onMouseMove(e.offsetX,$se.offsetY,$smodifiers);\\n};\\n\\n//$sInit,$stick,$sand$srender\\n\\nfunction$sinit()$s{\\n\\tresize(600,$s600);\\n\\t\\n\\tboard$s=$snew$sBoard(RANKS,$sFILES,$s0,$s0,$swidth,$sheight);\\n}\\nif(typeof$sice$s!==$s\\\"undefined\\\"$s&&$sice.meta.framework.initialized)$sinit();\\n\\nfunction$stick(dt)$s{\\n\\t//$sTick\\n}\\n\\nfunction$srender()$s{\\n\\tbackground();\\n\\t\\n\\tboard.render();\\n\\t\\n\\t//$sTemp\\n\\tif(board.onBoard(mouse.pos.x,$smouse.pos.y))$s{\\n\\t\\t//$sRed$stile\\n\\t\\tconst$stile$s=$sboard.tileAt(mouse.pos.x,$smouse.pos.y);\\n\\t\\t//$soverlayRectAtTile(tile,$scolors.RED$s+$s\\\"80\\\");\\n\\t\\t\\n\\t\\tconst$spiece$s=$sboard.boardState.getPiece(tile);\\n\\t}\\n}\"}"],"lib":["{\"name\":\"ice\",\"lastModified\":1567381492696,\"data\":\"https://rebrand.ly/ice\"}","{\"name\":\"ice.framework\",\"lastModified\":1567382816000,\"data\":\"https://rebrand.ly/ice-fw\"}"]}}sha256:4fab23a2ef10cb3f15becc1ed44bc58646fdc98edabd1400bc054552cb772003
Add Comment
Please, Sign In to add comment