summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-02-25 18:44:23 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-02-25 18:44:23 +0530
commit06f02873bf6e819ae343effefd3354cd011e7f07 (patch)
treef09f70659edc44b24ebef61a8628b1166c015aa4
parent63fa6656749d1cdb6a54a001950048a9660f0d73 (diff)
board.html + moveable pieces & bitboard updates
-rw-r--r--assets/bb.webpbin0 -> 538 bytes
-rw-r--r--assets/bk.webpbin0 -> 1028 bytes
-rw-r--r--assets/bn.webpbin0 -> 740 bytes
-rw-r--r--assets/board.js156
-rw-r--r--assets/bp.pngbin0 -> 692 bytes
-rw-r--r--assets/bq.pngbin0 -> 1563 bytes
-rw-r--r--assets/br.webpbin0 -> 274 bytes
-rw-r--r--assets/wb.webpbin0 -> 834 bytes
-rw-r--r--assets/wk.webpbin0 -> 946 bytes
-rw-r--r--assets/wn.pngbin0 -> 1263 bytes
-rw-r--r--assets/wp.pngbin0 -> 898 bytes
-rw-r--r--assets/wq.webpbin0 -> 1388 bytes
-rw-r--r--assets/wr.pngbin0 -> 748 bytes
-rw-r--r--board.html75
-rw-r--r--src/search/pawn_moves.c2
15 files changed, 232 insertions, 1 deletions
diff --git a/assets/bb.webp b/assets/bb.webp
new file mode 100644
index 0000000..f780b4d
--- /dev/null
+++ b/assets/bb.webp
Binary files differ
diff --git a/assets/bk.webp b/assets/bk.webp
new file mode 100644
index 0000000..23d2e3b
--- /dev/null
+++ b/assets/bk.webp
Binary files differ
diff --git a/assets/bn.webp b/assets/bn.webp
new file mode 100644
index 0000000..68a6d63
--- /dev/null
+++ b/assets/bn.webp
Binary files differ
diff --git a/assets/board.js b/assets/board.js
new file mode 100644
index 0000000..6b8486a
--- /dev/null
+++ b/assets/board.js
@@ -0,0 +1,156 @@
+const assets = [
+ "wk.webp",
+ "wq.webp",
+ "wr.png",
+ "wb.webp",
+ "wn.png",
+ "wp.png",
+ "bk.webp",
+ "bq.png",
+ "br.webp",
+ "bb.webp",
+ "bn.webp",
+ "bp.png"
+].map(x => "./assets/" + x);
+let hoveringPiece = -1;
+
+const bitboards = [
+ 16n,
+ 8n,
+ 129n,
+ 36n,
+ 66n,
+ 65280n,
+ 1152921504606846976n,
+ 576460752303423488n,
+ 9295429630892703744n,
+ 2594073385365405696n,
+ 4755801206503243776n,
+ 71776119061217280n,
+];
+const WHITE_KING = 1;
+const WHITE_QUEEN = 2;
+const WHITE_ROOK = 3;
+const WHITE_BISHOP = 4;
+const WHITE_KNIGHT = 5;
+const WHITE_PAWN = 6;
+const BLACK_KING = 7;
+const BLACK_QUEEN = 8;
+const BLACK_ROOK = 9;
+const BLACK_BISHOP = 10;
+const BLACK_KNIGHT = 11;
+const BLACK_PAWN = 12;
+
+function trackBitboard(j, i, selected, output) {
+ const mask = 1n << BigInt(i);
+ if (selected) {
+ bitboards[j] |= mask;
+ } else {
+ bitboards[j] &= ~mask;
+ }
+ output.textContent = bitboards[j].toString();
+}
+
+function checkForPiece(square, bitIndex, set = true) {
+ for (let i = 0; i < bitboards.length; i++) {
+ const mask = bitboards[i];
+ if ((mask >> BigInt(bitIndex)) & 1n) {
+ if (set) square.style.backgroundImage = `url(${assets[i]})`;
+ return i;
+ }
+ }
+ return null;
+}
+
+const selectedAction = trackBitboard;
+
+window.onkeydown = (e) => {
+ if (e.key == 'b') {
+ console.log('Bitboards');
+ console.log(`
+position.bitboards[WHITE_KING] = ${bitboards[0].toString()}ULL;
+position.bitboards[WHITE_QUEEN] = ${bitboards[1].toString()}ULL;
+position.bitboards[WHITE_ROOK] = ${bitboards[2].toString()}ULL;
+position.bitboards[WHITE_BISHOP] = ${bitboards[3].toString()}ULL;
+position.bitboards[WHITE_KNIGHT] = ${bitboards[4].toString()}ULL;
+position.bitboards[WHITE_PAWN] = ${bitboards[5].toString()}ULL;
+position.bitboards[BLACK_KING] = ${bitboards[6].toString()}ULL;
+position.bitboards[BLACK_QUEEN] = ${bitboards[7].toString()}ULL;
+position.bitboards[BLACK_ROOK] = ${bitboards[8].toString()}ULL;
+position.bitboards[BLACK_BISHOP] = ${bitboards[9].toString()}ULL;
+position.bitboards[BLACK_KNIGHT] = ${bitboards[10].toString()}ULL;
+position.bitboards[BLACK_PAWN] = ${bitboards[11].toString()}ULL;
+ `)
+ }
+}
+window.onload = () => {
+ const output = document.getElementById("output");
+ const board = document.getElementById("board");
+ for (let i = 0; i < 64; i++) {
+ if (i % 8 == 0) {
+ const label = document.createElement("div");
+ label.classList.add("label");
+ label.textContent = ["h", "g", "f", "e", "d", "c", "b", "a"][i / 8];
+ board.appendChild(label);
+ }
+ const square = document.createElement("div");
+ square.classList.add("square");
+ const shift = Math.floor(i / 8);
+ square.classList.add((i + shift) % 2 ? "dark" : "light");
+ const bitIndex = (i % 8) - 8 * Math.floor(i / 8) + 56;
+ square.id = 'square-' + bitIndex.toString();
+ checkForPiece(square, bitIndex);
+ square.onclick = (e) => {
+ if (!e.ctrlKey) {
+ const piece = checkForPiece(square, bitIndex, false);
+ if (
+ (hoveringPiece < 0 && piece == null) ||
+ (hoveringPiece >= 0 && piece != null)
+ ) return;
+ if (hoveringPiece < 0) {
+ setHoverpiece(piece);
+ square.style.backgroundImage = `none`;
+ bitboards[piece] &= ~(1n << BigInt(bitIndex));
+ } else {
+ square.style.backgroundImage = `url(${assets[hoveringPiece]})`;
+ bitboards[hoveringPiece] |= (1n << BigInt(bitIndex));
+ setHoverpiece(-1);
+ }
+ return;
+ }
+ const selected = square.classList.contains("selected");
+ selectedAction(0, bitIndex, !selected, output);
+ if (selected) {
+ square.classList.remove("selected");
+ } else {
+ square.classList.add("selected");
+ }
+ };
+ board.appendChild(square);
+ }
+ const label = document.createElement("div");
+ label.classList.add("horizontal_label");
+ board.appendChild(label);
+ for (let i = 1; i < 9; i++) {
+ const label = document.createElement("div");
+ label.classList.add("horizontal_label");
+ label.textContent = i;
+ board.appendChild(label);
+ }
+
+ const mouse = document.getElementById("mouse");
+ function setHoverpiece(i) {
+ hoveringPiece = i;
+ if (i < 0) {
+ mouse.style.backgroundImage = `none`;
+ return;
+ }
+ mouse.style.backgroundImage = `url(${assets[i]})`;
+ }
+ window.onmousemove = (e) => {
+ const x = e.clientX;
+ const y = e.clientY;
+ mouse.style.left = x.toString() + 'px';
+ mouse.style.top = y.toString() + 'px';
+ }
+}
diff --git a/assets/bp.png b/assets/bp.png
new file mode 100644
index 0000000..fa57435
--- /dev/null
+++ b/assets/bp.png
Binary files differ
diff --git a/assets/bq.png b/assets/bq.png
new file mode 100644
index 0000000..6334dd4
--- /dev/null
+++ b/assets/bq.png
Binary files differ
diff --git a/assets/br.webp b/assets/br.webp
new file mode 100644
index 0000000..8d078e1
--- /dev/null
+++ b/assets/br.webp
Binary files differ
diff --git a/assets/wb.webp b/assets/wb.webp
new file mode 100644
index 0000000..5020e5e
--- /dev/null
+++ b/assets/wb.webp
Binary files differ
diff --git a/assets/wk.webp b/assets/wk.webp
new file mode 100644
index 0000000..72fdcf7
--- /dev/null
+++ b/assets/wk.webp
Binary files differ
diff --git a/assets/wn.png b/assets/wn.png
new file mode 100644
index 0000000..a03ccac
--- /dev/null
+++ b/assets/wn.png
Binary files differ
diff --git a/assets/wp.png b/assets/wp.png
new file mode 100644
index 0000000..d968278
--- /dev/null
+++ b/assets/wp.png
Binary files differ
diff --git a/assets/wq.webp b/assets/wq.webp
new file mode 100644
index 0000000..bfbd57a
--- /dev/null
+++ b/assets/wq.webp
Binary files differ
diff --git a/assets/wr.png b/assets/wr.png
new file mode 100644
index 0000000..69811d8
--- /dev/null
+++ b/assets/wr.png
Binary files differ
diff --git a/board.html b/board.html
new file mode 100644
index 0000000..add0337
--- /dev/null
+++ b/board.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Board</title>
+ <style>
+ :root {
+ --square-side-length: 6rem;
+ --dark-color: #779556;
+ --light-color: #ebecd0;
+ --selected-color: #f37f6b;
+ --background-color: #0f0f0f;
+ --text-color: #fefefe;
+ }
+ body {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ background-color: var(--background-color);
+ color: var(--text-color);
+ }
+ #board {
+ display: grid;
+ grid-template-columns: repeat(9, 1fr);
+ grid-template-rows: repeat(9, 1fr);
+ }
+ .dark {
+ background-color: var(--dark-color);
+ }
+ .light {
+ background-color: var(--light-color);
+ }
+ .selected {
+ background-color: var(--selected-color);
+ }
+ .square {
+ width: var(--square-side-length);
+ height: var(--square-side-length);
+ background-size: cover;
+ }
+ .label {
+ width: var(--square-side-length);
+ height: var(--square-side-length);
+ display: flex;
+ align-items: center;
+ justify-content: flex-end;
+ }
+ .horizontal_label {
+ width: var(--square-side-length);
+ height: var(--square-side-length);
+ display: flex;
+ justify-content: center;
+ }
+ #mouse {
+ position: absolute;
+ width: var(--square-side-length);
+ height: var(--square-side-length);
+ transform: translate(-50%, -50%);
+ transition: 0.1s ease out;
+ pointer-events: none;
+ background-size: cover;
+ }
+ </style>
+ <script src="./assets/board.js"></script>
+</head>
+<body>
+ <div id="board">
+ </div>
+ <div id="output">
+ </div>
+ <div id="mouse">
+ </div>
+</body>
+</html>
diff --git a/src/search/pawn_moves.c b/src/search/pawn_moves.c
index 58eac83..e169c07 100644
--- a/src/search/pawn_moves.c
+++ b/src/search/pawn_moves.c
@@ -12,7 +12,7 @@ void get_white_pawn_moves(moves_t* moves, position_t position) {
bitboard_t friendly_pawns = position.bitboards[WHITE_PAWN];
bitboard_t y = friendly_pieces | enemy_bitboard;
bitboard_t x = ~((friendly_pawns << 8) & y) & (friendly_pawns << 8);
- bitboard_t first_move_x = x | BITMASK_RANK_C;
+ bitboard_t first_move_x = x & BITMASK_RANK_C;
first_move_x |= (first_move_x << 8) & (~y);
x |= first_move_x;