aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2022-09-14 02:59:36 +0300
committereug-vs <eugene@eug-vs.xyz>2022-09-14 02:59:36 +0300
commitf7901374649cd76ac52a6c881c79dc8d64e00981 (patch)
tree4bc0f4aaa5c36b9618f70362f4b13f816216c11d /src/main.c
parent87514fc685ea45241dbb00471388638e0be1b229 (diff)
downloadj1chess-f7901374649cd76ac52a6c881c79dc8d64e00981.tar.gz
feat: compute knight attack table
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 75d3bb7..2e95970 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,17 +1,30 @@
#include "unittest.h"
#include "board.h"
-void test_notations() {
- printf("%u\n", notation_to_index('e', 4));
- unit_test(notation_to_index('e', 4) == 28, "Notation e4 is index 28");
+int main() {
+ { // Pop count
+ unit_test(pop_count(0b01110) == 3, "Pop count of 01110 is 3");
+ }
- char notation[2] = "x0";
- index_to_notation(28, notation);
- unit_test(notation[0] == 'e' && notation [1] == '4', "Index 28 is notation e4");
-}
+ { // Test knight attacks
+ Bitboard attacks[64];
+ precompute_knight_attack_table(attacks);
-int main() {
- test_notations();
+ int max_attacks = 0;
+ for (int i = 0; i < 64; i++) {
+ int attack_count = pop_count(attacks[i]);
+ if (attack_count > max_attacks) max_attacks = attack_count;
+ }
+ unit_test(max_attacks == 8, "Max amount of knight attacks should be 8");
+
+ { // Knight on b7 attack table
+ U64 bit = 1;
+ unit_test(
+ attacks[b7] == ((bit << d8) | (bit << d6) | (bit << c5) | (bit << a5)),
+ "Knight on b7 attacks d8, d6, c5, a5"
+ );
+ }
+ }
report();
return 0;