Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jabolcni committed Mar 29, 2024
1 parent 9b7b272 commit 2f3be6d
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 111 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,14 @@ In November 2023 version v0.3.1 was proposed for testing on CCRL Blitz list, whe

In February 2024 version v0.4.1 was proposed for testing on CCRL Blitz list, where it current stands at 2687 ± 20 ELO.

In March 2024 version v0.5.0 was tested on CCRL Blitz list, where it currently stands at 2916 ± 30 ELO.
In March 2024 version v0.5.0 was tested on CCRL Blitz list, where it currently stands at 2908 ± 20 ELO.

Latest version which is v0.5.1 has not been proposed for testing, but I estimate that it is around 2950 ± 20 ELO.

## Credits

- [Chess Programming Wiki](https://www.chessprogramming.org/)

- [BitBoard Chess Engine in C YouTube playlist](https://www.youtube.com/playlist?list=PLmN0neTso3Jxh8ZIylk74JpwfiWNI76Cs) by [@maksimKorzh](https://github.com/maksimKorzh) in which the authors explains the developement of [BBC](https://github.com/maksimKorzh/bbc) engine

- [Programming A Chess Engine in C](https://www.youtube.com/watch?v=bGAfaepBco4&list=PLZ1QII7yudbc-Ky058TEaOstZHVbT-2hg&index=2&ab_channel=BluefeverSoftware) by Bluefever Software in which the authors explains the developement of Vice engine
Expand All @@ -94,10 +97,8 @@ In March 2024 version v0.5.0 was tested on CCRL Blitz list, where it currently s

- [Koala Chess Engine](https://github.com/Wuelle/Kaola/tree/main) by [Wuelle](https://github.com/Wuelle). The UCI protocol implementation and FEN string parsing are directly derived from the Koala chess engine and slightly updated.

- [Chess Programming Wiki](https://www.chessprogramming.org/)

- [Avalanche Chess Engine](https://github.com/SnowballSH/Avalanche/tree/master) by [SnowballSH](https://github.com/SnowballSH). Usefull examples hot to programm chess engine in Zig langugae.

## License

Lambergar is licensed under the MIT License. Check out LICENSE.md for the full text. Feel free to use this program, but please credit this repository in your project if you use it.
Lambergar is licensed under the MIT License. Check out LICENSE for the full text. Feel free to use this program, but please credit this repository in your project if you use it.
105 changes: 48 additions & 57 deletions src/evaluation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,74 @@ const eg_tempo = 0;

// pawns, knights, bishops, rooks, queens, kings

const material_mg = [6]i32{ 132, 503, 544, 854, 1486, 0 };
const material_eg = [6]i32{ 107, 254, 268, 483, 895, 0 };
const material_mg = [6]i32{ 53, 248, 257, 326, 732, 0 };
const material_eg = [6]i32{ 103, 324, 332, 585, 971, 0 };

const mg_pawn_table = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, -27, -2, -7, 14, 21, 53, 69, 11, -45, -38, -14, -13, 4, -13, 23, -13, -49, -43, -13, 4, 2, 4, -18, -44, -29, -26, -26, -8, 0, 0, -11, -22, -44, -58, 7, 15, 48, 102, 36, 21, 60, -4, 12, 19, 36, 16, -17, -45, 0, 0, 0, 0, 0, 0, 0, 0 };
const eg_pawn_table = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, -19, -22, -13, -17, -20, -28, -43, -47, -27, -27, -29, -24, -27, -29, -46, -45, -19, -15, -31, -37, -33, -41, -35, -38, -9, -19, -20, -37, -32, -37, -31, -31, 4, -1, -8, -38, -26, -50, -26, -32, 107, 119, 106, 90, 77, 88, 112, 108, 0, 0, 0, 0, 0, 0, 0, 0 };
const mg_pawn_table = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, -23, -27, -23, -11, -15, 15, 26, 0, -29, -33, -22, -21, -14, -8, 4, -8, -22, -25, -12, -9, -5, 3, 4, -4, -16, -20, -14, -5, 3, 12, 7, 0, -18, -18, -2, 5, 29, 60, 40, 15, 67, 71, 64, 73, 57, 38, -23, 4, 0, 0, 0, 0, 0, 0, 0, 0 };
const eg_pawn_table = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, -6, -3, 2, 0, 8, 1, -13, -20, -10, -8, -7, -5, -1, -6, -18, -21, -6, -4, -12, -9, -10, -12, -16, -18, 3, -1, -4, -15, -11, -15, -8, -9, 9, 8, 5, 2, 5, -6, 8, -1, 96, 87, 82, 66, 65, 75, 97, 95, 0, 0, 0, 0, 0, 0, 0, 0 };

const mg_knight_table = [64]i32{ 4, 55, 24, 53, 56, 55, 48, -12, 46, 28, 60, 90, 86, 71, 63, 63, 35, 56, 86, 77, 94, 87, 92, 44, 61, 58, 84, 85, 97, 111, 84, 48, 71, 90, 73, 131, 103, 118, 83, 104, 9, 44, 77, 128, 140, 216, 106, 50, -63, -6, 111, 46, 138, 126, 44, 20, -308, -32, -24, -8, 93, -137, -142, -160 };
const eg_knight_table = [64]i32{ -42, -16, -5, 7, -12, -4, -23, -23, -30, -16, -19, -17, -15, -10, -17, -30, -17, -6, -12, 10, 7, -9, -24, -27, -11, 0, 13, 18, 16, -3, -17, 1, -13, -3, 18, 16, 10, 6, -7, -22, -19, -11, 15, 3, -18, -22, -26, -19, -1, -3, -29, -7, -38, -42, -20, -32, 46, -35, -10, -9, -31, 1, -5, -50 };
const mg_knight_table = [64]i32{ -58, -34, -47, -30, -23, -22, -37, -76, -39, -34, -27, -16, -16, -15, -25, -26, -35, -23, -13, -9, -4, -9, -14, -26, -17, -13, -1, -3, -5, 2, 2, -19, -11, -8, 2, 16, 8, 18, -5, 6, -33, -4, 10, 11, 39, 60, 8, 9, -40, -46, -10, -2, -5, 39, -44, -40, -129, -103, -67, -23, 0, -101, -17, -54 };
const eg_knight_table = [64]i32{ -58, -27, -9, -3, -6, -12, -18, -22, -45, -9, -10, -1, 0, -12, -4, -17, -20, -3, 1, 14, 13, 1, -4, -12, -5, 5, 19, 24, 29, 17, 6, 9, -2, 9, 22, 30, 26, 24, 19, 0, -5, 5, 19, 21, 9, 14, 8, -18, -8, 8, 7, 17, 13, -12, 3, -8, -9, 11, 17, 4, 3, 23, -7, -73 };

const mg_bishop_table = [64]i32{ 71, 53, 66, 58, 48, 40, 77, 62, 45, 89, 67, 67, 77, 89, 110, 61, 73, 78, 73, 64, 71, 81, 54, 67, 34, 40, 58, 72, 81, 48, 56, 15, -2, 34, 43, 69, 54, 23, 53, 36, 17, 33, 83, 39, 110, 103, 100, 79, -15, 14, -11, 16, 4, 94, 3, 68, -15, 5, -19, -48, -96, -34, 66, -53 };
const eg_bishop_table = [64]i32{ -33, -15, -15, -8, -3, 0, -34, -22, -13, -31, -21, -12, -12, -17, -25, -30, -27, -11, -7, 0, 2, -8, -15, -20, -13, -5, 0, 0, -1, 3, -15, -11, 11, 5, 4, 5, 4, 3, -12, -11, 5, 0, -9, 8, -12, -1, -11, -15, 0, 3, 3, -10, 1, -24, 2, -35, 0, -18, -6, 5, 6, 2, -21, 9 };
const mg_bishop_table = [64]i32{ -13, -3, -22, -25, -23, -26, -18, -18, -7, -13, -8, -18, -12, -7, 1, -6, -23, -12, -12, -12, -15, -7, -13, -9, -29, -20, -11, -10, -4, -18, -14, -20, -25, -18, -11, 10, -13, 7, -20, -14, -25, -16, -11, -9, 10, 17, 23, 0, -41, -37, -32, -38, -41, -21, -83, -42, -41, -59, -83, -88, -67, -91, -29, -54 };
const eg_bishop_table = [64]i32{ -9, -10, -4, -1, -2, 3, -8, -3, -15, -11, -7, 0, 0, -7, -10, -25, -4, 4, 4, 4, 12, 1, -1, -4, 0, 7, 12, 14, 8, 10, 2, -5, -3, 13, 7, 10, 16, 4, 14, -2, 2, 8, 8, 9, 3, 14, 1, -4, 4, 10, 9, 10, 8, 7, 19, -7, 10, 21, 18, 17, 10, 14, 5, 3 };

const mg_rook_table = [64]i32{ 19, 33, 53, 62, 73, 54, 8, 36, -7, 7, 13, 35, 47, 38, 65, -29, -9, 5, 12, 39, 37, 43, 66, 34, -16, -24, -13, 7, 7, 7, 49, 9, -12, 18, 29, 49, 29, 57, 80, 73, 16, 33, 17, 62, 69, 113, 141, 122, 8, -5, 32, 111, 36, 128, 136, 81, 15, 42, 43, 36, 70, 137, 99, 6 };
const eg_rook_table = [64]i32{ 9, 3, -1, -2, -12, -3, 7, -21, 6, 4, 9, 2, -5, -2, -9, 6, 5, 7, 4, -2, 0, -9, -17, -9, 14, 13, 16, 13, 12, 5, -10, -3, 14, 5, 9, 0, 2, -2, -11, -11, 12, 8, 9, -1, -5, -14, -16, -20, 14, 26, 16, -6, 5, -10, -11, -7, 23, 14, 14, 12, 4, -15, -6, 14 };
const mg_rook_table = [64]i32{ -25, -13, -10, -5, -5, -11, 3, -21, -35, -27, -16, -13, -15, -10, -6, -44, -31, -29, -28, -25, -23, -24, 1, -23, -30, -32, -28, -24, -25, -33, -2, -21, -23, -17, -15, -4, -15, -11, 12, 0, -15, 0, -2, 5, 27, 37, 50, 11, -11, -13, 0, 13, 3, 16, 15, 35, -3, 0, -17, -18, -24, -12, 20, 33 };
const eg_rook_table = [64]i32{ -3, -6, -1, -3, -7, -6, -17, -19, -12, -6, -4, -6, -8, -16, -22, -21, -3, 4, 6, 6, 3, 0, -13, -10, 10, 16, 17, 14, 11, 14, 4, 0, 16, 17, 17, 10, 13, 11, 6, 2, 17, 12, 14, 9, -1, 0, -4, 1, 19, 22, 21, 16, 14, 10, 11, -1, 17, 18, 25, 24, 23, 24, 16, 10 };

const mg_queen_table = [64]i32{ 173, 182, 183, 192, 193, 168, 118, 169, 155, 162, 169, 187, 192, 204, 193, 176, 136, 163, 149, 158, 156, 167, 163, 145, 137, 122, 138, 130, 145, 151, 154, 142, 97, 132, 120, 117, 124, 138, 137, 169, 112, 111, 145, 141, 185, 224, 277, 223, 98, 69, 73, 41, 69, 290, 159, 358, 77, 111, 155, 185, 204, 258, 82, 136 };
const eg_queen_table = [64]i32{ -27, -38, -26, -34, -28, -22, -1, -39, 0, 1, -9, -21, -20, -46, -45, -14, -14, -35, 27, 3, 23, 24, 38, 17, 0, 39, 26, 58, 46, 35, 36, 29, 12, 25, 34, 66, 80, 79, 57, 24, 1, 21, 34, 40, 69, 24, -19, -10, 30, 42, 61, 112, 86, 24, 62, -98, 33, 26, 18, 22, 6, -6, 41, 37 };
const mg_queen_table = [64]i32{ -7, -1, 1, 2, 7, -8, -8, -9, -5, -8, -1, 2, 6, 16, 22, 7, -8, -8, -8, -7, -2, 2, 9, 8, -9, -14, -8, -17, -11, -8, 5, -1, -8, -15, -15, -15, -17, -7, -3, 2, -8, -14, -13, -14, 4, 51, 30, 33, -32, -45, -34, -33, -37, 14, -18, 38, -4, -1, -2, -2, 15, 63, 87, 93 };
const eg_queen_table = [64]i32{ -30, -36, -34, -24, -45, -58, -73, -43, -30, -18, -19, -25, -30, -64, -93, -61, -22, -4, 4, -3, -2, -1, -15, -31, -12, 10, 13, 36, 30, 29, 13, 19, -12, 18, 24, 41, 64, 65, 60, 31, -10, 10, 27, 41, 65, 39, 54, 16, 17, 38, 57, 64, 79, 45, 59, 23, 7, 21, 37, 41, 37, 9, 4, 1 };

const mg_king_table = [64]i32{ -84, 38, 5, -98, -9, -48, 47, 27, 45, -38, -48, -108, -85, -62, 14, 14, 8, 31, -79, -106, -110, -65, -25, -52, 59, 38, 8, -87, -48, -76, -36, -87, 7, 20, 36, 2, -17, -12, 14, -34, 75, 177, 35, 70, 27, 93, 93, -12, 51, 129, 108, 97, 75, 131, 15, -26, 93, 82, 130, 84, 127, 97, 73, 56 };
const eg_king_table = [64]i32{ -27, -31, -12, 5, -14, 0, -36, -60, -36, 1, 17, 35, 32, 29, 5, -17, -31, -7, 25, 40, 44, 35, 18, 5, -44, -6, 16, 38, 37, 40, 22, 11, -24, 0, 15, 24, 27, 34, 25, 15, -25, -11, 10, 6, 18, 21, 23, 15, -29, -9, -9, -7, 0, 6, 23, 13, -62, -27, -33, -20, -24, -9, -9, -36 };
const mg_king_table = [64]i32{ -4, 36, 11, -53, -13, -50, 17, 19, 16, 3, -18, -41, -39, -28, 3, 12, 11, -7, -34, -22, -32, -36, -15, -22, 27, -8, -17, -32, -23, -34, -49, -62, -14, -37, -32, -24, -56, -36, -59, -68, -33, -44, 13, -41, -20, -4, -98, -105, -54, -5, 73, 63, 19, -12, -75, -93, 351, 162, 211, 147, 150, 199, 118, 313 };
const eg_king_table = [64]i32{ -30, -22, -15, -11, -32, -8, -28, -55, -18, -10, 1, 4, 6, 3, -8, -24, -15, 1, 15, 15, 17, 14, 0, -4, -10, 15, 23, 32, 29, 25, 19, 9, 11, 41, 43, 46, 50, 44, 48, 20, 27, 54, 34, 49, 42, 49, 69, 39, 16, 26, 9, 0, 19, 33, 53, 30, -195, -79, -67, -60, -65, -58, -31, -156 };

const mg_passed_score = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -9, -1, -26, -7, 18, 81, -8, 4, 3, -1, -41, 1, 24, 34, 42, 30, 0, -15, -14, -22, -54, -87, 4, 33, 39, 33, 15, 8, 29, -2, -41, 79, 78, 2, -24, -37, -46, -71, -107, 60, -4, 12, 19, 36, 16, -17, -45, 0, 0, 0, 0, 0, 0, 0, 0 };
const eg_passed_score = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, 7, 27, 5, -7, 14, 7, 11, 19, 18, 25, 11, 17, 13, 18, 31, 12, 38, 40, 35, 35, 32, 46, 66, 42, 72, 82, 58, 62, 50, 56, 80, 76, 147, 151, 141, 145, 116, 147, 152, 173, 107, 119, 106, 90, 77, 88, 112, 108, 0, 0, 0, 0, 0, 0, 0, 0 };
const mg_passed_score = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -6, -11, -13, 3, -10, 4, 12, 5, -9, -14, -23, -3, -22, -17, 21, 10, 0, -13, -3, -15, -34, -49, 0, 30, 26, 17, 10, 5, -3, -16, -4, 77, 62, 49, 31, 0, 2, -25, -9, 67, 71, 64, 73, 57, 38, -23, 4, 0, 0, 0, 0, 0, 0, 0, 0 };
const eg_passed_score = [64]i32{ 0, 0, 0, 0, 0, 0, 0, 0, 12, 22, 14, 18, 12, 13, 25, 11, 16, 28, 17, 18, 17, 24, 40, 11, 43, 50, 39, 30, 36, 48, 71, 43, 73, 73, 59, 56, 54, 66, 77, 63, 126, 121, 105, 95, 87, 104, 106, 120, 96, 87, 82, 66, 65, 75, 97, 95, 0, 0, 0, 0, 0, 0, 0, 0 };

