Giter Site home page Giter Site logo

chesslablab / php-chess Goto Github PK

View Code? Open in Web Editor NEW
81.0 4.0 45.0 72.62 MB

Object-oriented library that allows to create chess apps out-of-the-box.

Home Page: https://php-chess.docs.chesslablab.org/

License: MIT License

PHP 100.00%
chess pgn board game php fen machinelearning

php-chess's Introduction

PHP Chess

License: MIT Contributors Downloads Latest Stable Version GitHub Workflow Status

A chess library for PHP.

Documentation

Read the latest docs here.

License

The PHP Chess library is open-sourced software licensed under the MIT license.

Contributions

We encourage you to contribute to PHP Chess! Please follow the Contributing Guidelines.

Made with contrib.rocks.

php-chess's People

Contributors

11slartibartfast avatar bofalke avatar d47081 avatar dependabot[bot] avatar elijahcruz12 avatar jeffersonsimaogoncalves avatar maikuolan avatar marcingladkowski avatar nicolafan avatar peter279k avatar programarivm avatar rafael-neris avatar rc-lee avatar roadsigns avatar simonur avatar skuhnow avatar tathagat27 avatar victoria-dr avatar vikeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-chess's Issues

Fix PGN disambiguation

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.

disambiguation

This would need some fine-tuning: 1.Ng1f3 Ng8f6 2.d3 d6 3.Nf3d2

Promotion

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.

PGN to board?

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.

Implement the backward pawn evaluation

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.

figure-01
Figure 1. w = 2, b = 1


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!

Fix fatal error because of class not found

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

Implement the doubled pawn evaluation

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.

figure-01
Figure 1. w = 0, b = 1

figure-02
Figure 2. w = 1, b = 0


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!

Implement the passed pawn evaluation

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.

  • Every passed pawn has a value corresponding to the threat represented by its rank.

Examples:

figure-01
Figure 1. w = 0, b = 4

figure-02
Figure 2. w = 0, b = 5 + 6

figure-03
Figure 3. w = 2, b = 0


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!

Allow to flip the chessboard when creating an image

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.

Fix the balance when taking a heuristic picture

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);
    }
}

Implement the isolated pawn evaluation

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-01
Figure 1. w = 2, b = 1

figure-02

Figure 2. w = 1, b = 1

figure-03
Figure 3. w = 0, b = 2


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!

Update a namespace

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.

Pieces can't be selected after loading a FEN string

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+

position-01

$ 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.