コード例 #1
0
ファイル: GeneratorTest.php プロジェクト: Austin-Pray/lichess
 /**
  * @depends testGameCreation
  */
 public function testGamePlayerTurn(Entities\Game $game)
 {
     $player = $game->getPlayer('white');
     $this->assertTrue($player->getIsMyTurn());
     $this->assertFalse($player->getOpponent()->getIsMyTurn());
     $game->setTurns($game->getTurns() + 1);
     $this->assertFalse($player->getIsMyTurn());
     $this->assertTrue($player->getOpponent()->getIsMyTurn());
 }
コード例 #2
0
ファイル: Forsythe.php プロジェクト: Austin-Pray/lichess
 /**
  * Transform a game to standart Forsyth Edwards Notation
  * http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation
  */
 public function export(Game $game)
 {
     $board = $game->getBoard();
     $emptySquare = 0;
     $forsythe = '';
     for ($y = 8; $y > 0; $y--) {
         for ($x = 1; $x < 9; $x++) {
             if ($piece = $board->getPieceByPos($x, $y)) {
                 if ($emptySquare) {
                     $forsythe .= $emptySquare;
                     $emptySquare = 0;
                 }
                 $forsythe .= $this->pieceToForsythe($piece);
             } else {
                 ++$emptySquare;
             }
         }
         if ($emptySquare) {
             $forsythe .= $emptySquare;
             $emptySquare = 0;
         }
         $forsythe .= '/';
     }
     $forsythe = trim($forsythe, '/');
     // b ou w to indicate turn
     $forsythe .= ' ';
     $forsythe .= $game->getTurns() % 2 ? 'b' : 'w';
     // possibles castles
     $forsythe .= ' ';
     $hasCastle = false;
     $analyser = new Analyser($board);
     foreach ($game->getPlayers() as $player) {
         if ($analyser->canCastleKingside($player)) {
             $hasCastle = true;
             $forsythe .= $player->isWhite() ? 'K' : 'k';
         }
         if ($analyser->canCastleQueenside($player)) {
             $hasCastle = true;
             $forsythe .= $player->isWhite() ? 'Q' : 'q';
         }
     }
     if (!$hasCastle) {
         $forsythe .= '-';
     }
     return $forsythe;
 }
コード例 #3
0
ファイル: Player.php プロジェクト: Austin-Pray/lichess
 public function getIsMyTurn()
 {
     return $this->game->getTurns() % 2 xor 'white' === $this->color;
 }