Skip to content

Commit

Permalink
-16 bytes (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
cj5716 authored Oct 29, 2023
1 parent 7909bac commit 48d76f2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bash build-mini.sh

## 4ku-mini Size
```
3,946 bytes
3,930 bytes
```

---
Expand Down
50 changes: 30 additions & 20 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,25 +356,35 @@ void generate_piece_moves(Move *const movelist,
const i32 phases[] = {0, 1, 1, 2, 4, 0};
const i32 max_material[] = {139, 449, 452, 841, 1674, 0, 0};
const i32 material[] = {S(100, 139), S(329, 449), S(341, 452), S(455, 841), S(825, 1674), 0};
const i32 pst_rank[][8] = {
{0, S(-2, 0), S(-3, -1), S(-1, -1), S(1, 0), S(5, 2), 0, 0},
{S(-4, -5), S(-2, -3), S(-1, -1), S(1, 3), S(3, 4), S(7, 1), S(5, 0), S(-11, 1)},
{S(-2, -2), S(1, -2), S(1, 0), S(1, 0), S(2, 1), S(4, 0), S(1, 0), S(-8, 2)},
{S(-2, -4), S(-2, -4), S(-3, -2), S(-4, 1), S(-1, 2), S(3, 2), S(3, 3), S(6, 1)},
{S(1, -13), S(1, -10), S(0, -5), S(-1, 1), S(-1, 6), S(1, 5), S(-2, 9), S(1, 7)},
{S(0, -6), S(0, -2), S(-2, 0), S(-4, 3), S(-1, 4), S(5, 4), S(3, 3), S(4, -4)},
const i32 pst_rank[] = {
0, S(-2, 0), S(-3, -1), S(-1, -1), S(1, 0), S(5, 2), 0, 0, // Pawn
S(-4, -5), S(-2, -3), S(-1, -1), S(1, 3), S(3, 4), S(7, 1), S(5, 0), S(-11, 1), // Knight
S(-2, -2), S(1, -2), S(1, 0), S(1, 0), S(2, 1), S(4, 0), S(1, 0), S(-8, 2), // Bishop
S(-2, -4), S(-2, -4), S(-3, -2), S(-4, 1), S(-1, 2), S(3, 2), S(3, 3), S(6, 1), // Rook
S(1, -13), S(1, -10), S(0, -5), S(-1, 1), S(-1, 6), S(1, 5), S(-2, 9), S(1, 7), // Queen
S(0, -6), S(0, -2), S(-2, 0), S(-4, 3), S(-1, 4), S(5, 4), S(3, 3), S(4, -4) // King
};
const i32 pst_file[][8] = {
{S(-2, 1), S(-1, 1), S(-1, 0), S(0, -1), S(1, 0), S(2, 0), S(2, 0), S(-1, -1)},
{S(-4, -3), S(-2, -1), S(0, 1), S(2, 3), S(2, 2), S(2, 0), S(1, -1), S(-1, -3)},
{S(-2, 0), 0, S(1, 0), S(0, 1), S(0, 1), S(-1, 1), S(2, -1), S(0, -1)},
{S(-2, 0), S(-2, 1), S(-1, 1), S(1, 0), S(1, -1), S(1, 0), S(2, 0), S(-1, -1)},
{S(-3, -4), S(-2, -2), S(-1, 0), S(0, 1), S(0, 2), S(1, 3), S(2, 1), S(3, -1)},
{S(-2, -5), S(2, -1), S(-2, 1), S(-3, 2), S(-4, 2), S(-1, 1), S(2, -1), S(0, -5)},
const i32 pst_file[] = {
S(-2, 1), S(-1, 1), S(-1, 0), S(0, -1), S(1, 0), S(2, 0), S(2, 0), S(-1, -1), // Pawn
S(-4, -3), S(-2, -1), S(0, 1), S(2, 3), S(2, 2), S(2, 0), S(1, -1), S(-1, -3), // Knight
S(-2, 0), 0, S(1, 0), S(0, 1), S(0, 1), S(-1, 1), S(2, -1), S(0, -1), // Bishop
S(-2, 0), S(-2, 1), S(-1, 1), S(1, 0), S(1, -1), S(1, 0), S(2, 0), S(-1, -1), // Rook
S(-3, -4), S(-2, -2), S(-1, 0), S(0, 1), S(0, 2), S(1, 3), S(2, 1), S(3, -1), // Queen
S(-2, -5), S(2, -1), S(-2, 1), S(-3, 2), S(-4, 2), S(-1, 1), S(2, -1), S(0, -5) // King
};
const i32 open_files[][5] = {
{S(3, 4), S(-4, 20), S(20, 16), S(3, 19), S(-23, 10)},
{S(-3, -12), S(-11, 0), S(47, 0), S(-13, 35), S(-63, 1)},
const i32 open_files[] = {
// Semi open files
S(3, 4),
S(-4, 20),
S(20, 16),
S(3, 19),
S(-23, 10),
// Open files
S(-3, -12),
S(-11, 0),
S(47, 0),
S(-13, 35),
S(-63, 1),
};
const i32 mobilities[] = {S(9, 5), S(8, 7), S(4, 4), S(4, 3), S(-5, -1)};
const i32 pawn_protection[] = {S(24, 14), S(2, 16), S(8, 17), S(9, 8), S(-5, 23), S(-34, 26)};
Expand Down Expand Up @@ -425,8 +435,8 @@ const i32 pawn_attacked_penalty[] = {S(64, 14), S(155, 142)};
const i32 file = sq % 8;

// Split quantized PSTs
score += pst_rank[p][rank] * 8;
score += pst_file[p][file] * 8;
score += pst_rank[p * 8 + rank] * 8;
score += pst_file[p * 8 + file] * 8;

// Pawn protection
const u64 piece_bb = 1ULL << sq;
Expand Down Expand Up @@ -480,7 +490,7 @@ const i32 pawn_attacked_penalty[] = {S(64, 14), S(155, 142)};
// Open or semi-open files
const u64 file_bb = 0x101010101010101ULL << file;
if (!(file_bb & pawns[0]))
score += open_files[!(file_bb & pawns[1])][p - 1];
score += open_files[!(file_bb & pawns[1]) * 5 + p - 1];

if (p == King && piece_bb & 0xC3D7) {
// C3D7 = Reasonable king squares
Expand Down

0 comments on commit 48d76f2

Please sign in to comment.