Example #1
0
 public function testHistoryPrettyMoves()
 {
     $chess = new ChessPublicator();
     $moves = ["e4", "e6", "d4", "d5", "Nc3", "Nf6", "Bg5", "dxe4", "Nxe4", "Be7", "Bxf6", "gxf6", "g3", "f5", "Nc3", "Bf6"];
     foreach ($moves as $move) {
         $this->assertNotNull($chess->move($move), $move);
     }
     $histories = $chess->history(['verbose' => true]);
     $this->assertSame(count($histories), count($moves));
     foreach ($histories as $k => $history) {
         $this->assertSame($history['san'], $moves[$k]);
     }
 }
Example #2
0
 /**
  * @depends testParsePgn
  * @depends testValidatePgn
  */
 public function testLoadPgn()
 {
     $chess = new ChessPublicator();
     $return = $chess->loadPgn('1.e4 e5 2.Nf3');
     $this->assertSame($chess->fen(), 'rnbqkbnr/pppp1ppp/8/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2');
     $return = $chess->loadPgn('1.e4 e5 2.e4');
     $this->assertFalse($return);
     $return = $chess->loadPgn('1.e4 e5 make it invalid 2.Nf3');
     $this->assertFalse($return);
 }
Example #3
0
    public function testinThreefoldRepetition()
    {
        $chess = new ChessPublicator();
        /*
         * [Event "Fischer - Petrosian Candidates Final"]
         * [Site "Buenos Aires ARG"]
         * [Date "1971.10.07"]
         * [EventDate "1971.09.30"]
         * [Round "3"]
         * [Result "1/2-1/2"]
         * [White "Robert James Fischer"]
         * [Black "Tigran Vartanovich Petrosian"]
         * [ECO "C11"]
         * [WhiteElo "?"]
         * [BlackElo "?"]
         * [PlyCount "67"]
         */
        $match = '1. e4 e6 2. d4 d5 3. Nc3 Nf6 4. Bg5 dxe4 5. Nxe4 Be7 6. Bxf6
		gxf6 7. g3 f5 8. Nc3 Bf6 9. Nge2 Nc6 10. d5 exd5 11. Nxd5 Bxb2
		12. Bg2 O-O 13. O-O Bh8 14. Nef4 Ne5 15. Qh5 Ng6 16. Rad1 c6
		17. Ne3 Qf6 18. Kh1 Bg7 19. Bh3 Ne7 20. Rd3 Be6 21. Rfd1 Bh6
		22. Rd4 Bxf4 23. Rxf4 Rad8 24. Rxd8 Rxd8 25. Bxf5 Nxf5
		26. Nxf5 Rd5 27. g4 Bxf5 28. gxf5 h6 29. h3 Kh7 30. Qe2 Qe5
		31. Qh5 Qf6 32. Qe2 Re5 33.Qd3 Rd5 34.Qe2';
        $moves = preg_replace("/([0-9]{0,})\\./", "", $match);
        $moves = str_replace('  ', ' ', str_replace("\r", ' ', str_replace("\n", ' ', str_replace("\t", '', $moves))));
        $moves = explode(' ', trim($moves));
        foreach ($moves as $move) {
            $this->assertNotNull($chess->move($move), $move);
        }
        $this->assertSame($chess->inThreefoldRepetition(), true);
    }
