Skip to content

Commit

Permalink
Removed MODE_ANALYSIS
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed May 22, 2023
1 parent 3d1b774 commit f0d6e69
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
24 changes: 14 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Variants:

Modes:

- `Chess\Game:MODE_ANALYSIS`
- `Chess\Game:MODE_GM`
- `Chess\Game:MODE_FEN`
- `Chess\Game:MODE_PGN`
Expand All @@ -22,32 +21,34 @@ Let's look at the methods available in the `Chess\Game` class through some examp

#### `public function play(string $color, string $pgn): bool`

The following code snippet starts a classical game in analysis mode and makes the first move in PGN format.
The following code snippet starts a classical game in FEN mode and makes the first move in PGN format.

```php
use Chess\Game;

$game = new Game(
Game::VARIANT_CLASSICAL,
Game::MODE_ANALYSIS
Game::MODE_FEN
);

$game->play('w', 'Nc3');
$game->loadFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -')
->play('w', 'Nc3');
```

#### `public function playLan(string $color, string $lan): bool`

This one also starts a classical game in analysis mode making the first move in long algebraic notation instead.
This one also starts a classical game in FEN mode making the first move in long algebraic notation instead.

```php
use Chess\Game;

$game = new Game(
Game::VARIANT_CLASSICAL,
Game::MODE_ANALYSIS
Game::MODE_FEN
);

$game->playLan('w', 'b1c3');
$game->loadFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -')
->playLan('w', 'b1c3');
```

#### `public function loadFen(string $fen): void`
Expand All @@ -62,8 +63,8 @@ $game = new Game(
Game::MODE_FEN
);

$game->loadFen('rn1qkb1r/4pp1p/3p1np1/2pP4/4P3/2N3P1/PP3P1P/R1BQ1KNR b kq - 0 9');
$game->play('b', 'Bg7');
$game->loadFen('rn1qkb1r/4pp1p/3p1np1/2pP4/4P3/2N3P1/PP3P1P/R1BQ1KNR b kq - 0 9')
->play('b', 'Bg7');
```

#### `public function loadPgn(string $movetext): void`
Expand Down Expand Up @@ -188,9 +189,12 @@ use Chess\Game;

$game = new Game(
Game::VARIANT_CLASSICAL,
Game::MODE_ANALYSIS
Game::MODE_FEN
);

$game->loadFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -')
->play('w', 'Nc3');

$state = $game->state();
```

Expand Down
11 changes: 8 additions & 3 deletions src/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Game
const VARIANT_CAPABLANCA_100 = 'capablanca100';
const VARIANT_CLASSICAL = 'classical';

const MODE_ANALYSIS = 'analysis';
const MODE_GM = 'gm';
const MODE_FEN = 'fen';
const MODE_PGN = 'pgn';
Expand Down Expand Up @@ -228,20 +227,26 @@ public function ai(array $options = [], array $params = []): ?object
* Loads a FEN string allowing to continue a chess game.
*
* @param string $fen
* @return \Chess\Game
*/
public function loadFen(string $fen): void
public function loadFen(string $fen): Game
{
$this->board = (new StrToBoard($fen))->create();

return $this;
}

/**
* Loads a PGN movetext allowing to continue a chess game.
*
* @param string $movetext
* @return \Chess\Game
*/
public function loadPgn(string $movetext): void
public function loadPgn(string $movetext): Game
{
$this->board = (new PgnPlayer($movetext))->play()->getBoard();

return $this;
}

/**
Expand Down
21 changes: 9 additions & 12 deletions tests/unit/GameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,12 @@ public function play_games()
if ($fileInfo->isDot()) continue;
$filename = $fileInfo->getFilename();
$text = file_get_contents(self::DATA_FOLDER."/pgn/$filename");
$text = (new Movetext($move, $text))->validate();
$movetext = (new Movetext($move, $text))->getMovetext();
$game = new Game(
Game::VARIANT_CLASSICAL,
Game::MODE_ANALYSIS
);
foreach ($movetext->moves as $key => $val) {
if ($key % 2 === 0) {
$this->assertTrue($game->play('w', $val));
} else {
$this->assertTrue($game->play('b', $val));
$movetext = new Movetext($move, $text);
if ($movetext->validate()) {
$game = new Game(Game::VARIANT_CLASSICAL, Game::MODE_FEN);
$game->loadFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -');
foreach ($movetext->getMovetext()->moves as $key => $val) {
$this->assertTrue($game->play($game->getBoard()->getTurn(), $val));
}
}
}
Expand All @@ -124,9 +119,11 @@ public function classical_play_uci_B00()
{
$game = new Game(
Game::VARIANT_CLASSICAL,
Game::MODE_ANALYSIS
Game::MODE_FEN
);

$game->loadFen('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -');

$this->assertTrue($game->playLan('w', 'e2e4'));
$this->assertTrue($game->playLan('b', 'b8c6'));
$this->assertTrue($game->playLan('w', 'g1f3'));
Expand Down

0 comments on commit f0d6e69

Please sign in to comment.