const mg_isolated_pawn_score = [8]i32{ -12, -14, -15, -24, -24, -20, -11, -12 };
const eg_isolated_pawn_score = [8]i32{ 0, -5, -5, -4, -1, -2, -7, 0 };
const mg_isolated_pawn_score = [8]i32{ -6, -1, -7, -10, -9, -7, -1, -6 };
const eg_isolated_pawn_score = [8]i32{ -5, -9, -9, -9, -9, -9, -9, -5 };

const mg_blocked_passer_score = [8]i32{ 0, -49, 0, 3, -9, 19, 45, 0 };
const eg_blocked_passer_score = [8]i32{ 0, 6, -17, -41, -59, -129, -165, 0 };
const mg_blocked_passer_score = [8]i32{ 0, -7, 0, 4, 5, 11, -3, 0 };
const eg_blocked_passer_score = [8]i32{ 0, -6, -13, -29, -50, -90, -84, 0 };

const mg_supported_pawn = [8]i32{ 0, 0, 22, 22, 28, 61, 495, 0 };
const eg_supported_pawn = [8]i32{ 0, 0, 14, 9, 17, 27, -97, 0 };
const mg_supported_pawn = [8]i32{ 0, 0, 13, 8, 12, 36, 222, 0 };
const eg_supported_pawn = [8]i32{ 0, 0, 10, 6, 10, 23, -22, 0 };

