We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | JOIN chess_game ON account_id = black_id OR account_id = white_id |
| 34 | 34 | WHERE end_time > ' . TIME . ' OR end_time IS NULL;'); |
| 35 | 35 | $games = array(); |
| 36 | - while($db->nextRecord()) { |
|
| 36 | + while ($db->nextRecord()) { |
|
| 37 | 37 | $game = self::getChessGame($db->getInt('chess_game_id'), $forceUpdate); |
| 38 | - if($game->getCurrentTurnAccount()->isNPC()) { |
|
| 38 | + if ($game->getCurrentTurnAccount()->isNPC()) { |
|
| 39 | 39 | $games[] = $game; |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $db = new SmrMySqlDatabase(); |
| 47 | 47 | $db->query('SELECT chess_game_id FROM chess_game WHERE game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND (black_id = ' . $db->escapeNumber($player->getAccountID()) . ' OR white_id = ' . $db->escapeNumber($player->getAccountID()) . ') AND (end_time > ' . TIME . ' OR end_time IS NULL);'); |
| 48 | 48 | $games = array(); |
| 49 | - while($db->nextRecord()) { |
|
| 49 | + while ($db->nextRecord()) { |
|
| 50 | 50 | $games[] = self::getChessGame($db->getInt('chess_game_id')); |
| 51 | 51 | } |
| 52 | 52 | return $games; |
@@ -56,14 +56,14 @@ discard block |
||
| 56 | 56 | $db = new SmrMySqlDatabase(); |
| 57 | 57 | $db->query('SELECT chess_game_id FROM chess_game WHERE black_id = ' . $db->escapeNumber($accountID) . ' OR white_id = ' . $db->escapeNumber($accountID) . ';'); |
| 58 | 58 | $games = array(); |
| 59 | - while($db->nextRecord()) { |
|
| 59 | + while ($db->nextRecord()) { |
|
| 60 | 60 | $games[] = self::getChessGame($db->getInt('chess_game_id')); |
| 61 | 61 | } |
| 62 | 62 | return $games; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public static function getChessGame($chessGameID,$forceUpdate = false) { |
|
| 66 | - if($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) { |
|
| 65 | + public static function getChessGame($chessGameID, $forceUpdate = false) { |
|
| 66 | + if ($forceUpdate || !isset(self::$CACHE_CHESS_GAMES[$chessGameID])) { |
|
| 67 | 67 | self::$CACHE_CHESS_GAMES[$chessGameID] = new ChessGame($chessGameID); |
| 68 | 68 | } |
| 69 | 69 | return self::$CACHE_CHESS_GAMES[$chessGameID]; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $this->db->query('SELECT * |
| 75 | 75 | FROM chess_game |
| 76 | 76 | WHERE chess_game_id=' . $this->db->escapeNumber($chessGameID) . ' LIMIT 1;'); |
| 77 | - if($this->db->nextRecord()) { |
|
| 77 | + if ($this->db->nextRecord()) { |
|
| 78 | 78 | $this->chessGameID = $chessGameID; |
| 79 | 79 | $this->gameID = $this->db->getInt('game_id'); |
| 80 | 80 | $this->startDate = $this->db->getInt('start_time'); |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | public static function isPlayerChecked(array &$board, array &$hasMoved, $colour) { |
| 97 | - foreach($board as &$row) { |
|
| 98 | - foreach($row as &$p) { |
|
| 99 | - if($p != null && $p->colour != $colour && $p->isAttacking($board, $hasMoved, true)) { |
|
| 97 | + foreach ($board as &$row) { |
|
| 98 | + foreach ($row as &$p) { |
|
| 99 | + if ($p != null && $p->colour != $colour && $p->isAttacking($board, $hasMoved, true)) { |
|
| 100 | 100 | return true; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | 'King' => false |
| 121 | 121 | ) |
| 122 | 122 | ), |
| 123 | - ChessPiece::PAWN => array(-1,-1) |
|
| 123 | + ChessPiece::PAWN => array(-1, -1) |
|
| 124 | 124 | ); |
| 125 | 125 | } |
| 126 | 126 | |
@@ -143,17 +143,17 @@ discard block |
||
| 143 | 143 | $this->resetHasMoved(); |
| 144 | 144 | |
| 145 | 145 | try { |
| 146 | - while($db->nextRecord()) { |
|
| 147 | - if($debugInfo === true) { |
|
| 146 | + while ($db->nextRecord()) { |
|
| 147 | + if ($debugInfo === true) { |
|
| 148 | 148 | echo 'x=', $db->getInt('start_x'), ', y=', $db->getInt('start_y'), ', endX=', $db->getInt('end_x'), ', endY=', $db->getInt('end_y'), ', forAccountID=', $db->getInt('move_id') % 2 == 1 ? $this->getWhiteID() : $this->getBlackID(), EOL; |
| 149 | 149 | } |
| 150 | - if(0 != $this->tryMove($db->getInt('start_x'), $db->getInt('start_y'), $db->getInt('end_x'), $db->getInt('end_y'), $db->getInt('move_id') % 2 == 1 ? $this->getWhiteID() : $this->getBlackID())) { |
|
| 150 | + if (0 != $this->tryMove($db->getInt('start_x'), $db->getInt('start_y'), $db->getInt('end_x'), $db->getInt('end_y'), $db->getInt('move_id') % 2 == 1 ? $this->getWhiteID() : $this->getBlackID())) { |
|
| 151 | 151 | break; |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | - catch(Exception $e) { |
|
| 156 | - if($debugInfo === true) { |
|
| 155 | + catch (Exception $e) { |
|
| 156 | + if ($debugInfo === true) { |
|
| 157 | 157 | echo $e->getMessage() . EOL . $e->getTraceAsString() . EOL; |
| 158 | 158 | } |
| 159 | 159 | // We probably tried an invalid move - move on. |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | public function getBoard() { |
| 164 | - if($this->board == null) { |
|
| 164 | + if ($this->board == null) { |
|
| 165 | 165 | $this->db->query('SELECT * FROM chess_game_pieces WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ';'); |
| 166 | 166 | $pieces = array(); |
| 167 | - while($this->db->nextRecord()) { |
|
| 167 | + while ($this->db->nextRecord()) { |
|
| 168 | 168 | $accountID = $this->db->getInt('account_id'); |
| 169 | 169 | $pieces[] = new ChessPiece($this->chessGameID, $accountID, $this->getColourForAccountID($accountID), $this->db->getInt('piece_id'), $this->db->getInt('x'), $this->db->getInt('y'), $this->db->getInt('piece_no')); |
| 170 | 170 | } |
@@ -179,20 +179,20 @@ discard block |
||
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | public function getMoves() { |
| 182 | - if($this->moves == null) { |
|
| 182 | + if ($this->moves == null) { |
|
| 183 | 183 | $this->db->query('SELECT * FROM chess_game_moves WHERE chess_game_id = ' . $this->db->escapeNumber($this->chessGameID) . ' ORDER BY move_id;'); |
| 184 | 184 | $this->moves = array(); |
| 185 | 185 | $mate = false; |
| 186 | - while($this->db->nextRecord()) { |
|
| 186 | + while ($this->db->nextRecord()) { |
|
| 187 | 187 | $pieceTakenID = $this->db->getField('piece_taken') == null ? null : $this->db->getInt('piece_taken'); |
| 188 | 188 | $this->moves[] = $this->createMove($this->db->getInt('piece_id'), $this->db->getInt('start_x'), $this->db->getInt('start_y'), $this->db->getInt('end_x'), $this->db->getInt('end_y'), $pieceTakenID, $this->db->getField('checked'), $this->db->getInt('move_id') % 2 == 1 ? self::PLAYER_WHITE : self::PLAYER_BLACK, $this->db->getField('castling'), $this->db->getBoolean('en_passant'), $this->db->getInt('promote_piece_id')); |
| 189 | 189 | $mate = $this->db->getField('checked') == 'MATE'; |
| 190 | 190 | } |
| 191 | - if(!$mate && $this->hasEnded()) { |
|
| 192 | - if($this->getWinner() != 0) { |
|
| 191 | + if (!$mate && $this->hasEnded()) { |
|
| 192 | + if ($this->getWinner() != 0) { |
|
| 193 | 193 | $this->moves[] = ($this->getWinner() == $this->getWhiteID() ? 'Black' : 'White') . ' Resigned.'; |
| 194 | 194 | } |
| 195 | - else if(count($this->moves) < 2) { |
|
| 195 | + else if (count($this->moves) < 2) { |
|
| 196 | 196 | $this->moves[] = 'Game Cancelled.'; |
| 197 | 197 | } |
| 198 | 198 | else { |
@@ -205,30 +205,30 @@ discard block |
||
| 205 | 205 | |
| 206 | 206 | public function getFENString() { |
| 207 | 207 | $fen = ''; |
| 208 | - $board =& $this->getBoard(); |
|
| 208 | + $board = & $this->getBoard(); |
|
| 209 | 209 | $blanks = 0; |
| 210 | - for($y=0; $y < 8; $y++) { |
|
| 211 | - if($y > 0) { |
|
| 210 | + for ($y = 0; $y < 8; $y++) { |
|
| 211 | + if ($y > 0) { |
|
| 212 | 212 | $fen .= '/'; |
| 213 | 213 | } |
| 214 | - for($x=0; $x < 8; $x++) { |
|
| 215 | - if($board[$y][$x] == null) { |
|
| 214 | + for ($x = 0; $x < 8; $x++) { |
|
| 215 | + if ($board[$y][$x] == null) { |
|
| 216 | 216 | $blanks++; |
| 217 | 217 | } |
| 218 | 218 | else { |
| 219 | - if($blanks > 0) { |
|
| 219 | + if ($blanks > 0) { |
|
| 220 | 220 | $fen .= $blanks; |
| 221 | 221 | $blanks = 0; |
| 222 | 222 | } |
| 223 | 223 | $fen .= $board[$y][$x]->getPieceLetter(); |
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | - if($blanks > 0) { |
|
| 226 | + if ($blanks > 0) { |
|
| 227 | 227 | $fen .= $blanks; |
| 228 | 228 | $blanks = 0; |
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | - switch($this->getCurrentTurnColour()) { |
|
| 231 | + switch ($this->getCurrentTurnColour()) { |
|
| 232 | 232 | case self::PLAYER_WHITE: |
| 233 | 233 | $fen .= ' w '; |
| 234 | 234 | break; |
@@ -239,30 +239,30 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | // Castling |
| 241 | 241 | $castling = ''; |
| 242 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::KING] !== true) { |
|
| 243 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['King'] !== true) { |
|
| 242 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::KING] !== true) { |
|
| 243 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['King'] !== true) { |
|
| 244 | 244 | $castling .= 'K'; |
| 245 | 245 | } |
| 246 | - if($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['Queen'] !== true) { |
|
| 246 | + if ($this->hasMoved[self::PLAYER_WHITE][ChessPiece::ROOK]['Queen'] !== true) { |
|
| 247 | 247 | $castling .= 'Q'; |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::KING] !== true) { |
|
| 251 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['King'] !== true) { |
|
| 250 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::KING] !== true) { |
|
| 251 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['King'] !== true) { |
|
| 252 | 252 | $castling .= 'k'; |
| 253 | 253 | } |
| 254 | - if($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['Queen'] !== true) { |
|
| 254 | + if ($this->hasMoved[self::PLAYER_BLACK][ChessPiece::ROOK]['Queen'] !== true) { |
|
| 255 | 255 | $castling .= 'q'; |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | - if($castling == '') { |
|
| 258 | + if ($castling == '') { |
|
| 259 | 259 | $castling = '-'; |
| 260 | 260 | } |
| 261 | 261 | $fen .= $castling . ' '; |
| 262 | 262 | |
| 263 | - if($this->hasMoved[ChessPiece::PAWN][0] != -1) { |
|
| 263 | + if ($this->hasMoved[ChessPiece::PAWN][0] != -1) { |
|
| 264 | 264 | $fen .= chr(ord('a') + $this->hasMoved[ChessPiece::PAWN][0]); |
| 265 | - switch($this->hasMoved[ChessPiece::PAWN][1]) { |
|
| 265 | + switch ($this->hasMoved[ChessPiece::PAWN][1]) { |
|
| 266 | 266 | case 3: |
| 267 | 267 | $fen .= '6'; |
| 268 | 268 | break; |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | else { |
| 275 | 275 | $fen .= '-'; |
| 276 | 276 | } |
| 277 | - $fen .= ' 0 ' . floor(count($this->moves)/2); |
|
| 277 | + $fen .= ' 0 ' . floor(count($this->moves) / 2); |
|
| 278 | 278 | |
| 279 | 279 | return $fen; |
| 280 | 280 | } |
@@ -282,14 +282,14 @@ discard block |
||
| 282 | 282 | private static function parsePieces(array $pieces) { |
| 283 | 283 | $board = array(); |
| 284 | 284 | $row = array(); |
| 285 | - for($i=0;$i<8;$i++) { |
|
| 285 | + for ($i = 0; $i < 8; $i++) { |
|
| 286 | 286 | $row[] = null; |
| 287 | 287 | } |
| 288 | - for($i=0;$i<8;$i++) { |
|
| 288 | + for ($i = 0; $i < 8; $i++) { |
|
| 289 | 289 | $board[] = $row; |
| 290 | 290 | } |
| 291 | - foreach($pieces as $piece) { |
|
| 292 | - if($board[$piece->getY()][$piece->getX()] != null) { |
|
| 291 | + foreach ($pieces as $piece) { |
|
| 292 | + if ($board[$piece->getY()][$piece->getX()] != null) { |
|
| 293 | 293 | throw new Exception('Two pieces found in the same tile.'); |
| 294 | 294 | } |
| 295 | 295 | $board[$piece->getY()][$piece->getX()] = $piece; |
@@ -300,8 +300,7 @@ discard block |
||
| 300 | 300 | public static function getStandardGame($chessGameID, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
| 301 | 301 | $white = $whitePlayer->getAccountID(); |
| 302 | 302 | $black = $blackPlayer->getAccountID(); |
| 303 | - return array |
|
| 304 | - ( |
|
| 303 | + return array( |
|
| 305 | 304 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::ROOK, 0, 0), |
| 306 | 305 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::KNIGHT, 1, 0), |
| 307 | 306 | new ChessPiece($chessGameID, $black, self::PLAYER_BLACK, ChessPiece::BISHOP, 2, 0), |
@@ -341,7 +340,7 @@ discard block |
||
| 341 | 340 | } |
| 342 | 341 | |
| 343 | 342 | public static function insertNewGame($startDate, $endDate, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
| 344 | - if($startDate == null) { |
|
| 343 | + if ($startDate == null) { |
|
| 345 | 344 | throw new Exception('Start date cannot be null.'); |
| 346 | 345 | } |
| 347 | 346 | |
@@ -359,7 +358,7 @@ discard block |
||
| 359 | 358 | private static function insertPieces($chessGameID, AbstractSmrPlayer $whitePlayer, AbstractSmrPlayer $blackPlayer) { |
| 360 | 359 | $db = new SmrMySqlDatabase(); |
| 361 | 360 | $pieces = self::getStandardGame($chessGameID, $whitePlayer, $blackPlayer); |
| 362 | - foreach($pieces as $p) { |
|
| 361 | + foreach ($pieces as $p) { |
|
| 363 | 362 | $db->query('INSERT INTO chess_game_pieces' . |
| 364 | 363 | '(chess_game_id,account_id,piece_id,x,y)' . |
| 365 | 364 | 'values' . |
@@ -371,63 +370,63 @@ discard block |
||
| 371 | 370 | // This move will be set as the most recent move |
| 372 | 371 | $this->lastMove = [ |
| 373 | 372 | 'From' => ['X' => $startX, 'Y' => $startY], |
| 374 | - 'To' => ['X' => $endX, 'Y' => $endY], |
|
| 373 | + 'To' => ['X' => $endX, 'Y' => $endY], |
|
| 375 | 374 | ]; |
| 376 | 375 | |
| 377 | 376 | $otherPlayerColour = self::getOtherColour($playerColour); |
| 378 | - if($pieceID == ChessPiece::KING) { |
|
| 377 | + if ($pieceID == ChessPiece::KING) { |
|
| 379 | 378 | $this->hasMoved[$playerColour][ChessPiece::KING] = true; |
| 380 | 379 | } |
| 381 | 380 | // Check if the piece moving is a rook and mark it as moved to stop castling. |
| 382 | - if($pieceID == ChessPiece::ROOK && ($startX == 0 || $startX == 7) && ($startY == ($playerColour == self::PLAYER_WHITE ? 7 : 0))) { |
|
| 383 | - $this->hasMoved[$playerColour][ChessPiece::ROOK][$startX==0?'Queen':'King'] = true; |
|
| 381 | + if ($pieceID == ChessPiece::ROOK && ($startX == 0 || $startX == 7) && ($startY == ($playerColour == self::PLAYER_WHITE ? 7 : 0))) { |
|
| 382 | + $this->hasMoved[$playerColour][ChessPiece::ROOK][$startX == 0 ? 'Queen' : 'King'] = true; |
|
| 384 | 383 | } |
| 385 | 384 | // Check if we've taken a rook and marked them as moved, if they've already moved this does nothing, but if they were taken before moving this stops an issue with trying to castle with a non-existent castle. |
| 386 | - if($pieceTaken == ChessPiece::ROOK && ($endX == 0 || $endX == 7) && $endY == ($otherPlayerColour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 387 | - $this->hasMoved[$otherPlayerColour][ChessPiece::ROOK][$endX==0?'Queen':'King'] = true; |
|
| 385 | + if ($pieceTaken == ChessPiece::ROOK && ($endX == 0 || $endX == 7) && $endY == ($otherPlayerColour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 386 | + $this->hasMoved[$otherPlayerColour][ChessPiece::ROOK][$endX == 0 ? 'Queen' : 'King'] = true; |
|
| 388 | 387 | } |
| 389 | - if($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
|
| 388 | + if ($pieceID == ChessPiece::PAWN && ($startY == 1 || $startY == 6) && ($endY == 3 || $endY == 4)) { |
|
| 390 | 389 | $this->hasMoved[ChessPiece::PAWN] = array($endX, $endY); |
| 391 | 390 | } |
| 392 | 391 | else { |
| 393 | - $this->hasMoved[ChessPiece::PAWN] = array(-1,-1); |
|
| 392 | + $this->hasMoved[ChessPiece::PAWN] = array(-1, -1); |
|
| 394 | 393 | } |
| 395 | 394 | return ($castling == 'Queen' ? '0-0-0' : ($castling == 'King' ? '0-0' : '')) |
| 396 | 395 | . ChessPiece::getSymbolForPiece($pieceID, $playerColour) |
| 397 | - . chr(ord('a')+$startX) |
|
| 398 | - . (8-$startY) |
|
| 396 | + . chr(ord('a') + $startX) |
|
| 397 | + . (8 - $startY) |
|
| 399 | 398 | . ' ' |
| 400 | 399 | . ($pieceTaken == null ? '' : ChessPiece::getSymbolForPiece($pieceTaken, $otherPlayerColour)) |
| 401 | - . chr(ord('a')+$endX) |
|
| 402 | - . (8-$endY) |
|
| 400 | + . chr(ord('a') + $endX) |
|
| 401 | + . (8 - $endY) |
|
| 403 | 402 | . ($promotionPieceID == null ? '' : ChessPiece::getSymbolForPiece($promotionPieceID, $playerColour)) |
| 404 | 403 | . ' ' |
| 405 | - . ($checking == null ? '' : ($checking == 'CHECK' ? '+' : '++') ) |
|
| 404 | + . ($checking == null ? '' : ($checking == 'CHECK' ? '+' : '++')) |
|
| 406 | 405 | . ($enPassant ? ' e.p.' : ''); |
| 407 | 406 | } |
| 408 | 407 | |
| 409 | 408 | public function isCheckmated($colour) { |
| 410 | 409 | $king = null; |
| 411 | - foreach($this->board as $row) { |
|
| 412 | - foreach($row as $piece) { |
|
| 413 | - if($piece != null && $piece->pieceID == ChessPiece::KING && $piece->colour == $colour) { |
|
| 410 | + foreach ($this->board as $row) { |
|
| 411 | + foreach ($row as $piece) { |
|
| 412 | + if ($piece != null && $piece->pieceID == ChessPiece::KING && $piece->colour == $colour) { |
|
| 414 | 413 | $king = $piece; |
| 415 | 414 | break; |
| 416 | 415 | } |
| 417 | 416 | } |
| 418 | 417 | } |
| 419 | - if($king == null) { |
|
| 418 | + if ($king == null) { |
|
| 420 | 419 | throw new Exception('Could not find the king: game id = ' . $this->chessGameID); |
| 421 | 420 | } |
| 422 | - if(!self::isPlayerChecked($this->board, $this->getHasMoved(), $colour)) { |
|
| 421 | + if (!self::isPlayerChecked($this->board, $this->getHasMoved(), $colour)) { |
|
| 423 | 422 | return false; |
| 424 | 423 | } |
| 425 | - foreach($this->board as $row) { |
|
| 426 | - foreach($row as $piece) { |
|
| 427 | - if($piece != null && $piece->colour == $colour) { |
|
| 424 | + foreach ($this->board as $row) { |
|
| 425 | + foreach ($row as $piece) { |
|
| 426 | + if ($piece != null && $piece->colour == $colour) { |
|
| 428 | 427 | $moves = $piece->getPossibleMoves($this->board, $this->getHasMoved()); |
| 429 | 428 | //There are moves we can make, we are clearly not checkmated. |
| 430 | - if(count($moves) > 0) { |
|
| 429 | + if (count($moves) > 0) { |
|
| 431 | 430 | return false; |
| 432 | 431 | } |
| 433 | 432 | } |
@@ -438,15 +437,15 @@ discard block |
||
| 438 | 437 | |
| 439 | 438 | public static function isCastling($x, $toX) { |
| 440 | 439 | $movement = $toX - $x; |
| 441 | - if(abs($movement) == 2) { |
|
| 440 | + if (abs($movement) == 2) { |
|
| 442 | 441 | //To the left. |
| 443 | - if($movement == -2) { |
|
| 442 | + if ($movement == -2) { |
|
| 444 | 443 | return array('Type' => 'Queen', |
| 445 | 444 | 'X' => 0, |
| 446 | 445 | 'ToX' => 3 |
| 447 | 446 | ); |
| 448 | 447 | } //To the right |
| 449 | - else if($movement == 2) { |
|
| 448 | + else if ($movement == 2) { |
|
| 450 | 449 | return array('Type' => 'King', |
| 451 | 450 | 'X' => 7, |
| 452 | 451 | 'ToX' => 5 |
@@ -457,36 +456,36 @@ discard block |
||
| 457 | 456 | } |
| 458 | 457 | |
| 459 | 458 | public static function movePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $pawnPromotionPiece = ChessPiece::QUEEN) { |
| 460 | - if(!self::isValidCoord($x, $y, $board)) { |
|
| 459 | + if (!self::isValidCoord($x, $y, $board)) { |
|
| 461 | 460 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
| 462 | 461 | } |
| 463 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
| 462 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
| 464 | 463 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
| 465 | 464 | } |
| 466 | 465 | $pieceTaken = $board[$toY][$toX]; |
| 467 | 466 | $board[$toY][$toX] = $board[$y][$x]; |
| 468 | - $p =& $board[$toY][$toX]; |
|
| 467 | + $p = & $board[$toY][$toX]; |
|
| 469 | 468 | $board[$y][$x] = null; |
| 470 | - if($p == null) { |
|
| 469 | + if ($p == null) { |
|
| 471 | 470 | throw new Exception('Trying to move non-existent piece: ' . var_export($board, true)); |
| 472 | 471 | } |
| 473 | 472 | $p->setX($toX); |
| 474 | 473 | $p->setY($toY); |
| 475 | 474 | |
| 476 | 475 | $oldPawnMovement = $hasMoved[ChessPiece::PAWN]; |
| 477 | - $nextPawnMovement = array(-1,-1); |
|
| 476 | + $nextPawnMovement = array(-1, -1); |
|
| 478 | 477 | $castling = false; |
| 479 | 478 | $enPassant = false; |
| 480 | 479 | $rookMoved = false; |
| 481 | 480 | $rookTaken = false; |
| 482 | 481 | $pawnPromotion = false; |
| 483 | - if($p->pieceID == ChessPiece::KING) { |
|
| 482 | + if ($p->pieceID == ChessPiece::KING) { |
|
| 484 | 483 | //Castling? |
| 485 | 484 | $castling = self::isCastling($x, $toX); |
| 486 | - if($castling !== false) { |
|
| 485 | + if ($castling !== false) { |
|
| 487 | 486 | $hasMoved[$p->colour][ChessPiece::KING] = true; |
| 488 | 487 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = true; |
| 489 | - if($board[$y][$castling['X']] == null) { |
|
| 488 | + if ($board[$y][$castling['X']] == null) { |
|
| 490 | 489 | throw new Exception('Cannot castle with non-existent castle.'); |
| 491 | 490 | } |
| 492 | 491 | $board[$toY][$castling['ToX']] = $board[$y][$castling['X']]; |
@@ -494,37 +493,37 @@ discard block |
||
| 494 | 493 | $board[$y][$castling['X']] = null; |
| 495 | 494 | } |
| 496 | 495 | } |
| 497 | - else if($p->pieceID == ChessPiece::PAWN) { |
|
| 498 | - if($toY == 0 || $toY == 7) { |
|
| 496 | + else if ($p->pieceID == ChessPiece::PAWN) { |
|
| 497 | + if ($toY == 0 || $toY == 7) { |
|
| 499 | 498 | $pawnPromotion = $p->promote($pawnPromotionPiece, $board); |
| 500 | 499 | } |
| 501 | 500 | //Double move to track? |
| 502 | - else if(($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
| 501 | + else if (($y == 1 || $y == 6) && ($toY == 3 || $toY == 4)) { |
|
| 503 | 502 | $nextPawnMovement = array($toX, $toY); |
| 504 | 503 | } |
| 505 | 504 | //En passant? |
| 506 | - else if($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
| 505 | + else if ($hasMoved[ChessPiece::PAWN][0] == $toX && |
|
| 507 | 506 | ($hasMoved[ChessPiece::PAWN][1] == 3 && $toY == 2 || $hasMoved[ChessPiece::PAWN][1] == 4 && $toY == 5)) { |
| 508 | 507 | $enPassant = true; |
| 509 | 508 | $pieceTaken = $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]]; |
| 510 | - if($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
| 509 | + if ($board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] == null) { |
|
| 511 | 510 | throw new Exception('Cannot en passant a non-existent pawn.'); |
| 512 | 511 | } |
| 513 | 512 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = null; |
| 514 | 513 | } |
| 515 | 514 | } |
| 516 | - else if($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 515 | + else if ($p->pieceID == ChessPiece::ROOK && ($x == 0 || $x == 7) && $y == ($p->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 517 | 516 | //Rook moved? |
| 518 | - if($hasMoved[$p->colour][ChessPiece::ROOK][$x==0?'Queen':'King'] === false) { |
|
| 517 | + if ($hasMoved[$p->colour][ChessPiece::ROOK][$x == 0 ? 'Queen' : 'King'] === false) { |
|
| 519 | 518 | // We set rook moved in here as it's used for move info. |
| 520 | - $rookMoved = $x==0?'Queen':'King'; |
|
| 519 | + $rookMoved = $x == 0 ? 'Queen' : 'King'; |
|
| 521 | 520 | $hasMoved[$p->colour][ChessPiece::ROOK][$rookMoved] = true; |
| 522 | 521 | } |
| 523 | 522 | } |
| 524 | 523 | // Check if we've taken a rook and marked them as moved, if they've already moved this does nothing, but if they were taken before moving this stops an issue with trying to castle with a non-existent castle. |
| 525 | - if($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 526 | - if($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX==0?'Queen':'King'] === false) { |
|
| 527 | - $rookTaken = $toX==0?'Queen':'King'; |
|
| 524 | + if ($pieceTaken != null && $pieceTaken->pieceID == ChessPiece::ROOK && ($toX == 0 || $toX == 7) && $toY == ($pieceTaken->colour == self::PLAYER_WHITE ? 7 : 0)) { |
|
| 525 | + if ($hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$toX == 0 ? 'Queen' : 'King'] === false) { |
|
| 526 | + $rookTaken = $toX == 0 ? 'Queen' : 'King'; |
|
| 528 | 527 | $hasMoved[$pieceTaken->colour][ChessPiece::ROOK][$rookTaken] = true; |
| 529 | 528 | } |
| 530 | 529 | } |
@@ -541,18 +540,18 @@ discard block |
||
| 541 | 540 | } |
| 542 | 541 | |
| 543 | 542 | public static function undoMovePiece(array &$board, array &$hasMoved, $x, $y, $toX, $toY, $moveInfo) { |
| 544 | - if(!self::isValidCoord($x, $y, $board)) { |
|
| 543 | + if (!self::isValidCoord($x, $y, $board)) { |
|
| 545 | 544 | throw new Exception('Invalid from coordinates, x=' . $x . ', y=' . $y); |
| 546 | 545 | } |
| 547 | - if(!self::isValidCoord($toX, $toY, $board)) { |
|
| 546 | + if (!self::isValidCoord($toX, $toY, $board)) { |
|
| 548 | 547 | throw new Exception('Invalid to coordinates, x=' . $toX . ', y=' . $toY); |
| 549 | 548 | } |
| 550 | - if($board[$y][$x] != null) { |
|
| 549 | + if ($board[$y][$x] != null) { |
|
| 551 | 550 | throw new Exception('Undoing move onto another piece? x=' . $x . ', y=' . $y); |
| 552 | 551 | } |
| 553 | 552 | $board[$y][$x] = $board[$toY][$toX]; |
| 554 | - $p =& $board[$y][$x]; |
|
| 555 | - if($p == null) { |
|
| 553 | + $p = & $board[$y][$x]; |
|
| 554 | + if ($p == null) { |
|
| 556 | 555 | throw new Exception('Trying to undo move of a non-existent piece: ' . var_export($board, true)); |
| 557 | 556 | } |
| 558 | 557 | $board[$toY][$toX] = $moveInfo['PieceTaken']; |
@@ -561,12 +560,12 @@ discard block |
||
| 561 | 560 | |
| 562 | 561 | $hasMoved[ChessPiece::PAWN] = $moveInfo['OldPawnMovement']; |
| 563 | 562 | //Castling |
| 564 | - if($p->pieceID == ChessPiece::KING) { |
|
| 563 | + if ($p->pieceID == ChessPiece::KING) { |
|
| 565 | 564 | $castling = self::isCastling($x, $toX); |
| 566 | - if($castling !== false) { |
|
| 565 | + if ($castling !== false) { |
|
| 567 | 566 | $hasMoved[$p->colour][ChessPiece::KING] = false; |
| 568 | 567 | $hasMoved[$p->colour][ChessPiece::ROOK][$castling['Type']] = false; |
| 569 | - if($board[$toY][$castling['ToX']] == null) { |
|
| 568 | + if ($board[$toY][$castling['ToX']] == null) { |
|
| 570 | 569 | throw new Exception('Cannot undo castle with non-existent castle.'); |
| 571 | 570 | } |
| 572 | 571 | $board[$y][$castling['X']] = $board[$toY][$castling['ToX']]; |
@@ -574,25 +573,25 @@ discard block |
||
| 574 | 573 | $board[$toY][$castling['ToX']] = null; |
| 575 | 574 | } |
| 576 | 575 | } |
| 577 | - else if($moveInfo['EnPassant'] === true) { |
|
| 576 | + else if ($moveInfo['EnPassant'] === true) { |
|
| 578 | 577 | $board[$toY][$toX] = null; |
| 579 | 578 | $board[$hasMoved[ChessPiece::PAWN][1]][$hasMoved[ChessPiece::PAWN][0]] = $moveInfo['PieceTaken']; |
| 580 | 579 | } |
| 581 | - else if($moveInfo['RookMoved'] !== false) { |
|
| 580 | + else if ($moveInfo['RookMoved'] !== false) { |
|
| 582 | 581 | $hasMoved[$p->colour][ChessPiece::ROOK][$moveInfo['RookMoved']] = false; |
| 583 | 582 | } |
| 584 | - if($moveInfo['RookTaken'] !== false) { |
|
| 583 | + if ($moveInfo['RookTaken'] !== false) { |
|
| 585 | 584 | $hasMoved[$moveInfo['PieceTaken']->colour][ChessPiece::ROOK][$moveInfo['RookTaken']] = false; |
| 586 | 585 | } |
| 587 | 586 | } |
| 588 | 587 | |
| 589 | 588 | public function tryAlgebraicMove($move) { |
| 590 | - if(strlen($move) != 4 && strlen($move) != 5) { |
|
| 589 | + if (strlen($move) != 4 && strlen($move) != 5) { |
|
| 591 | 590 | throw new Exception('Move of length "' . strlen($move) . '" is not valid, full move: ' . $move); |
| 592 | 591 | } |
| 593 | 592 | $aVal = ord('a'); |
| 594 | 593 | $hVal = ord('h'); |
| 595 | - if(ord($move[0]) < $aVal || ord($move[2]) < $aVal |
|
| 594 | + if (ord($move[0]) < $aVal || ord($move[2]) < $aVal |
|
| 596 | 595 | || ord($move[0]) > $hVal || ord($move[2]) > $hVal |
| 597 | 596 | || $move[1] < 1 || $move[3] < 1 |
| 598 | 597 | || $move[1] > 8 || $move[3] > 8) { |
@@ -603,73 +602,73 @@ discard block |
||
| 603 | 602 | $toX = ord($move[2]) - $aVal; |
| 604 | 603 | $toY = 8 - $move[3]; |
| 605 | 604 | $pawnPromotionPiece = null; |
| 606 | - if(isset($move[4])) { |
|
| 605 | + if (isset($move[4])) { |
|
| 607 | 606 | $pawnPromotionPiece = ChessPiece::getPieceForLetter($move[4]); |
| 608 | 607 | } |
| 609 | 608 | return $this->tryMove($x, $y, $toX, $toY, $this->getCurrentTurnAccountID(), $pawnPromotionPiece); |
| 610 | 609 | } |
| 611 | 610 | |
| 612 | 611 | public function tryMove($x, $y, $toX, $toY, $forAccountID, $pawnPromotionPiece) { |
| 613 | - if($this->hasEnded()) { |
|
| 612 | + if ($this->hasEnded()) { |
|
| 614 | 613 | return 5; |
| 615 | 614 | } |
| 616 | - if($this->getCurrentTurnAccountID() != $forAccountID) { |
|
| 615 | + if ($this->getCurrentTurnAccountID() != $forAccountID) { |
|
| 617 | 616 | return 4; |
| 618 | 617 | } |
| 619 | 618 | $lastTurnPlayer = $this->getCurrentTurnPlayer(); |
| 620 | 619 | $this->getBoard(); |
| 621 | 620 | $p = $this->board[$y][$x]; |
| 622 | - if($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
| 621 | + if ($p == null || $p->colour != $this->getColourForAccountID($forAccountID)) { |
|
| 623 | 622 | return 2; |
| 624 | 623 | } |
| 625 | 624 | |
| 626 | 625 | $moves = $p->getPossibleMoves($this->board, $this->getHasMoved(), $forAccountID); |
| 627 | - foreach($moves as $move) { |
|
| 628 | - if($move[0]==$toX && $move[1]==$toY) { |
|
| 626 | + foreach ($moves as $move) { |
|
| 627 | + if ($move[0] == $toX && $move[1] == $toY) { |
|
| 629 | 628 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
| 630 | 629 | $currentPlayer = $this->getCurrentTurnPlayer(); |
| 631 | 630 | |
| 632 | 631 | $moveInfo = ChessGame::movePiece($this->board, $this->getHasMoved(), $x, $y, $toX, $toY, $pawnPromotionPiece); |
| 633 | 632 | |
| 634 | 633 | //We have taken the move, we should refresh $p |
| 635 | - $p =& $this->board[$toY][$toX]; |
|
| 634 | + $p = & $this->board[$toY][$toX]; |
|
| 636 | 635 | |
| 637 | 636 | $pieceTakenID = null; |
| 638 | - if($moveInfo['PieceTaken'] != null) { |
|
| 637 | + if ($moveInfo['PieceTaken'] != null) { |
|
| 639 | 638 | $pieceTakenID = $moveInfo['PieceTaken']->pieceID; |
| 640 | - if($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
| 639 | + if ($moveInfo['PieceTaken']->pieceID == ChessPiece::KING) { |
|
| 641 | 640 | throw new Exception('King was taken.'); |
| 642 | 641 | } |
| 643 | 642 | } |
| 644 | 643 | |
| 645 | 644 | $pieceID = $p->pieceID; |
| 646 | 645 | $pieceNo = $p->pieceNo; |
| 647 | - if($moveInfo['PawnPromotion'] !== false) { |
|
| 646 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
| 648 | 647 | $p->pieceID = $moveInfo['PawnPromotion']['PieceID']; |
| 649 | 648 | $p->pieceNo = $moveInfo['PawnPromotion']['PieceNo']; |
| 650 | 649 | } |
| 651 | 650 | |
| 652 | 651 | $checking = null; |
| 653 | - if($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
| 652 | + if ($p->isAttacking($this->board, $this->getHasMoved(), true)) { |
|
| 654 | 653 | $checking = 'CHECK'; |
| 655 | 654 | } |
| 656 | - if($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
| 655 | + if ($this->isCheckmated(self::getOtherColour($p->colour))) { |
|
| 657 | 656 | $checking = 'MATE'; |
| 658 | 657 | } |
| 659 | - if($this->moves!=null) { |
|
| 658 | + if ($this->moves != null) { |
|
| 660 | 659 | $this->moves[] = $this->createMove($pieceID, $x, $y, $toX, $toY, $pieceTakenID, $checking, $this->getCurrentTurnColour(), $moveInfo['Castling']['Type'], $moveInfo['EnPassant'], $moveInfo['PawnPromotion'] === false ? null : $moveInfo['PawnPromotion']['PieceID']); |
| 661 | 660 | } |
| 662 | - if(self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
| 661 | + if (self::isPlayerChecked($this->board, $this->getHasMoved(), $p->colour)) { |
|
| 663 | 662 | return 3; |
| 664 | 663 | } |
| 665 | 664 | |
| 666 | 665 | $otherPlayer = $this->getCurrentTurnPlayer(); |
| 667 | - if($moveInfo['PawnPromotion'] !== false) { |
|
| 666 | + if ($moveInfo['PawnPromotion'] !== false) { |
|
| 668 | 667 | $piecePromotedSymbol = $p->getPieceSymbol(); |
| 669 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted','Total'), HOF_PUBLIC); |
|
| 670 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted','Total'), HOF_PUBLIC); |
|
| 671 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Own Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
| 672 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pawns Promoted',$piecePromotedSymbol), HOF_PUBLIC); |
|
| 668 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pawns Promoted', 'Total'), HOF_PUBLIC); |
|
| 669 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pawns Promoted', 'Total'), HOF_PUBLIC); |
|
| 670 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pawns Promoted', $piecePromotedSymbol), HOF_PUBLIC); |
|
| 671 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pawns Promoted', $piecePromotedSymbol), HOF_PUBLIC); |
|
| 673 | 672 | } |
| 674 | 673 | |
| 675 | 674 | $castlingType = $moveInfo['Castling'] === false ? null : $moveInfo['Castling']['Type']; |
@@ -679,37 +678,37 @@ discard block |
||
| 679 | 678 | (' . $this->db->escapeNumber($p->chessGameID) . ',' . $this->db->escapeNumber($pieceID) . ',' . $this->db->escapeNumber($x) . ',' . $this->db->escapeNumber($y) . ',' . $this->db->escapeNumber($toX) . ',' . $this->db->escapeNumber($toY) . ',' . $this->db->escapeString($checking, true, true) . ',' . ($moveInfo['PieceTaken'] == null ? 'NULL' : $this->db->escapeNumber($moveInfo['PieceTaken']->pieceID)) . ',' . $this->db->escapeString($castlingType, true, true) . ',' . $this->db->escapeBoolean($moveInfo['EnPassant']) . ',' . ($moveInfo['PawnPromotion'] == false ? 'NULL' : $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID'])) . ');'); |
| 680 | 679 | |
| 681 | 680 | |
| 682 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Total Taken'), HOF_PUBLIC); |
|
| 683 | - if($moveInfo['PieceTaken'] != null) { |
|
| 681 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Total Taken'), HOF_PUBLIC); |
|
| 682 | + if ($moveInfo['PieceTaken'] != null) { |
|
| 684 | 683 | $this->db->query('DELETE FROM chess_game_pieces |
| 685 | 684 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ' AND account_id=' . $this->db->escapeNumber($moveInfo['PieceTaken']->accountID) . ' AND piece_id=' . $this->db->escapeNumber($moveInfo['PieceTaken']->pieceID) . ' AND piece_no=' . $this->db->escapeNumber($moveInfo['PieceTaken']->pieceNo) . ';'); |
| 686 | 685 | |
| 687 | 686 | $pieceTakenSymbol = $moveInfo['PieceTaken']->getPieceSymbol(); |
| 688 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pieces Taken','Total'), HOF_PUBLIC); |
|
| 689 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Own Pieces Taken','Total'), HOF_PUBLIC); |
|
| 690 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Opponent Pieces Taken',$pieceTakenSymbol), HOF_PUBLIC); |
|
| 691 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Own Pieces Taken',$pieceTakenSymbol), HOF_PUBLIC); |
|
| 687 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', 'Total'), HOF_PUBLIC); |
|
| 688 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', 'Total'), HOF_PUBLIC); |
|
| 689 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Opponent Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC); |
|
| 690 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Own Pieces Taken', $pieceTakenSymbol), HOF_PUBLIC); |
|
| 692 | 691 | } |
| 693 | 692 | $this->db->query('UPDATE chess_game_pieces |
| 694 | 693 | SET x=' . $this->db->escapeNumber($toX) . ', y=' . $this->db->escapeNumber($toY) . |
| 695 | 694 | ($moveInfo['PawnPromotion'] !== false ? ', piece_id=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceID']) . ', piece_no=' . $this->db->escapeNumber($moveInfo['PawnPromotion']['PieceNo']) : '') . ' |
| 696 | 695 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ' AND account_id=' . $this->db->escapeNumber($p->accountID) . ' AND piece_id=' . $this->db->escapeNumber($pieceID) . ' AND piece_no=' . $this->db->escapeNumber($pieceNo) . ';'); |
| 697 | - if($moveInfo['Castling'] !== false) { |
|
| 696 | + if ($moveInfo['Castling'] !== false) { |
|
| 698 | 697 | $this->db->query('UPDATE chess_game_pieces |
| 699 | 698 | SET x=' . $this->db->escapeNumber($moveInfo['Castling']['ToX']) . ' |
| 700 | 699 | WHERE chess_game_id=' . $this->db->escapeNumber($this->chessGameID) . ' AND account_id=' . $this->db->escapeNumber($p->accountID) . ' AND x = ' . $this->db->escapeNumber($moveInfo['Castling']['X']) . ' AND y = ' . $this->db->escapeNumber($y) . ';'); |
| 701 | 700 | } |
| 702 | 701 | $return = 0; |
| 703 | - if($checking == 'MATE') { |
|
| 702 | + if ($checking == 'MATE') { |
|
| 704 | 703 | $this->setWinner($forAccountID); |
| 705 | 704 | $return = 1; |
| 706 | 705 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'You have just lost [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
| 707 | 706 | } |
| 708 | 707 | else { |
| 709 | 708 | SmrPlayer::sendMessageFromCasino($lastTurnPlayer->getGameID(), $this->getCurrentTurnAccountID(), 'It is now your turn in [chess=' . $this->getChessGameID() . '] against [player=' . $lastTurnPlayer->getPlayerID() . '].'); |
| 710 | - if($checking == 'CHECK') { |
|
| 711 | - $currentPlayer->increaseHOF(1, array($chessType,'Moves','Check Given'), HOF_PUBLIC); |
|
| 712 | - $otherPlayer->increaseHOF(1, array($chessType,'Moves','Check Received'), HOF_PUBLIC); |
|
| 709 | + if ($checking == 'CHECK') { |
|
| 710 | + $currentPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Given'), HOF_PUBLIC); |
|
| 711 | + $otherPlayer->increaseHOF(1, array($chessType, 'Moves', 'Check Received'), HOF_PUBLIC); |
|
| 713 | 712 | } |
| 714 | 713 | } |
| 715 | 714 | $currentPlayer->saveHOF(); |
@@ -748,10 +747,10 @@ discard block |
||
| 748 | 747 | } |
| 749 | 748 | |
| 750 | 749 | public function getColourID($colour) { |
| 751 | - if($colour == self::PLAYER_WHITE) { |
|
| 750 | + if ($colour == self::PLAYER_WHITE) { |
|
| 752 | 751 | return $this->getWhiteID(); |
| 753 | 752 | } |
| 754 | - if($colour == self::PLAYER_BLACK) { |
|
| 753 | + if ($colour == self::PLAYER_BLACK) { |
|
| 755 | 754 | return $this->getBlackID(); |
| 756 | 755 | } |
| 757 | 756 | } |
@@ -761,10 +760,10 @@ discard block |
||
| 761 | 760 | } |
| 762 | 761 | |
| 763 | 762 | public function getColourForAccountID($accountID) { |
| 764 | - if($accountID == $this->getWhiteID()) { |
|
| 763 | + if ($accountID == $this->getWhiteID()) { |
|
| 765 | 764 | return self::PLAYER_WHITE; |
| 766 | 765 | } |
| 767 | - if($accountID == $this->getBlackID()) { |
|
| 766 | + if ($accountID == $this->getBlackID()) { |
|
| 768 | 767 | return self::PLAYER_BLACK; |
| 769 | 768 | } |
| 770 | 769 | return false; |
@@ -792,8 +791,8 @@ discard block |
||
| 792 | 791 | $winningPlayer = $this->getColourPlayer($winnerColour); |
| 793 | 792 | $losingPlayer = $this->getColourPlayer(self::getOtherColour($winnerColour)); |
| 794 | 793 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
| 795 | - $winningPlayer->increaseHOF(1, array($chessType,'Games','Won'), HOF_PUBLIC); |
|
| 796 | - $losingPlayer->increaseHOF(1, array($chessType,'Games','Lost'), HOF_PUBLIC); |
|
| 794 | + $winningPlayer->increaseHOF(1, array($chessType, 'Games', 'Won'), HOF_PUBLIC); |
|
| 795 | + $losingPlayer->increaseHOF(1, array($chessType, 'Games', 'Lost'), HOF_PUBLIC); |
|
| 797 | 796 | return array('Winner' => $winningPlayer, 'Loser' => $losingPlayer); |
| 798 | 797 | } |
| 799 | 798 | |
@@ -834,21 +833,21 @@ discard block |
||
| 834 | 833 | } |
| 835 | 834 | |
| 836 | 835 | public static function getOtherColour($colour) { |
| 837 | - if($colour == self::PLAYER_WHITE) { |
|
| 836 | + if ($colour == self::PLAYER_WHITE) { |
|
| 838 | 837 | return self::PLAYER_BLACK; |
| 839 | 838 | } |
| 840 | - if($colour == self::PLAYER_BLACK) { |
|
| 839 | + if ($colour == self::PLAYER_BLACK) { |
|
| 841 | 840 | return self::PLAYER_WHITE; |
| 842 | 841 | } |
| 843 | 842 | return false; |
| 844 | 843 | } |
| 845 | 844 | |
| 846 | 845 | public function resign($accountID) { |
| 847 | - if($this->hasEnded() || !$this->getColourForAccountID($accountID)) { |
|
| 846 | + if ($this->hasEnded() || !$this->getColourForAccountID($accountID)) { |
|
| 848 | 847 | return false; |
| 849 | 848 | } |
| 850 | 849 | // If only 1 person has moved then just end the game. |
| 851 | - if(count($this->getMoves()) < 2) { |
|
| 850 | + if (count($this->getMoves()) < 2) { |
|
| 852 | 851 | $this->endDate = TIME; |
| 853 | 852 | $this->db->query('UPDATE chess_game |
| 854 | 853 | SET end_time=' . $this->db->escapeNumber(TIME) . ' |
@@ -860,17 +859,17 @@ discard block |
||
| 860 | 859 | $winnerAccountID = $this->getColourID(self::getOtherColour($loserColour)); |
| 861 | 860 | $results = $this->setWinner($winnerAccountID); |
| 862 | 861 | $chessType = $this->isNPCGame() ? 'Chess (NPC)' : 'Chess'; |
| 863 | - $results['Loser']->increaseHOF(1, array($chessType,'Games','Resigned'), HOF_PUBLIC); |
|
| 862 | + $results['Loser']->increaseHOF(1, array($chessType, 'Games', 'Resigned'), HOF_PUBLIC); |
|
| 864 | 863 | SmrPlayer::sendMessageFromCasino($results['Winner']->getGameID(), $results['Winner']->getPlayerID(), '[player=' . $results['Loser']->getPlayerID() . '] just resigned against you in [chess=' . $this->getChessGameID() . '].'); |
| 865 | 864 | return 0; |
| 866 | 865 | } |
| 867 | 866 | } |
| 868 | 867 | |
| 869 | 868 | public function getPlayGameHREF() { |
| 870 | - return SmrSession::getNewHREF(create_container('skeleton.php','chess_play.php',array('ChessGameID' => $this->chessGameID))); |
|
| 869 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_play.php', array('ChessGameID' => $this->chessGameID))); |
|
| 871 | 870 | } |
| 872 | 871 | |
| 873 | 872 | public function getResignHREF() { |
| 874 | - return SmrSession::getNewHREF(create_container('skeleton.php','chess_resign_processing.php',array('ChessGameID' => $this->chessGameID))); |
|
| 873 | + return SmrSession::getNewHREF(create_container('skeleton.php', 'chess_resign_processing.php', array('ChessGameID' => $this->chessGameID))); |
|
| 875 | 874 | } |
| 876 | 875 | } |