Esempio n. 1
0
 /**
  * @depends testGameCreation
  */
 public function testGamePlayers(Entities\Game $game)
 {
     $this->assertEquals(2, count($game->getPlayers()));
     $this->assertEquals(array('white', 'black'), array_keys($game->getPlayers()));
     $player = $game->getPlayer('white');
     $this->assertTrue($player instanceof Entities\Player);
     $this->assertEquals('white', $player->getColor());
     $this->assertEquals(false, $player->getIsWinner());
     $this->assertEquals(false, $player->getIsAi());
     $this->assertSame($game, $player->getGame());
     $this->assertSame($game->getPlayer('black'), $player->getOpponent());
     $this->assertSame($player, $player->getOpponent()->getOpponent());
 }
Esempio n. 2
0
 /**
  * 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;
 }
Esempio n. 3
0
 public function setPlayers()
 {
     $game = new Game();
     $game->setPlayers($this->createPlayerStubs());
     $this->assertEquals(2, count($game->getPlayers()));
 }