Example #4
0
    public function testSANMoveFromRealGame()
    {
        $chess = new ChessPublicator();
        /* [Event "Earl tourn"]
         * [Site "?"]
         * [Date "1906.??.??"]
         * [Round "?"]
         * [White "Alekhine, Alexander"]
         * [Black "Ljubimov, T."]
         * [Result "1-0"]
         * [ECO "C58"]
         */
        $match = '1.e4 e5 2.Nf3 Nc6 3.d4 exd4 4.Nxd4 Nf6 5.Nc3 Bb4 6.Nxc6 bxc6 7.Qd4 Qe7 8.f3 d5 9.Bg5 O-O 10.O-O-O Bc5 11.Bxf6 gxf6 12.Qa4 Be3+ 13.Kb1 d4 14.Ne2 c5 15.Nc1 Be6 16.Bc4 Rfb8 17.Nd3 Rb6';
        $moves = preg_replace("/([0-9]{0,})\\./", "", $match);
        $moves = str_replace('  ', ' ', str_replace("\r", ' ', str_replace("\n", ' ', str_replace("\t", '', $moves))));
        $moves = explode(' ', trim($moves));
        //~ foreach($moves as $move) if($chess->move($move) === null) { echo $move . PHP_EOL; break; }
        foreach ($moves as $move) {
            $this->assertNotNull($chess->move($move), $move);
        }
        $this->assertSame($chess->fen(), 'r5k1/p1p1qp1p/1r2bp2/2p5/Q1BpP3/3NbP2/PPP3PP/1K1R3R w - - 6 18');
        return;
        // somehow it have to be turn off, just for faster unit testing, but if you want just comment this line
        $chess->reset();
        /* [Event "Earl tourn"]
         * [Site "?"]
         * [Date "1906.??.??"]
         * [Round "?"]
         * [White "Zubakin, N."]
         * [Black "Alekhine, Alexander"]
         * [Result "1/2-1/2"]
         * [ECO "C55"]
         */
        $match = '1.e4 e5 2.Nf3 Nc6 3.Bc4 Bc5 4.O-O d6 5.c3 Nf6 6.d4 exd4 7.cxd4 Bb6 8.Nc3 O-O
		9.h3 h6 10.Be3 Re8 11.d5 Ne5 12.Nxe5 dxe5 13.Bxb6 axb6 14.f4 Qd6 15.fxe5 Rxe5
		16.Qe2 Rg5 17.Rf3 Qc5+ 18.Kh1 Ng4 19.Rg3 Ne5 20.Rxg5 hxg5 21.Bb3 g4 22.Rf1 Qe7
		23.Qe3 Qh4 24.Qf4 Qh5 25.Nb5 gxh3 26.Qe3 hxg2+ 27.Kxg2 Qg6+ 28.Kh1 Bd7 29.Nxc7 Rc8
		30.d6 Kh7';
        $moves = preg_replace("/([0-9]{0,})\\./", "", $match);
        $moves = str_replace('  ', ' ', str_replace("\r", ' ', str_replace("\n", ' ', str_replace("\t", '', $moves))));
        $moves = explode(' ', trim($moves));
        foreach ($moves as $move) {
            $this->assertNotNull($chess->move($move), $move);
        }
        $this->assertSame($chess->fen(), '2r5/1pNb1ppk/1p1P2q1/4n3/4P3/1B2Q3/PP6/5R1K w - - 1 31');
        $chess->reset();
        /* [Event "World Championship 35th-KK5"]
         * [Site "Lyon/New York"]
         * [Date "1990.??.??"]
         * [Round "16"]
         * [White "Kasparov, Gary"]
         * [Black "Karpov, Anatoly"]
         * [Result "1-0"]
         * [WhiteElo "2800"]
         * [BlackElo "2730"]
         * [ECO "C45"]
         */
        $match = '1.e4 e5 2.Nf3 Nc6 3.d4 exd4 4.Nxd4 Nf6 5.Nxc6 bxc6 6.e5 Qe7 7.Qe2 Nd5 8.c4 Nb6
		9.Nd2 Qe6 10.b3 a5 11.Bb2 Bb4 12.a3 Bxd2+ 13.Qxd2 d5 14.cxd5 cxd5 15.Rc1 O-O
		16.Rxc7 Qg6 17.f3 Bf5 18.g4 Bb1 19.Bb5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0,})\\./", "", $match);
        $moves = str_replace('  ', ' ', str_replace("\r", ' ', str_replace("\n", ' ', str_replace("\t", '', $moves))));
        $moves = explode(' ', trim($moves));
        foreach ($moves as $move) {
            $this->assertNotNull($chess->move($move), $move);
        }
        $this->assertSame($chess->fen(), '6k1/2R1K3/3B2p1/6Pn/8/8/8/1b6 b - - 76 102');
    }
Example #5
0
 public function test7()
 {
     $chess = new ChessPublicator('8/RPP5/8/3k4/5Bp1/6Pp/P4P1P/5K2 w - - 1 42');
     $this->assertSame($chess->perft(1), 26);
 }