const mg_pawn_phalanx = [8]i32{ 0, 8, 21, 31, 62, 255, 122, 0 };
const eg_pawn_phalanx = [8]i32{ 0, -3, 4, 12, 42, 48, 384, 0 };
const mg_pawn_phalanx = [8]i32{ 0, 3, 12, 15, 40, 216, -289, 0 };
const eg_pawn_phalanx = [8]i32{ 0, 2, 6, 22, 63, 39, 328, 0 };

const mg_knigh_mobility = [9]i32{ 28, 72, 87, 97, 107, 113, 119, 121, 127 };
const eg_knigh_mobility = [9]i32{ -71, -38, -11, -3, -1, 7, 5, 5, -11 };
const mg_knigh_mobility = [9]i32{ -44, -28, -22, -18, -15, -13, -11, -8, -4 };
const eg_knigh_mobility = [9]i32{ -50, -23, -5, 2, 10, 18, 19, 16, 9 };

const mg_bishop_mobility = [14]i32{ 39, 57, 71, 82, 90, 95, 100, 107, 110, 122, 127, 152, 94, 205 };
const eg_bishop_mobility = [14]i32{ -51, -32, -21, -11, -2, 5, 12, 10, 18, 9, 13, 0, 32, -11 };
const mg_bishop_mobility = [14]i32{ -35, -29, -23, -19, -15, -13, -11, -10, -7, -6, 0, 7, 2, 48 };
const eg_bishop_mobility = [14]i32{ -46, -25, -14, -4, 5, 14, 20, 23, 27, 26, 25, 21, 34, 8 };

const mg_rook_mobility = [15]i32{ 5, 25, 30, 40, 41, 57, 67, 78, 86, 97, 105, 118, 128, 115, 180 };
const eg_rook_mobility = [15]i32{ -19, -14, -12, -12, -1, -2, -1, 1, 5, 7, 10, 13, 17, 23, 1 };
const mg_rook_mobility = [15]i32{ -33, -27, -22, -18, -18, -13, -11, -8, -5, -3, -1, 0, 5, 10, 21 };
const eg_rook_mobility = [15]i32{ -25, -20, -20, -16, -8, -4, 1, 5, 11, 17, 22, 27, 26, 25, 16 };

const mg_queen_mobility = [28]i32{ 253, 260, 267, 267, 275, 277, 280, 283, 289, 295, 297, 299, 304, 310, 315, 318, 304, 312, 323, 336, 338, 345, 351, 456, 351, 278, 214, 187 };
const eg_queen_mobility = [28]i32{ -35, -106, -83, -61, -61, -35, -25, -5, -1, 11, 15, 25, 23, 27, 28, 30, 54, 48, 50, 47, 46, 47, 32, -24, 31, 61, 89, 88 };
const mg_queen_mobility = [28]i32{ -16, -14, -11, -10, -7, -5, -4, -3, 0, 0, 1, 2, 3, 4, 6, 7, 11, 15, 20, 30, 44, 89, 77, 170, 132, 304, 594, 1448 };
const eg_queen_mobility = [28]i32{ -106, -46, -36, -26, -24, -17, -10, -2, 1, 7, 12, 17, 20, 23, 27, 32, 29, 27, 27, 20, 9, -18, -14, -59, -46, -133, -273, -683 };

const mg_pawn_attacking = [6]i32{ 0, 43, 65, 53, 31, 0 };
const eg_pawn_attacking = [6]i32{ 0, -17, 18, -56, -34, 0 };
const mg_pawn_attacking = [6]i32{ 0, 36, 41, 25, 23, 0 };
const eg_pawn_attacking = [6]i32{ 0, 18, 43, 10, 34, 0 };

const mg_knight_attacking = [6]i32{ -14, 0, 15, 69, -3, 0 };
const eg_knight_attacking = [6]i32{ 9, 0, 31, -17, -11, 0 };
const mg_knight_attacking = [6]i32{ -7, 0, 23, 32, 14, 0 };
const eg_knight_attacking = [6]i32{ 7, 0, 25, -13, -5, 0 };

const mg_bishop_attacking = [6]i32{ -3, 19, 0, 31, 32, 0 };
const eg_bishop_attacking = [6]i32{ 10, 12, 0, -24, -1, 0 };
const mg_bishop_attacking = [6]i32{ -1, 12, 0, 22, 26, 0 };
const eg_bishop_attacking = [6]i32{ 8, 27, 0, -4, 51, 0 };

const mg_rook_attacking = [6]i32{ -17, 7, 20, 0, 62, 0 };
const eg_rook_attacking = [6]i32{ 16, 13, 8, 0, -63, 0 };
const mg_rook_attacking = [6]i32{ -3, 4, 11, 0, 34, 0 };
const eg_rook_attacking = [6]i32{ 8, 18, 14, 0, 24, 0 };

