Jump to content

Help with library php-chess


Recommended Posts

Hey everyone,

I'm trying to use a library called php-chess, which can be found here: https://github.com/programarivm/php-chess/

As described in the readme-File, I installed (at my local computer under /opt/lampp/htdocs/chess) it via composer with 

composer require programarivm/php-chess

Imho the installation was successful, since some composer files were created and also the directory '/opt/lampp/htdocs/chess/vendor/programarivm/php-chess', where all the files from the library are stored.

After creating the file 'index.php' (stored under /opt/lampp/htdocs/chess) I wrote the following lines:

<?php
require __DIR__ . '/vendor/autoload.php';
use Chess\Game;
$game = new Game();
$isLegalMove = $game->play('w', 'e4');
?>

I'm new to this topic, but I think I did the right thing to load the library with the require-statement in the 1st line. The other lines are copied from the readme-file from the project, because I just wanted to test it. But when loading http://localhost/chess/index.php I get an error: 

Fatal error: Uncaught Error: Class 'Chess\Game' not found in /opt/lampp/htdocs/chess/index.php:4 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/chess/index.php on line 4

I don't understand what I did wrong here. I loaded the library and the other lines are copied from the author of the project, and I assume he didn't make a mistake. Where is my mistake? How can I use that library?

Thanks for your help!

Link to comment
Share on other sites

(background information: by default, Composer assumes you want all the things you install to have a "minimum stability" of "stable", meaning the packages themselves are marked as being stable releases - as opposed to alpha releases, or beta releases, or "dev" releases)

To see what's going on, follow these steps:

1. Take a look at your composer.lock file to see exactly which version of programarivm/php-chess was installed. You should see it as version 1.1.3.
2. Look at the repo's latest releases. You'll see that the latest version is 1.1.51.
3. For bonus points, try browsing the repo at version 1.1.3. Look at the instructions and compare with what you have done. Close but not quite the same, eh?
4. Rather than give up and go with an old version from last August, try telling composer to install version 1.1.51 instead:

$ composer require "programarivm/php-chess 1.1.51"

5. Composer will complain about depending on rubix/ml being "dev-master" and how that conflicts with your "minimum-stability".

The conclusion here is that since your minimum-stability is (the default of) "stable", and recent php-chess versions require a thing that is not stable, Composer won't install those.

But you do want those.

6. Tell Composer that "dev" stability is fine. That might feel wrong but unfortunately this is actually a very normal thing to do because lots of developers out there don't do Good Things with their versions.

$ composer config minimum-stability dev

7. Now have Composer update php-chess to the latest version.

$ composer update programarivm/php-chess

8. Watch the update output to see what version it installs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.