Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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/13/2021\\n$s*/\\n\\n//$sConstants\\nconst$sRANKS$s=$s8;\\nconst$sFILES$s=$s8;\\nconst$sCOLOR_LIGHT$s=$s\\\"#F0D9B5\\\";\\nconst$sCOLOR_DARK$s=$s\\\"#B58863\\\";\\n\\n//$sRepresents$sthe$scoordinates$sof$sa$schess$spiece\\nclass$sTilePos$s{\\n\\trank;\\n\\tfile;\\n\\t\\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$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\\tname;\\n\\tsymbol;\\n\\tvalue;\\n\\tcolor;\\n\\tpos;\\n\\tmoveHistory;\\n\\t\\n\\tconstructor(name,$ssymbol,$svalue,$scolor,$spos)$s{\\n\\t\\tthis.name$s=$sname;\\n\\t\\tthis.symbol$s=$ssymbol;\\n\\t\\tthis.value$s=$svalue;\\n\\t\\tthis.color$s=$scolor;\\n\\t\\tthis.pos$s=$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\\treturn$sfalse;\\n\\t}\\n}\\n\\n//$sThe$srook\\nclass$sRook$sextends$sPiece$s{\\n\\tconstructor(color,$spos)$s{\\n\\t\\tsuper(\\\"Rook\\\",$s\\\"R\\\",$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//$sTODO$sCheck$sthat$spieces$saren't$sin$sthe$sway\\n\\t\\t\\n\\t\\t//$sIf$sthe$srank$sis$sthe$ssame,$sor$sthe$sfile$sis$sthe$ssame,$swe$scan$smove$sthere\\n\\t\\treturn$sthis.pos.rank$s===$starget.rank$s||$sthis.pos.file$s===$starget.file;\\n\\t}\\n}\\n\\n//$sRepresents$sthe$sstate$sof$sa$schessboard\\nclass$sBoardState$s{\\n\\tRANKS;\\n\\tFILES;\\n\\ttiles;\\n\\t\\n\\tconstructor(ranks,$sfiles)$s{\\n\\t\\tthis.RANKS$s=$sranks;\\n\\t\\tthis.FILES$s=$sfiles;\\n\\t\\tthis.tiles$s=$s[];\\n\\t\\t\\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}\\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*$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\\tconst$stileW$s=$sw$s/$sthis.FILES;\\n\\t\\tconst$stileH$s=$sh$s/$sthis.RANKS;\\n\\t\\t\\n\\t\\tnoStroke();\\n\\t\\ttextAlign(\\\"center$smiddle\\\");\\n\\t\\tfont(\\\"Verdana\\\",$smin(tileW,$stileH)$s*$s0.5);\\n\\t\\t\\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$stileX$s=$sx$s+$sfile$s*$stileW;\\n\\t\\t\\t\\t\\tconst$stileY$s=$sy$s+$srank$s*$stileH;\\n\\t\\t\\t\\t\\tconst$spiece$s=$sthis.getPiece(tile);\\n\\t\\t\\t\\t\\t\\n\\t\\t\\t\\t\\tfill(piece.color$s===$s\\\"white\\\"$s?$scolors.WHITE$s:$scolors.BLACK);\\n\\t\\t\\t\\t\\t\\n\\t\\t\\t\\t\\ttext(piece.symbol,$stileX$s+$stileW$s/$s2,$stileY$s+$stileH$s/$s2);\\n\\t\\t\\t\\t}\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\\n\\n//$sRepresents$sa$schess$sboard\\nclass$sBoard$s{\\n\\tRANKS;\\n\\tFILES;\\n\\tboardState;\\n\\t\\n\\tconstructor(ranks,$sfiles)$s{\\n\\t\\tthis.RANKS$s=$sranks;\\n\\t\\tthis.FILES$s=$sfiles;\\n\\t\\t\\n\\t\\tthis.boardState$s=$snew$sBoardState(this.RANKS,$sthis.FILES);\\n\\t}\\n\\t\\n\\trender(x,$sy,$sw,$sh)$s{\\n\\t\\tconst$stileW$s=$sw$s/$sthis.FILES;\\n\\t\\tconst$stileH$s=$sh$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(x$s+$sfile$s*$stileW,$sy$s+$srank$s*$stileH,$stileW,$stileH);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t\\t\\n\\t\\t//$sRender$sthe$spieces\\n\\t\\tthis.boardState.render(x,$sy,$sw,$sh);\\n\\t}\\n}\\n\\n//$sIsland$sof$smisfit$svariables\\nconst$sboard$s=$snew$sBoard(RANKS,$sFILES);\\n\\nfunction$sinit()$s{\\n\\tresize(600,$s600);\\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(0,$s0,$swidth,$sheight);\\n}\"}"],"lib":["{\"name\":\"ice\",\"lastModified\":1567381492696,\"data\":\"https://rebrand.ly/ice\"}","{\"name\":\"ice.framework\",\"lastModified\":1567382816000,\"data\":\"https://rebrand.ly/ice-fw\"}"]}}sha256:9458d895fde27c75721190c81b31a2d34f846bc756dec6967ad5ff0e5d2f8ad5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement