Exemplo n.º 1
0
 /**
  * Moves a piece and increment game turns
  *
  * @return void
  **/
 protected function move($move, array $options = array())
 {
     $manipulator = new Manipulator($this->game->getBoard());
     $manipulator->move($move, $options);
     $this->game->getBoard()->compile();
     $this->game->addTurn();
 }
Exemplo n.º 2
0
function _playWholeGame()
{
    $moves = array('e2 e4', 'd7 d5', 'e4 d5', 'd8 d5', 'b1 c3', 'd5 a5', 'd2 d4', 'c7 c6', 'g1 f3', 'c8 g4', 'c1 f4', 'e7 e6', 'h2 h3', 'g4 f3', 'd1 f3', 'f8 b4', 'f1 e2', 'b8 d7', 'a2 a3', 'e8 c8', 'a3 b4', 'a5 a1', 'e1 d2', 'a1 h1', 'f3 c6', 'b7 c6', 'e2 a6');
    $generator = new Generator();
    $game = $generator->createGame();
    $manipulator = new Manipulator($game->getBoard());
    foreach ($moves as $move) {
        $manipulator->play($move);
    }
}
Exemplo n.º 3
0
 public function testExport()
 {
     $generator = new Generator();
     $game = $generator->createGame();
     $manipulator = new Manipulator($game->getBoard());
     $forsythe = new Forsythe();
     $this->assertEquals('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq', $forsythe->export($game));
     $manipulator->play('e2 e4');
     $this->assertEquals('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq', $forsythe->export($game));
     $manipulator->play('c7 c5');
     $this->assertEquals('rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq', $forsythe->export($game));
     $manipulator->play('g1 f3');
     $this->assertEquals('rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq', $forsythe->export($game));
 }
Exemplo n.º 4
0
 public function __construct(Game $game, Stack $stack = null)
 {
     $autodraw = new Autodraw();
     $stack = $stack ?: new Stack();
     $analyser = new Analyser($game->getBoard());
     parent::__construct($game, $autodraw, $analyser, $stack);
 }
Exemplo n.º 5
0
 /**
  * apply moves
  **/
 protected function applyMoves(array $moves)
 {
     $manipulator = new Manipulator($this->game->getBoard());
     foreach ($moves as $move) {
         $manipulator->play($move);
     }
 }
Exemplo n.º 6
0
 public function inviteAiAction($hash)
 {
     $player = $this->findPlayer($hash);
     $game = $player->getGame();
     if ($game->getIsStarted()) {
         throw new \LogicException('Game already started');
     }
     $opponent = $player->getOpponent();
     $opponent->setIsAi(true);
     $opponent->setAiLevel(1);
     $game->setStatus(Game::STARTED);
     if ($player->isBlack()) {
         $ai = $this->container->getLichessAiService();
         $manipulator = new Manipulator($game->getBoard(), new Stack());
         $manipulator->play($ai->move($game, $opponent->getAiLevel()));
     }
     $this->container->getLichessPersistenceService()->save($game);
     return $this->redirect($this->generateUrl('lichess_player', array('hash' => $player->getFullHash())));
 }
Exemplo n.º 7
0
    public function testCheck()
    {
        $data = <<<EOF
        
 Q      
   k    
        
        
        
        
K       
EOF;
        $game = $this->createGame($data);
        $this->game->getBoard()->getPieceByKey('b7')->setFirstMove(1);
        $stack = new Stack();
        $manipulator = new Manipulator($this->game->getBoard(), $stack);
        $manipulator->play('b7 b6', array('promotion' => 'Knight'));
        $this->assertEquals(array(array('type' => 'move', 'from' => 'b7', 'to' => 'b6'), array('type' => 'check', 'key' => 'd6')), $stack->getEvents());
    }
Exemplo n.º 8
0
 /**
  * Moves a piece and increment game turns
  *
  * @return void
  **/
 protected function move($move, array $options = array())
 {
     $manipulator = new Manipulator($this->game->getBoard());
     $manipulator->play($move, $options);
 }