const mg_queen_attacking = [6]i32{ 3, 0, -2, 5, 0, 0 };
const eg_queen_attacking = [6]i32{ 0, 0, 28, -21, 0, 0 };
const mg_queen_attacking = [6]i32{ 0, 1, 0, -4, 0, 0 };
const eg_queen_attacking = [6]i32{ 0, -3, 8, 3, 0, 0 };

const mg_doubled_pawns = [1]i32{-4};
const eg_doubled_pawns = [1]i32{-9};
const mg_doubled_pawns = [1]i32{-2};
const eg_doubled_pawns = [1]i32{-13};

const mg_bishop_pair = [1]i32{48};
const eg_bishop_pair = [1]i32{44};
const mg_bishop_pair = [1]i32{12};
const eg_bishop_pair = [1]i32{46};

const mg_pesto_table = [6][64]i32{
mg_pawn_table,
Expand Down Expand Up @@ -391,7 +391,7 @@ pub const Evaluation = struct {

pub fn eval(self: *Evaluation, pos: *Position, comptime perspective_color: Color) i32 {

var phase_bounded = @min(self.phase[Color.White.toU4()]+self.phase[Color.Black.toU4()], 64);
var phase_bounded: i32 = @intCast(@min(self.phase[Color.White.toU4()]+self.phase[Color.Black.toU4()], 64));
const perspective = if (perspective_color == Color.White) @as(i32, 1) else @as(i32, -1);

var eval_mg = self.eval_mg;
Expand All @@ -402,7 +402,7 @@ pub const Evaluation = struct {
eval_eg += pieces_score[1]; // TUNER OFF

var e: i32 = @divTrunc((eval_mg * phase_bounded + eval_eg * (64-phase_bounded)), 64);
const tempo = @divTrunc((mg_tempo * phase_bounded + eg_tempo * (64-phase_bounded)), 64);
const tempo: i32 = @divTrunc((mg_tempo * phase_bounded + eg_tempo * (64-phase_bounded)), 64);

if (self.phase[Color.White.toU4()] > 3 and self.phase[Color.Black.toU4()] == 0 and pos.piece_count(Piece.BLACK_PAWN) == 0) {

Expand Down Expand Up @@ -959,8 +959,6 @@ fn eval_pieces(self: *Evaluation, pos: *Position) [2]i32 { // TUNER OFF
pc_bb = black_rook;
while (pc_bb != 0) {
var sq = bb.pop_lsb(&pc_bb);
// var file = position.file_of_u6(sq);
// var mask_file = bb.MASK_FILE[file];
var att = attacks.get_rook_attacks(sq, occ);
var mobility = att & ~black_pieces;
black_att |= mobility;
Expand Down Expand Up @@ -1287,13 +1285,6 @@ pub inline fn get_passed_pawn_score(sq: u6) [2]i32 {
return score;
}

// pub inline fn get_passed_pawn_score_f(file: u6) [2]i32 {
// var score = [_]i32{ 0, 0 };
// score[0] = mg_passed_score[file];
// score[1] = eg_passed_score[file];
// return score;
// }

pub inline fn get_isolated_pawn_score(file: u6) [2]i32 {
var score = [_]i32{ 0, 0 };
score[0] += mg_isolated_pawn_score[file];
Expand Down
7 changes: 2 additions & 5 deletions src/history.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ const PieceType = position.PieceType;
const Position = position.Position;

pub const max_histroy = 400;
const histry_multiplier = 32;
//const history_divider = 512;
const history_divider = 1200;
const history_divider = 16384;

pub inline fn histoy_bonus(_entry: i32, bonus: i32) i32 {
return _entry + histry_multiplier * bonus - @as(i32, @intCast(@divTrunc(@abs(_entry * bonus), history_divider)));
//return _entry + histry_multiplier * bonus - _entry * @as(i32, @intCast(@divTrunc(@abs(bonus), history_divider)));
return _entry + bonus - @as(i32, @intCast(@divTrunc(@abs(_entry * bonus), history_divider)));
}

pub fn update_all_history(search: *Search, move: Move, quet_moves: std.ArrayList(Move), quet_mv_pieces: std.ArrayList(Piece), depth: i8, comptime color: Color) void {
Expand Down
12 changes: 7 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@ pub fn main() !void {
var pos = Position.new();
try pos.set(start_position);
var thinker = Search.new();
thinker.clear_for_new_game();
var main_search_thread: std.Thread = undefined;

// var tuner_instance = tuner.Tuner.new(); // TUNER ON
// tuner_instance.init(); // TUNER ON
// try tuner_instance.convertDataset(); // TUNER ON
// var tuner_instance = tuner.Tuner.new(); // TUNER ON
// tuner_instance.init(); // TUNER ON
// try tuner_instance.convertDataset(); // TUNER ON

mainloop: while (true) {
//std.time.sleep(20 * 1000 * 1000);
const command = try uci.next_command(allocator);
try switch (command) {
GuiCommand.uci => {
try send_command(EngineCommand{ .id = .{ .key = "name", .value = "Lambergar v0.5.0" } }, allocator);
try send_command(EngineCommand{ .id = .{ .key = "name", .value = "Lambergar v0.5.1" } }, allocator);
try send_command(EngineCommand{ .id = .{ .key = "author", .value = "Janez Podobnik" } }, allocator);
try send_command(EngineCommand{ .option = .{ .name = "Hash", .option_type = "spin", .default = "128", .min = "1", .max = "4096" } }, allocator);
//try send_command(EngineCommand{ .option = .{ .name = "Threads", .option_type = "spin", .default = "1", .min = "1", .max = "1" } }, allocator);
Expand All @@ -68,7 +69,8 @@ pub fn main() !void {
GuiCommand.isready => send_command(EngineCommand.readyok, allocator),
GuiCommand.debug => {},
GuiCommand.newgame => {
thinker = Search.new();
//thinker = Search.new();
thinker.clear_for_new_game();
tt.TT.clear();
try pos.set(start_position);
},
Expand Down

0 comments on commit 2f3be6d

Please sign in to comment.