A chess library for PHP.
Read the latest docs here.
The PHP Chess library is open-sourced software licensed under the MIT license.
We encourage you to contribute to PHP Chess! Please follow the Contributing Guidelines.
Made with contrib.rocks.
Object-oriented library that allows to create chess apps out-of-the-box.
Home Page: https://php-chess.docs.chesslablab.org/
License: MIT License
A chess library for PHP.
Read the latest docs here.
The PHP Chess library is open-sourced software licensed under the MIT license.
We encourage you to contribute to PHP Chess! Please follow the Contributing Guidelines.
Made with contrib.rocks.
After fixing this bug on the server, now all PGN moves look like disambiguated when displayed on the frontend, as it is shown in the image attached.
This would need some fine-tuning: 1.Ng1f3 Ng8f6 2.d3 d6 3.Nf3d2
Is there currently a way to know that you can promote, as well as being able to choose which piece you promote to? It's not in the README, which is why I'm opening an issue to ask about this.
I was wondering if it was possible for creating the game based on a PGN, or a loadPGN() method on the Game class is possible? I was wondering this because I want to be able to create a board, and keep the history of a whole game, even when switching requests, as I'm using this for an API for an Android game, plus being able to save the PGN for my users would be very useful.
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
For further information, please visit:
A backward pawn is a disadvantage that a chess player or a human-like AI may want to exploit.
Every backward pawn should be counted as described in the example below.
Thus, a new file named BackwardPawnEvaluation.php
should be implemented in a similar way as the following evaluation features:
With the new feature implemented, we'll be able to take more accurate normalized heuristic pictures; for further information please visit:
Happy learning and coding!
This issue is intended to practise some unit testing skills.
A new chess opening needs to be added as the following example:
Specifically, the Symmetrical Defense to the Queen's Gambit should be tested:
1.d4 d5 2.c4 c5
Happy learning and coding!
The current class name may be confusing since the code is not documented. Chess\HeuristicFenStringToBoardPicture
should be refactored to Chess\HeuristicPictureByFenString
.
The doubled pawn evaluation should be added to Chess\HeuristicPicture and tested accordingly in Chess\Tests\Unit\HeuristicPictureTest.
For further information please visit:
Keep it up, and happy learning.
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting flipped board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
Figure 1. Fianchetto Variation of the Benoni Defense
For further information, please visit:
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting flipped board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
Figure 1. Fianchetto Variation of the Benoni Defense
For further information, please visit:
The documentation for Chess\Image\BoardToPng
should be improved by attaching a flipped board, for which the 01_kaufman_flip.png
file can be created in Chess\Tests\Unit\Image\BoardToPngTest
.
For further information please visit:
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
For further information, please visit:
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting flipped board. This way the data can be visualized.
PHP Fatal error: Uncaught Error: Class 'Chess\StringToBoard' not found in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Game.php:283
Stack trace:
#0 /home/standard/projects/chess-server/src/Socket.php(110): Chess\Game->loadFen()
#1 /home/standard/projects/chess-server/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php(75): ChessServer\Socket->onMessage()
#2 /home/standard/projects/chess-server/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php(131): Ratchet\WebSocket\WsServer->Ratchet\WebSocket\{closure}()
#3 /home/standard/projects/chess-server/vendor/ratchet/rfc6455/src/Messaging/MessageBuffer.php(248): Ratchet\WebSocket\WsServer->Ratchet\WebSocket\{closure}()
#4 /home/standard/projects/chess-server/vendor/ratchet/rfc6455/src/Messaging/MessageBuffer.php(194): Ratchet\RFC6455\Messaging\MessageBuffer->processData()
#5 /home/standard/projects/chess-server/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php(153): Ratchet\RFC6455\Messaging\MessageBuffer->onData()
#6 /home/standard/projec in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Game.php on line 283
Doubled pawns are usually considered a disadvantage that may determine the result of a chess game, especially in the endgame.
As Philidor once said:
"Pawns are the soul of chess."
Every doubled pawn structure should be counted as described in the examples below.
Thus, a new file named DoubledPawnEvaluation.php
should be implemented in a similar way as the following evaluation features:
With the new feature implemented, we'll be able to take more accurate normalized heuristic pictures; for further information please visit:
Happy learning and coding!
Probably the simplest way for this class to recognize en passant captures is to programmatically play on the board the double pawn push.
A passed pawn can definitely be a crucial advantage that determines the result of a chess game.
As Philidor once said:
"Pawns are the soul of chess."
This feature should be evaluated as it is described next.
Examples:
Thus, a new file named PassedPawnEvaluation.php
should be implemented in a similar way as the following evaluation features:
With the new feature implemented, we'll be able to take more accurate normalized heuristic pictures; for further information please visit:
Happy learning and coding!
FEN strings should be validated in a similar way as PGN syntax is being validated.
At the present moment, the create()
method in Chess\FEN\StringToBoard
can generate a chessboard image from white side only, however it should generate an image from black side as well.
A second argument needs to be added to the Chess\FEN\StringToBoard
class constructor to allow flipping the board as it is described next.
use Chess\FEN\StringToBoard;
use Chess\Image\BoardToPng;
$board = (new StringToBoard('1rbq1rk1/p1b1nppp/1p2p3/8/1B1pN3/P2B4/1P3PPP/2RQ1R1K w - - bm Nf6+'))
->create();
$flip = true;
(new BoardToPng($board, $flip))->output('01_kaufman.png');
Happy learning and coding.
The following test passes in tests/unit/HeuristicPictureTest.php
but it shouldn't after playing 1.e4 Nf6
:
<?php
namespace Chess\Tests\Unit;
use Chess\Board;
use Chess\HeuristicPicture;
use Chess\PGN\Convert;
use Chess\PGN\Symbol;
use Chess\Tests\AbstractUnitTestCase;
use Chess\Tests\Sample\Checkmate\Fool as FoolCheckmate;
use Chess\Tests\Sample\Checkmate\Scholar as ScholarCheckmate;
use Chess\Tests\Sample\Opening\Benoni\BenkoGambit;
class HeuristicPictureTest extends AbstractUnitTestCase
{
...
/**
* @test
*/
public function w_e4_b_Nf6_take_get_balance()
{
$board = new Board();
$board->play(Convert::toStdObj(Symbol::WHITE, 'e4'));
$board->play(Convert::toStdObj(Symbol::BLACK, 'Nf6'));
$balance = (new HeuristicPicture($board->getMovetext()))
->take()
->getBalance();
$expected = [
[ -1, 1, -1, 1, -1, 0, -1, -1 ],
];
$this->assertEquals($expected, $balance);
}
}
Chess
classes and methods should be documented in the PHP Chess Docs.
Chess\PGN\Movetext
should be documented.
Most probably the Chess\Evaluation\System
class can be simplified because only one system is being used actually.
A new method to allow proposing a takeback should be implemented in the Chess\Game
class.
It'd be nice if a png image could be generated from a FEN string or a chessboard object.
Probably the output generation could be taken from p-chess/chess @garak @akondas @peter279k @chrysanthos
Isolated pawns are a disadvantage that may determine the result of a chess game, especially in the endgame.
As Philidor once said:
"Pawns are the soul of chess."
Every isolated pawn should be counted as described in the examples below.
Figure 2. w = 1, b = 1
Thus, a new file named IsolatedPawnEvaluation.php
should be implemented in a similar way as the following evaluation features:
With the new feature implemented, we'll be able to take more accurate normalized heuristic pictures; for further information please visit:
Happy learning and coding!
The sample chess openings should be tested in Chess\Tests\Unit\AsciiTest
as well by printing the ascii representation of the resulting board. This way the data can be visualized; thus, the Symmetrical Defense to the Queen's Gambit should be displayed as it is described next.
This issue is aimed to practice software architecture and unit testing skills.
Sometimes a particular file name or namespace needs to be changed. This is the case of the Chess\Tests\Unit\Fen\AsciiTest
namespace, which should be updated to Chess\Tests\Unit\AsciiTest
in order to keep a one-to-one correspondence between the file path and its corresponding namespace.
Please replace Chess\Tests\Unit\Fen
with Chess\Tests\Unit
in the tests/unit/AsciiTest.php
file and make sure all tests pass after the update.
Happy learning and coding!
Keep it up.
This issue is intended to practise some unit testing skills.
A new chess opening needs to be added as the following example:
Specifically, the Classical Variation of the French Defense should be tested:
1.e4 e6 2.d4 d5 3.Nc3 Nf6
Happy learning and coding!
It'd be awesome if the sample chess openings could be tested in Chess\Tests\Unit\Image\BoardToPngTest
as well by creating an image of the resulting board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting flipped board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
Figure 1. Fianchetto Variation of the Benoni Defense
For further information, please visit:
DocBlocks as per phpDocumentor docs should be written for classes, traits, methods and so on.
The first position of the Kaufman test throws an error when selecting a black piece after a white piece is moved.
1rbq1rk1/p1b1nppp/1p2p3/8/1B1pN3/P2B4/1P3PPP/2RQ1R1K w - - bm Nf6+
$ php cli/ws-server.php
Welcome to PHP Chess Server
Commands available:
/accept {"id":"id"} Accepts a friend request to play a game.
/ascii Prints the ASCII representation of the game.
/castling Gets the castling status.
/captures Gets the pieces captured by both players.
/fen Prints the FEN string representation of the game.
/heuristicpicture Takes a balanced heuristic picture of the current game.
/history The current game's history.
/ischeck Finds out if the game is in check.
/ismate Finds out if the game is over.
/piece {"position":"string"} Gets a piece by its position on the board.
/pieces {"color":["w","b"]} Gets the pieces on the board by color.
/playfen {"fen":"string"} Plays a chess move in shortened FEN format.
/quit Quits a game.
/start {"mode":["analysis","fen","playfriend"],"fen":"string","color":["w","b"],"min":"int"} Starts a new game.
/status The current game status.
Listening to commands...
PHP Notice: Trying to get property 'move' of non-object in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php on line 606
PHP Notice: Trying to get property 'position' of non-object in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php on line 606
PHP Notice: Trying to get property 'next' of non-object in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php on line 606
PHP Fatal error: Uncaught TypeError: Argument 1 passed to Chess\Board::getPieceByPosition() must be of the type string, null given, called in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php on line 606 and defined in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php:361
Stack trace:
#0 /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php(606): Chess\Board->getPieceByPosition()
#1 /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php(818): Chess\Board->undoCastle()
#2 /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php(532): Chess\Board->leavesInCheck()
#3 /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php(562): Chess\Board->isLegalMove()
#4 /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/FEN/AbstractStringToPgn.php(91): Chess\Board->play()
#5 /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Game.php(321): C in /home/standard/projects/chess-server/vendor/programarivm/php-chess/src/Board.php on line 361
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting flipped board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
Figure 1. Fianchetto Variation of the Benoni Defense
For further information, please visit:
Also, add the symbol "#" if the king is checkmated.
The sample chess openings should be tested in Chess\Tests\Unit\AsciiTest
as well by printing the ascii representation of the resulting board. This way the data can be visualized; thus, the Classical Variation of the French Defense should be displayed as it is described next.
It'd be awesome if the sample chess openings could be tested in Chess\Tests\Unit\Fen\AsciiTest
as well by printing the ascii representation of the resulting board. This way the data can be visualized; thus, the Fianchetto Variation of the Benoni Defense should be displayed as it is described next.
The Chess\Game
class should implement a method returning the game's heuristic picture.
For further information, please visit:
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
Figure 1. Fianchetto Variation of the Benoni Defense
For further information, please visit:
This issue is intended to practise some unit testing skills.
A new chess opening needs to be added as the following example:
Specifically, the Exchange Variation of the French Defense should be tested:
1.e4 e6 2.d4 d5 3.exd5 exd5
Happy learning and coding!
There's a bug that prevents a knight from moving to a square when the two knights can occupy that same square, as it is shown in the example attached.
The passed pawn evaluation should be added to Chess\HeuristicPicture and tested accordingly in Chess\Tests\Unit\HeuristicPictureTest.
For further information please visit:
Keep it up, and happy coding and learning.
The isolated pawn evaluation should be added to Chess\HeuristicPicture and tested accordingly in Chess\Tests\Unit\HeuristicPictureTest.
For further information please visit:
Keep it up, and happy learning.
The sample chess openings should be tested in Chess\Tests\Unit\Image\BoardToPngTest
by creating an image of the resulting board. This way the data can be visualized; for example, the Fianchetto Variation of the Benoni Defense is displayed as it is described next.
For further information, please visit:
The knight on b1 can't be moved to c3.
1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 Nc6
This issue is intended to practice some unit testing skills.
A new chess opening needs to be added as the following examples:
Specifically, the Fianchetto Variation of the Benoni Defense should be tested:
1.d4 Nf6 2.c4 c5 3.d5 e6 4.Nc3 exd5 5.cxd5 d6 6.Nf3 g6 7.g3 Bg7 8.Bg2 0-0 9.0-0 Nbd7 10.Nd2 a6 11.a4 Re8
Happy learning and coding!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.