aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-06-26 20:01:36 +0300
committereug-vs <eugene@eug-vs.xyz>2023-06-26 20:01:36 +0300
commit72761f770a73e3e8fac9b57043ed19f084bfb230 (patch)
treebc482dc87dfbddd4cd9a71461d37e9dde41cfb45
parentc3474b1481a02baefda1abe286d4fbef39597bce (diff)
downloadj1chess-tmp.tar.gz
tmp: save progress from @black-pearltmp
-rw-r--r--src/bitboard.c26
-rw-r--r--src/bitboard.h6
-rw-r--r--src/bitboard.ha15
-rw-r--r--src/board.h11
-rw-r--r--src/main.ha11
-rw-r--r--src/move.h6
-rw-r--r--src/types.h15
7 files changed, 78 insertions, 12 deletions
diff --git a/src/bitboard.c b/src/bitboard.c
index e53e3ed..96f220d 100644
--- a/src/bitboard.c
+++ b/src/bitboard.c
@@ -35,3 +35,29 @@ inline int bitscanAndReset(Bitboard* bb) {
*bb &= *bb - 1;
return idx;
}
+
+
+/* These 4 blindly copied from chessprogramming.org TODO: rewrite */
+U64 rankMask(enumSquare sq) {
+ return C64(0xff) << (sq & 56);
+}
+
+U64 fileMask(enumSquare sq) {
+ return C64(0x0101010101010101) << (sq & 7);
+}
+
+U64 diagonalMask(enumSquare sq) {
+ const U64 maindia = C64(0x8040201008040201);
+ int diag =8*(sq & 7) - (sq & 56);
+ int nort = -diag & ( diag >> 31);
+ int sout = diag & (-diag >> 31);
+ return (maindia >> sout) << nort;
+}
+
+U64 antiDiagMask(enumSquare sq) {
+ const U64 maindia = C64(0x0102040810204080);
+ int diag =56- 8*(sq&7) - (sq&56);
+ int nort = -diag & ( diag >> 31);
+ int sout = diag & (-diag >> 31);
+ return (maindia >> sout) << nort;
+}
diff --git a/src/bitboard.h b/src/bitboard.h
index 6b89c84..02298d3 100644
--- a/src/bitboard.h
+++ b/src/bitboard.h
@@ -1,7 +1,6 @@
#include "types.h"
typedef U64 Bitboard;
-#define BIT (U64)1
int popCount(Bitboard bb);
@@ -12,3 +11,8 @@ Bitboard ls1b(Bitboard bb);
int bitscan(Bitboard bb);
int bitscanAndReset(Bitboard* bb);
+
+Bitboard rankMask(enumSquare sq);
+Bitboard fileMask(enumSquare sq);
+Bitboard diagMask(enumSquare sq);
+Bitboard antiDiasMask(enumSquare sq);
diff --git a/src/bitboard.ha b/src/bitboard.ha
new file mode 100644
index 0000000..8af3403
--- /dev/null
+++ b/src/bitboard.ha
@@ -0,0 +1,15 @@
+use fmt;
+
+fn printBitboard(bb: u64) void = {
+ for (let i = 0; i < 64; i+= 1) {
+ fmt::printfln("{}", ((bb >> i) & 1) && '1' || '.');
+ };
+ // if ((index + 1) % 8 == 0) {
+ // };
+};
+
+@test fn printBitboard() void = {
+ let bb: u64 = 123u64;
+ printBitboard(bb);
+
+};
diff --git a/src/board.h b/src/board.h
index b63b494..2f37815 100644
--- a/src/board.h
+++ b/src/board.h
@@ -17,17 +17,6 @@ typedef struct {
BYTE enPassantSquare;
} Board;
-typedef enum enumSquare {
- a1, b1, c1, d1, e1, f1, g1, h1,
- a2, b2, c2, d2, e2, f2, g2, h2,
- a3, b3, c3, d3, e3, f3, g3, h3,
- a4, b4, c4, d4, e4, f4, g4, h4,
- a5, b5, c5, d5, e5, f5, g5, h5,
- a6, b6, c6, d6, e6, f6, g6, h6,
- a7, b7, c7, d7, e7, f7, g7, h7,
- a8, b8, c8, d8, e8, f8, g8, h8
-} enumSquare;
-
static const char* notation[64] = {
"a1", "b1", "c1", "d1", "e1", "f1", "g1", "h1",
"a2", "b2", "c2", "d2", "e2", "f2", "g2", "h2",
diff --git a/src/main.ha b/src/main.ha
new file mode 100644
index 0000000..492f179
--- /dev/null
+++ b/src/main.ha
@@ -0,0 +1,11 @@
+use fmt;
+
+export fn main() void = {
+ fmt::println("Hello world!")!;
+ let a: u64 = 123;
+};
+
+@test fn testWtf() void = {
+ assert(1 == 0, "Failed");
+ fmt::println("Test wtf")!;
+};
diff --git a/src/move.h b/src/move.h
new file mode 100644
index 0000000..4bf244a
--- /dev/null
+++ b/src/move.h
@@ -0,0 +1,6 @@
+#include "bitboard.h"
+
+typedef struct {
+ Bitboard from;
+ Bitboard to;
+} Move;
diff --git a/src/types.h b/src/types.h
index 371d8b8..0728947 100644
--- a/src/types.h
+++ b/src/types.h
@@ -1,6 +1,21 @@
+#ifndef TYPES_H
+#define TYPES_H
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long QWORD;
typedef unsigned long U64;
+#define C64(constantU64) constantU64##ULL
+#define BIT (U64)1
+typedef enum enumSquare {
+ a1, b1, c1, d1, e1, f1, g1, h1,
+ a2, b2, c2, d2, e2, f2, g2, h2,
+ a3, b3, c3, d3, e3, f3, g3, h3,
+ a4, b4, c4, d4, e4, f4, g4, h4,
+ a5, b5, c5, d5, e5, f5, g5, h5,
+ a6, b6, c6, d6, e6, f6, g6, h6,
+ a7, b7, c7, d7, e7, f7, g7, h7,
+ a8, b8, c8, d8, e8, f8, g8, h8
+} enumSquare;
+#endif