Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/optimization #553

Merged
merged 82 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
843dcd6
Refactored Chess\Variant\Classical\PGN\AN\Square to a non-static class
programarivm Jun 8, 2024
1170a80
Updated Chess\Piece\B
programarivm Jun 8, 2024
91e12a8
Updated Chess\Piece\N
programarivm Jun 8, 2024
549cff5
Updated Chess\Piece\Q
programarivm Jun 8, 2024
4475335
Updated Chess\Piece\K
programarivm Jun 8, 2024
b5b1596
Updated Chess\Piece\A
programarivm Jun 8, 2024
f1f7f3e
Updated Chess\Piece\C
programarivm Jun 8, 2024
5d8ad6a
Updated Chess\Piece\P
programarivm Jun 8, 2024
6c0df9a
Updated Chess\Piece\PieceArray
programarivm Jun 8, 2024
7406fed
Updated Chess\Variant\Classical\FEN\StrToBoard
programarivm Jun 8, 2024
87c7489
Updated Chess\Variant\Classical\Board
programarivm Jun 8, 2024
4b1037f
Refactored Chess\Variant\Classical\FEN\Field
programarivm Jun 8, 2024
ad33b54
Updated the pawn evaluations
programarivm Jun 8, 2024
efa46cb
Updated Chess\Variant\Capablanca\FEN\Str
programarivm Jun 8, 2024
ee69249
Updated Chess\Variant\Chess960\Board
programarivm Jun 8, 2024
c5d1cb2
Updated Chess\Eval\BadBishopEval
programarivm Jun 8, 2024
84f727f
Updated tests
programarivm Jun 8, 2024
4062262
Updated Chess\Randomizer\Randomizer
programarivm Jun 8, 2024
0c7a37c
Updated tests
programarivm Jun 8, 2024
dd8e5d0
Updated tests
programarivm Jun 8, 2024
da17d37
Updated Chess\Variant\Classical\Board
programarivm Jun 8, 2024
427e646
Updated Chess\Variant\CapablancaFischer\Board
programarivm Jun 8, 2024
20131f7
Cleanup
programarivm Jun 8, 2024
c25cef6
Refactored Chess\Variant\Classical\PGN\AN\Square
programarivm Jun 9, 2024
73413f9
Deleted ValidationInterface
programarivm Jun 9, 2024
366e144
Refactored Chess\Variant\Classical\PGN\AN\Color
programarivm Jun 9, 2024
9d963a0
Refactored PiecePlacement
programarivm Jun 9, 2024
4ece3df
Refactored Chess\Piece\R
programarivm Jun 9, 2024
8544011
Refactored classes in the Chess\Piece namespace
programarivm Jun 10, 2024
2ecea1e
Array micro-optimization
programarivm Jun 10, 2024
ef4139c
Array micro-optimization
programarivm Jun 10, 2024
fef9491
Refactored classes in the Chess\Piece namespace
programarivm Jun 10, 2024
9b5ade6
Refactored the current player's turn
programarivm Jun 11, 2024
ecc0d0f
Refactored the captured pieces
programarivm Jun 11, 2024
e1ad344
Refactored the history
programarivm Jun 11, 2024
6477e3f
Made the board's color public
programarivm Jun 11, 2024
d6c9321
Made the board's castling rule public
programarivm Jun 11, 2024
03a53f0
Made the board's castling ability public
programarivm Jun 11, 2024
ffc1c84
Made the board's starting FEN public
programarivm Jun 11, 2024
87d3528
Made the board's starting FEN public
programarivm Jun 11, 2024
c3320bf
Made the board's square public
programarivm Jun 11, 2024
55aa26e
Made the board's move public
programarivm Jun 11, 2024
1350f0f
Made the board's space evaluation public
programarivm Jun 11, 2024
bc252a0
Made the board's square evaluation public
programarivm Jun 11, 2024
ce02b7f
Deleted getSqCount()
programarivm Jun 11, 2024
efa2f6d
Implemented the clone() method
programarivm Jun 11, 2024
597e29e
Fixed the clone() method
programarivm Jun 11, 2024
a09d562
Fixed Chess\Play\RavPlay
programarivm Jun 11, 2024
f31b763
Custom object serialization
programarivm Jun 11, 2024
eeb8e3e
Updated tests
programarivm Jun 11, 2024
59604e7
Updated Chess\Eval\CheckmateInOneEval
programarivm Jun 12, 2024
2a7fadd
Updated Chess\Eval\CheckmateInPlyEval
programarivm Jun 12, 2024
d168c80
Made the piece's color public
programarivm Jun 12, 2024
679d83f
Made the piece's sq public
programarivm Jun 12, 2024
71a86cf
Made the piece's id public
programarivm Jun 12, 2024
4ca610a
Made the piece's mobility public
programarivm Jun 12, 2024
7eabf2b
Made the piece's move public
programarivm Jun 12, 2024
f6369ed
Renamed getSqFile() as file()
programarivm Jun 12, 2024
ff6913d
Renamed getSqRank() as rank()
programarivm Jun 12, 2024
4adaa31
Deleted PieceObserverBoardTrait
programarivm Jun 12, 2024
087fe71
PSR12 coding style
programarivm Jun 12, 2024
fe78cad
Implemented the time complexity evaluation interfaces
programarivm Jun 12, 2024
27358c1
Renamed StandardFunction as QuadraticFunction
programarivm Jun 12, 2024
5a2480e
Added Chess\Function\LinearFunction
programarivm Jun 12, 2024
a208459
Implemented Chess\Function\AbstractFunction
programarivm Jun 12, 2024
33acd97
Renamed functions
programarivm Jun 12, 2024
55b1138
Added Chess\Function\ConstantComplexityFunction
programarivm Jun 12, 2024
89d2dd5
Deleted weights
programarivm Jun 12, 2024
aa43959
Deleted ConstantComplexityEvalInterface
programarivm Jun 12, 2024
aa355fb
Updated Chess\Function
programarivm Jun 12, 2024
06d5f99
Refactored Chess\Heuristics\FenHeuristics
programarivm Jun 12, 2024
b9a3a1e
Refactored Chess\Heuristics\SanHeuristics
programarivm Jun 12, 2024
3b7e761
Refactored Chess\Heuristics\FenHeuristics
programarivm Jun 12, 2024
e0dd7af
Updated tests
programarivm Jun 12, 2024
14f6388
Fixed Chess\Tutor\FenExplanation
programarivm Jun 12, 2024
2960d35
Deleted checkmate evaluations
programarivm Jun 12, 2024
1ff93eb
Deleted Chess\Heuristics\SanHeuristics
programarivm Jun 12, 2024
b581f57
Updated tests
programarivm Jun 12, 2024
f78a1f7
Deleted interfaces
programarivm Jun 12, 2024
bbc8bd1
PSR12 coding style
programarivm Jun 12, 2024
e07122a
Deleted functions
programarivm Jun 12, 2024
3c96cf0
Restructured folders
programarivm Jun 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactored Chess\Heuristics\FenHeuristics
  • Loading branch information
