Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ad26d22281 | |||
| 352b4e57d7 | |||
|
|
cdd8b45da8 | ||
|
|
6006442f90 | ||
|
|
eebdfdbee2 | ||
|
|
a6aba8801e | ||
|
|
8d1300d7e2 | ||
|
|
d0e6ce81ce | ||
|
|
f3dea86ded | ||
|
|
092ed19104 | ||
|
|
f8894bbdff | ||
|
|
258a8a0da9 | ||
|
|
dca6eac3ba | ||
|
|
5ee797e1f8 | ||
|
|
eaf3bfa192 | ||
|
|
9c73ca6838 | ||
|
|
0f50f31b13 | ||
|
|
b6f0b6ee5e | ||
| 4ae9eea7e2 | |||
| 1f368551c1 | |||
|
|
4e9f222ddc | ||
|
|
061795a039 | ||
|
|
1af497f063 | ||
|
|
b6cdf5b778 | ||
|
|
4eb4bc1348 | ||
|
|
c2fe2e968a | ||
|
|
21f2890b92 | ||
|
|
5d748b07d2 | ||
|
|
b252f16b2d | ||
|
|
18f4060df0 | ||
|
|
033440fbac | ||
|
|
bfb2a6db23 |
6
.github/workflows/dispatcher.yml
vendored
6
.github/workflows/dispatcher.yml
vendored
@@ -26,13 +26,13 @@ jobs:
|
|||||||
SERVER=false
|
SERVER=false
|
||||||
UI=false
|
UI=false
|
||||||
|
|
||||||
if [[ "$BRANCH" == *"Engine"* ]]; then
|
if [[ "$BRANCH" == *"Engine"* ]] ; then
|
||||||
ENGINE=true
|
ENGINE=true
|
||||||
fi
|
fi
|
||||||
if [[ "$BRANCH" == *"Server"* ]]; then
|
if [[ "$BRANCH" == *"Server"* ]] ; then
|
||||||
SERVER=true
|
SERVER=true
|
||||||
fi
|
fi
|
||||||
if [[ "$BRANCH" == *"UI"* ]]; then
|
if [[ "$BRANCH" == *"UI"* ]] ; then
|
||||||
UI=true
|
UI=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
1
.github/workflows/engine_test.yml
vendored
1
.github/workflows/engine_test.yml
vendored
@@ -1,7 +1,6 @@
|
|||||||
name: Engine Tests
|
name: Engine Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
|||||||
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@@ -1,7 +1,6 @@
|
|||||||
name: Release build
|
name: Release build
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
|||||||
1
.github/workflows/server_test.yml
vendored
1
.github/workflows/server_test.yml
vendored
@@ -1,7 +1,6 @@
|
|||||||
name: Server Tests
|
name: Server Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
|||||||
3
.github/workflows/test.sh
vendored
3
.github/workflows/test.sh
vendored
@@ -30,6 +30,9 @@ echo "$PROJECT_NAME" > "$LOG_FILE"
|
|||||||
awk '/^running [0-9]+ test[s]?$/,/^$/' full_test_output.log >> "$LOG_FILE"
|
awk '/^running [0-9]+ test[s]?$/,/^$/' full_test_output.log >> "$LOG_FILE"
|
||||||
|
|
||||||
# --- APPEND TO GLOBAL LOG (in repo root) ---
|
# --- APPEND TO GLOBAL LOG (in repo root) ---
|
||||||
|
if [[ $(git rev-parse --abbrev-ref HEAD) == "master" ]]; then
|
||||||
|
echo "master" >> $FINAL_LOG
|
||||||
|
fi
|
||||||
cat "$LOG_FILE" >> "$FINAL_LOG"
|
cat "$LOG_FILE" >> "$FINAL_LOG"
|
||||||
|
|
||||||
# --- SUMMARY ---
|
# --- SUMMARY ---
|
||||||
|
|||||||
1
.github/workflows/ui_test.yml
vendored
1
.github/workflows/ui_test.yml
vendored
@@ -1,7 +1,6 @@
|
|||||||
name: UI Tests
|
name: UI Tests
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
|
||||||
|
|||||||
64
.github/workflows/upload_data.yml
vendored
64
.github/workflows/upload_data.yml
vendored
@@ -20,33 +20,71 @@ jobs:
|
|||||||
echo "$GOOGLE_SERVICE_ACCOUNT_JSON" > service_account.json
|
echo "$GOOGLE_SERVICE_ACCOUNT_JSON" > service_account.json
|
||||||
|
|
||||||
python <<'PYCODE'
|
python <<'PYCODE'
|
||||||
import gspread, json, time, subprocess
|
import gspread, json, subprocess
|
||||||
|
|
||||||
# credentials
|
|
||||||
creds = json.load(open("service_account.json"))
|
creds = json.load(open("service_account.json"))
|
||||||
gc = gspread.service_account_from_dict(creds)
|
gc = gspread.service_account_from_dict(creds)
|
||||||
sh = gc.open_by_key("${{ secrets.SPREADSHEET_ID }}")
|
sh = gc.open_by_key("${{ secrets.SPREADSHEET_ID }}")
|
||||||
v = subprocess.run(['git','rev-parse','--show-toplevel'], capture_output=True).stdout.decode().strip()
|
v = subprocess.run(['git','rev-parse','--show-toplevel'], capture_output=True).stdout.decode().strip()
|
||||||
print(f"{v}/test_data.log")
|
print(f"{v}/test_data.log")
|
||||||
|
|
||||||
|
|
||||||
|
def writeRowsToSpreadsheet(data_list, worksheet):
|
||||||
|
existing_rows = len(worksheet.get_all_values())
|
||||||
|
start_row = existing_rows + 3
|
||||||
|
rows_to_append = [row.split() for row in data_list]
|
||||||
|
print(f"{rows_to_append}")
|
||||||
|
|
||||||
|
for i, row in enumerate(rows_to_append):
|
||||||
|
worksheet.insert_row(row, start_row + i)
|
||||||
|
|
||||||
|
|
||||||
with open(f"{v}/test_data.log", "r") as f:
|
with open(f"{v}/test_data.log", "r") as f:
|
||||||
lines = [line.strip() for line in f if line.strip()]
|
lines = [line.strip() for line in f if line.strip()]
|
||||||
|
|
||||||
|
isMaster = False
|
||||||
project = lines[0].lower()
|
project = lines[0].lower()
|
||||||
worksheet = sh.worksheet(project)
|
if project == "master":
|
||||||
|
isMaster = True
|
||||||
|
|
||||||
|
engine_data = []
|
||||||
|
server_data = []
|
||||||
|
ui_data = []
|
||||||
|
master_data = []
|
||||||
|
|
||||||
# project name
|
for entry in lines:
|
||||||
data = lines[1:]
|
if not isMaster and entry == "engine":
|
||||||
|
project = "engine"
|
||||||
|
elif not isMaster and entry == "server":
|
||||||
|
project = "server"
|
||||||
|
elif not isMaster and entry == "ui":
|
||||||
|
project = "ui"
|
||||||
|
|
||||||
#blank rows
|
if project == "engine" and entry != "engine":
|
||||||
existing_rows = len(worksheet.get_all_values())
|
engine_data.append(entry)
|
||||||
start_row = existing_rows + 3
|
elif project == "server" and entry != "server":
|
||||||
|
server_data.append(entry)
|
||||||
|
elif project == "ui" and entry != "ui":
|
||||||
|
ui_data.append(entry)
|
||||||
|
elif project == "master" and entry != "master":
|
||||||
|
master_data.append(entry)
|
||||||
|
|
||||||
# Split data into columns (by spaces)
|
print("PRINTING FILTERED DATA\n\n")
|
||||||
rows_to_append = [row.split() for row in data]
|
print(f"engine\n{engine_data}")
|
||||||
|
print(f"server\n{server_data}")
|
||||||
|
print(f"ui\n{ui_data}")
|
||||||
|
print("\n\n\n")
|
||||||
|
|
||||||
for i, row in enumerate(rows_to_append):
|
if isMaster and len(master_data) != 0:
|
||||||
worksheet.insert_row(row, start_row + i)
|
worksheet = sh.worksheet("master")
|
||||||
|
writeRowsToSpreadsheet(master_data, worksheet)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
if len(engine_data) != 0:
|
||||||
|
writeRowsToSpreadsheet(engine_data, sh.worksheet("engine"))
|
||||||
|
if len(server_data) != 0:
|
||||||
|
writeRowsToSpreadsheet(server_data, sh.worksheet("server"))
|
||||||
|
if len(ui_data) != 0:
|
||||||
|
writeRowsToSpreadsheet(ui_data, sh.worksheet("ui"))
|
||||||
|
|
||||||
print(f"Uploaded {len(rows_to_append)} rows to '{project}' tab.")
|
|
||||||
PYCODE
|
PYCODE
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
once_cell = "1.19"
|
||||||
2
engine/src/bitboard.rs
Normal file
2
engine/src/bitboard.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mod attackmaps;
|
||||||
|
mod utils;
|
||||||
252
engine/src/bitboard/attackmaps.rs
Normal file
252
engine/src/bitboard/attackmaps.rs
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
|
const A_FILE: u64 = 0x0101_0101_0101_0101;
|
||||||
|
const H_FILE: u64 = 0x8080_8080_8080_8080;
|
||||||
|
const AB_FILE: u64 = 0x0303_0303_0303_0303;
|
||||||
|
const GH_FILE: u64 = 0xC0C0_C0C0_C0C0_C0C0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
EXPLANATIONS:
|
||||||
|
> square_index: 8 * rank number + file number (a-h = 0-7)
|
||||||
|
> side: white = 0, black = 1
|
||||||
|
> direction_index: 0..8 = [E, NE, N, NW, W, SW, S, SE]
|
||||||
|
*/
|
||||||
|
|
||||||
|
// KING_ATTACK_MAP[<square_index>]
|
||||||
|
pub static KING_ATTACK_MAP: Lazy<[u64; 64]> = Lazy::new(|| {
|
||||||
|
let mut table: [u64; 64] = [0u64; 64];
|
||||||
|
|
||||||
|
for sq in 0..64 {
|
||||||
|
let king: u64 = 1 << sq;
|
||||||
|
|
||||||
|
let left_attacks: u64 = king << 7 | king >> 1 | king >> 9;
|
||||||
|
let right_attacks: u64 = king << 1 | king << 9 | king >> 7;
|
||||||
|
|
||||||
|
table[sq] = (left_attacks & !H_FILE) | (right_attacks & !A_FILE) | king << 8 | king >> 8;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
});
|
||||||
|
|
||||||
|
// PAWN_ATTACK_MAP[<square_index>][<side>]
|
||||||
|
pub static PAWN_ATTACK_MAP: Lazy<[[u64; 2]; 64]> = Lazy::new(|| {
|
||||||
|
let mut table: [[u64; 2]; 64] = [[0u64; 2]; 64];
|
||||||
|
|
||||||
|
for sq in 0..64 {
|
||||||
|
let pawn: u64 = 1 << sq;
|
||||||
|
table[sq][0] |= (pawn << 9) & !A_FILE;
|
||||||
|
table[sq][0] |= (pawn << 7) & !H_FILE;
|
||||||
|
}
|
||||||
|
for sq in 0..64 {
|
||||||
|
let pawn: u64 = 1 << sq;
|
||||||
|
table[sq][1] |= (pawn >> 9) & !H_FILE;
|
||||||
|
table[sq][1] |= (pawn >> 7) & !A_FILE;
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
});
|
||||||
|
|
||||||
|
// KNIGHT_ATTACK_MAP[<square_index>]
|
||||||
|
pub static KNIGHT_ATTACK_MAP: Lazy<[u64; 64]> = Lazy::new(|| {
|
||||||
|
let mut table: [u64; 64] = [0u64; 64];
|
||||||
|
|
||||||
|
for sq in 0..64 {
|
||||||
|
let knight: u64 = 1 << sq;
|
||||||
|
|
||||||
|
let far_left_attacks: u64 = knight << 6 | knight >> 10;
|
||||||
|
let near_left_attacks: u64 = knight << 15 | knight >> 17;
|
||||||
|
let far_right_attacks: u64 = knight << 10 | knight >> 6;
|
||||||
|
let near_right_attacks: u64 = knight << 17 | knight >> 15;
|
||||||
|
|
||||||
|
table[sq] = (far_left_attacks & !GH_FILE) | (far_right_attacks & !AB_FILE) | (near_left_attacks & !H_FILE) | (near_right_attacks & !A_FILE);
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
});
|
||||||
|
|
||||||
|
// RAY_TABLE[<square_index>][<direction_index>]
|
||||||
|
pub static RAY_TABLE: Lazy<[[u64; 8]; 64]> = Lazy::new(|| {
|
||||||
|
let mut table: [[u64; 8]; 64] = [[0u64; 8]; 64];
|
||||||
|
let dirs: [i8; 8] = [1, 9, 8, 7, -1, -9, -8, -7];
|
||||||
|
for sq in 0..64 {
|
||||||
|
for d in 0..8 {
|
||||||
|
let mut ray: u64 = 0u64;
|
||||||
|
let origin: u64 = 1 << sq;
|
||||||
|
let mut new_target: u64 = if dirs[d] > 0 {origin << dirs[d]} else {origin >> -dirs[d]};
|
||||||
|
if [0, 1, 7].contains(&d) {
|
||||||
|
new_target &= !A_FILE;
|
||||||
|
}
|
||||||
|
else if [3, 4, 5].contains(&d) {
|
||||||
|
new_target &= !H_FILE;
|
||||||
|
}
|
||||||
|
while new_target != 0 {
|
||||||
|
ray |= new_target;
|
||||||
|
|
||||||
|
new_target = if dirs[d] > 0 {new_target << dirs[d]} else {new_target >> -dirs[d]};
|
||||||
|
if [0, 1, 7].contains(&d) {
|
||||||
|
new_target &= !A_FILE;
|
||||||
|
}
|
||||||
|
else if [3, 4, 5].contains(&d) {
|
||||||
|
new_target &= !H_FILE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
table[sq][d] = ray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return table;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// <----- TESTS ----->
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_king_attack_map() {
|
||||||
|
|
||||||
|
// test setup for corners [SW, SE, NW, NE]
|
||||||
|
let corner_indexes: [usize; 4] = [0, 7, 56, 63];
|
||||||
|
let corner_attack_maps: [u64; 4] = [
|
||||||
|
(1u64 << 1) | (1u64 << 8) | (1u64 << 9),
|
||||||
|
(1u64 << 6) | (1u64 << 14) | (1u64 << 15),
|
||||||
|
(1u64 << 48) | (1u64 << 49) | (1u64 << 57),
|
||||||
|
(1u64 << 54) | (1u64 << 55) | (1u64 << 62)
|
||||||
|
];
|
||||||
|
|
||||||
|
// tests for corners
|
||||||
|
for index in 0..4 {
|
||||||
|
assert_eq!(KING_ATTACK_MAP[corner_indexes[index]], corner_attack_maps[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for sides [S, E, W, N]
|
||||||
|
let side_indexes: [usize; 4] = [3, 31, 32, 60];
|
||||||
|
let side_attack_maps: [u64; 4] = [
|
||||||
|
(1 << 2) | (1 << 4) | (1 << 10) | (1 << 11) | (1 << 12),
|
||||||
|
(1 << 22) | (1 << 23) | (1 << 30) | (1 << 38) | (1 << 39),
|
||||||
|
(1 << 24) | (1 << 25) | (1 << 33) | (1 << 40) | (1 << 41),
|
||||||
|
(1 << 51) | (1 << 52) | (1 << 53) | (1 << 59) | (1 << 61)
|
||||||
|
];
|
||||||
|
|
||||||
|
// tests for sides
|
||||||
|
for index in 0..4 {
|
||||||
|
assert_eq!(KING_ATTACK_MAP[side_indexes[index]], side_attack_maps[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for center
|
||||||
|
let center_index: usize = 27;
|
||||||
|
let center_attack_map: u64 = (1 << 18) | (1 << 19) | (1 << 20) | (1 << 26) | (1 << 28) | (1 << 34) | (1 << 35) | (1 << 36);
|
||||||
|
|
||||||
|
// test for center
|
||||||
|
assert_eq!(KING_ATTACK_MAP[center_index], center_attack_map);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_pawn_attack_map() {
|
||||||
|
|
||||||
|
// test setup for white sides
|
||||||
|
let white_side_indexes: [usize; 2] = [24, 31];
|
||||||
|
let white_side_attack_maps: [u64; 2] = [
|
||||||
|
(1 << 33),
|
||||||
|
(1 << 38)
|
||||||
|
];
|
||||||
|
// tests for white sides
|
||||||
|
for index in 0..2 {
|
||||||
|
assert_eq!(PAWN_ATTACK_MAP[white_side_indexes[index]][0], white_side_attack_maps[index])
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for black sides
|
||||||
|
let black_side_indexes: [usize; 2] = [32, 39];
|
||||||
|
let black_side_attack_maps: [u64; 2] = [
|
||||||
|
(1 << 25),
|
||||||
|
(1 << 30)
|
||||||
|
];
|
||||||
|
// tests for black sides
|
||||||
|
for index in 0..2 {
|
||||||
|
assert_eq!(PAWN_ATTACK_MAP[black_side_indexes[index]][1], black_side_attack_maps[index])
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for white center
|
||||||
|
let white_center_indexes: [usize; 2] = [11, 12];
|
||||||
|
let white_center_attack_maps: [u64; 2] = [
|
||||||
|
(1 << 18) | (1 << 20),
|
||||||
|
(1 << 19) | (1 << 21)
|
||||||
|
];
|
||||||
|
// tests for white center
|
||||||
|
for index in 0..2 {
|
||||||
|
assert_eq!(PAWN_ATTACK_MAP[white_center_indexes[index]][0], white_center_attack_maps[index])
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for black center
|
||||||
|
let black_center_indexes: [usize; 2] = [51, 52];
|
||||||
|
let black_center_attack_maps: [u64; 2] = [
|
||||||
|
(1 << 42) | (1 << 44),
|
||||||
|
(1 << 43) | (1 << 45)
|
||||||
|
];
|
||||||
|
// tests for black center
|
||||||
|
for index in 0..2 {
|
||||||
|
assert_eq!(PAWN_ATTACK_MAP[black_center_indexes[index]][1], black_center_attack_maps[index])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_knight_attack_map() {
|
||||||
|
// test setup for corners [SW, SE, NW, NE]
|
||||||
|
let corner_indexes: [usize; 4] = [0, 7, 56, 63];
|
||||||
|
let corner_attack_maps: [u64; 4] = [
|
||||||
|
(1 << 17) | (1 << 10),
|
||||||
|
(1 << 13) | (1 << 22),
|
||||||
|
(1 << 41) | (1 << 50),
|
||||||
|
(1 << 46) | (1 << 53)
|
||||||
|
];
|
||||||
|
|
||||||
|
// tests for corners
|
||||||
|
for index in 0..4 {
|
||||||
|
assert_eq!(KNIGHT_ATTACK_MAP[corner_indexes[index]], corner_attack_maps[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for sides [S, E, W, N]
|
||||||
|
let side_indexes: [usize; 4] = [3, 31, 32, 60];
|
||||||
|
let side_attack_maps: [u64; 4] = [
|
||||||
|
(1 << 9) | (1 << 13) | (1 << 18) | (1 << 20),
|
||||||
|
(1 << 14) | (1 << 21) | (1 << 37) | (1 << 46),
|
||||||
|
(1 << 17) | (1 << 26) | (1 << 42) | (1 << 49),
|
||||||
|
(1 << 43) | (1 << 45) | (1 << 50) | (1 << 54)
|
||||||
|
];
|
||||||
|
|
||||||
|
// tests for sides
|
||||||
|
for index in 0..4 {
|
||||||
|
assert_eq!(KNIGHT_ATTACK_MAP[side_indexes[index]], side_attack_maps[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test setup for center
|
||||||
|
let center_index: usize = 27;
|
||||||
|
let center_attack_map: u64 = (1 << 10) | (1 << 12) | (1 << 17) | (1 << 21) | (1 << 33) | (1 << 37) | (1 << 42) | (1 << 44);
|
||||||
|
|
||||||
|
// test for center
|
||||||
|
assert_eq!(KNIGHT_ATTACK_MAP[center_index], center_attack_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ray_table() {
|
||||||
|
|
||||||
|
// test setup for all directions from center
|
||||||
|
let starting_square_index: usize = 27;
|
||||||
|
let ray_masks: [u64; 8] = [
|
||||||
|
(1 << 28) | (1 << 29) | (1 << 30) | (1 << 31),
|
||||||
|
(1 << 36) | (1 << 45) | (1 << 54) | (1 << 63),
|
||||||
|
(1 << 35) | (1 << 43) | (1 << 51) | (1 << 59),
|
||||||
|
(1 << 34) | (1 << 41) | (1 << 48),
|
||||||
|
(1 << 26) | (1 << 25) | (1 << 24),
|
||||||
|
(1 << 18) | (1 << 9) | (1 << 0),
|
||||||
|
(1 << 19) | (1 << 11) | (1 << 3),
|
||||||
|
(1 << 20) | (1 << 13) | (1 << 6)
|
||||||
|
];
|
||||||
|
|
||||||
|
// tests for all directions from starting_square
|
||||||
|
for direction in 0..8 {
|
||||||
|
assert_eq!(RAY_TABLE[starting_square_index][direction], ray_masks[direction]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
99
engine/src/bitboard/utils.rs
Normal file
99
engine/src/bitboard/utils.rs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#[inline(always)]
|
||||||
|
pub fn pop_lsb(value: &mut u64) -> usize {
|
||||||
|
let idx = value.trailing_zeros() as usize;
|
||||||
|
*value &= !(1 << idx);
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn pop_msb(value: &mut u64) -> usize {
|
||||||
|
let idx = 63 - value.leading_zeros() as usize;
|
||||||
|
*value &= !(1 << idx);
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
const RANK_NUMBERS: [char; 8] = ['1', '2', '3', '4', '5', '6', '7', '8'];
|
||||||
|
const FILE_LETTERS: [char; 8] = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
||||||
|
pub fn notation_from_square_number(sq: u8) -> String {
|
||||||
|
let row = sq / 8;
|
||||||
|
let col = sq % 8;
|
||||||
|
let mut notation = String::new();
|
||||||
|
|
||||||
|
let row_not = RANK_NUMBERS[row as usize];
|
||||||
|
let col_not = FILE_LETTERS[col as usize];
|
||||||
|
|
||||||
|
notation.push(col_not);
|
||||||
|
notation.push(row_not);
|
||||||
|
return notation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// <----- TESTS ----->
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pop_lsb_test() {
|
||||||
|
|
||||||
|
// test setup
|
||||||
|
let test_values: [u64; 6] = [
|
||||||
|
0x8000_0000_0000_0000,
|
||||||
|
0x4E91_CF05_713E_451B,
|
||||||
|
0xD588_2D58_6962_34B0,
|
||||||
|
0x9581_3335_DCAB_1DD4,
|
||||||
|
0xBEAC_DBE0_903A_AC00,
|
||||||
|
0x01E8_C895_A6F0_0000
|
||||||
|
];
|
||||||
|
let expected_values: [usize; 6] = [63, 0, 4, 2, 10, 20];
|
||||||
|
|
||||||
|
// tests
|
||||||
|
for index in 0..6 {
|
||||||
|
let mut test_value = test_values[index];
|
||||||
|
assert_eq!(pop_lsb(&mut test_value), expected_values[index])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn pop_msb_test() {
|
||||||
|
// test setup
|
||||||
|
let test_values: [u64; 6] = [
|
||||||
|
0x86D6_8EB0_96A8_8D1C,
|
||||||
|
0x0000_0000_0000_0001,
|
||||||
|
0x3809_24AF_A7AE_8129,
|
||||||
|
0x0277_DA36_3B31_86D9,
|
||||||
|
0x0000_C1C3_201C_0DB1,
|
||||||
|
0x0000_0203_0DE4_E944
|
||||||
|
];
|
||||||
|
let expected_values: [usize; 6] = [63, 0, 61, 57, 47, 41];
|
||||||
|
|
||||||
|
// tests
|
||||||
|
for index in 0..6 {
|
||||||
|
let mut test_value = test_values[index];
|
||||||
|
assert_eq!(pop_msb(&mut test_value), expected_values[index])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn notation_from_square_number_test() {
|
||||||
|
// test setup
|
||||||
|
let square_indices: [u8; 8] = [1, 12, 22, 27, 32, 47, 53, 58];
|
||||||
|
let notations: [String; 8] = [
|
||||||
|
String::from("b1"),
|
||||||
|
String::from("e2"),
|
||||||
|
String::from("g3"),
|
||||||
|
String::from("d4"),
|
||||||
|
String::from("a5"),
|
||||||
|
String::from("h6"),
|
||||||
|
String::from("f7"),
|
||||||
|
String::from("c8")
|
||||||
|
];
|
||||||
|
|
||||||
|
// tests
|
||||||
|
for index in 0..8 {
|
||||||
|
let notation = notation_from_square_number(square_indices[index].clone());
|
||||||
|
assert_eq!(notation, notations[index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
mod bitboard;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user