programarivm committed Jun 12, 2024
commit 06d5f999c81e0e8849f57be4968e34a80951c2d5
1 change: 0 additions & 1 deletion src/Function/LinearComplexityFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class LinearComplexityFunction extends AbstractFunction
PressureEval::class,
KingSafetyEval::class,
ProtectionEval::class,
AttackEval::class,
DiscoveredCheckEval::class,
DoubledPawnEval::class,
PassedPawnEval::class,
Expand Down
11 changes: 6 additions & 5 deletions src/Heuristics/FenHeuristics.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Chess\Heuristics;

use Chess\Eval\InverseEvalInterface;
use Chess\Function\QuadraticComplexityFunction;
use Chess\Function\AbstractFunction;
use Chess\Variant\Classical\Board;
use Chess\Variant\Classical\PGN\AN\Color;

Expand All @@ -28,9 +28,9 @@ class FenHeuristics
/**
* The evaluation function.
*
* @var \Chess\Function\QuadraticComplexityFunction
* @var \Chess\Function\AbstractFunction
*/
protected QuadraticComplexityFunction $function;
protected AbstractFunction $function;

/**
* The result.
Expand All @@ -50,12 +50,13 @@ class FenHeuristics
* Constructor.
*
* @param \Chess\Variant\Classical\Board $board
* @param \Chess\Variant\Classical\AbstractFunction $function
*/
public function __construct(Board $board)
public function __construct(Board $board, AbstractFunction $function)
{
$this->board = $board;

$this->function = new QuadraticComplexityFunction();
$this->function = $function;

$this->calc()->balance();
}
Expand Down
33 changes: 24 additions & 9 deletions tests/unit/Heuristics/FenHeuristicsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Chess\FenToBoardFactory;
use Chess\Heuristics\FenHeuristics;
use Chess\Function\QuadraticComplexityFunction;
use Chess\Tests\AbstractUnitTestCase;
use Chess\Variant\Capablanca\Board as CapablancaBoard;

Expand All @@ -18,7 +19,9 @@ public function get_balance_start()

$board = FenToBoardFactory::create($fen);

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ];

Expand All @@ -34,7 +37,9 @@ public function get_balance_e4()

$board = FenToBoardFactory::create($fen);

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 0.0, 12.0, -4.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

Expand All @@ -50,7 +55,9 @@ public function get_balance_e4_e5()

$board = FenToBoardFactory::create($fen);

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

Expand All @@ -66,7 +73,9 @@ public function get_balance_e4_e5_Nf3_Nf6()

$board = FenToBoardFactory::create($fen);

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

Expand All @@ -82,9 +91,11 @@ public function get_balance_A59()

$board = FenToBoardFactory::create($fen);

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$expected = [ 1.0, 9.0, -1.0, 4.0, -3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, -5.1, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0 ];
$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 1.0, 9.0, -1.0, 4.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, -5.1, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

$this->assertEquals($expected, $balance);
}
Expand All @@ -98,9 +109,11 @@ public function get_balance_scholar_checkmate()

$board = FenToBoardFactory::create($fen);

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 1.0, 5.66, -12.0, 2.0, 3.0, 4.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0 ];
$expected = [ 1.0, 5.66, -12.0, 2.0, 3.0, 4.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

$this->assertEquals($expected, $balance);
}
Expand All @@ -114,7 +127,9 @@ public function capablanca_f4()

$board = FenToBoardFactory::create($fen, new CapablancaBoard());

$balance = (new FenHeuristics($board))->getBalance();
$function = new QuadraticComplexityFunction();

$balance = (new FenHeuristics($board, $function))->getBalance();

$expected = [ 0.0, 12.0, -3.0, 9.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ];

Expand Down