diff options
| -rw-r--r-- | assets/board.js | 41 | ||||
| -rw-r--r-- | board.html | 11 | ||||
| -rw-r--r-- | src/search.h | 1 | ||||
| -rw-r--r-- | src/search/bishop_moves.c | 7 | ||||
| -rw-r--r-- | src/search/moves.c | 4 | ||||
| -rw-r--r-- | src/search/queen_moves.c | 14 | ||||
| -rw-r--r-- | src/search/rook_moves.c | 7 | ||||
| -rw-r--r-- | src/server.c | 5 |
8 files changed, 86 insertions, 4 deletions
diff --git a/assets/board.js b/assets/board.js index e4dcb87..fdfeb28 100644 --- a/assets/board.js +++ b/assets/board.js @@ -84,7 +84,37 @@ position.bitboards[BLACK_PAWN] = ${bitboards[11].toString()}ULL; `) } } + +let validMoves = {}; +let renderingMoves = []; + +function updateRenderingMoves() { + for (let i = 0; i < 64; i++) { + const square = document.getElementById(`square-${i}`); + if (i in renderingMoves) { + square.children[0].classList.add("possible_move"); + } else { + square.children[0].classList.remove("possible_move"); + } + } +} + +function addMoves(moves) { + console.log(moves); + validMoves = {}; + for (const [from, to] of moves) { + if (validMoves[from] == undefined) validMoves[from] = [] + validMoves[from].push(to); + } + + console.log(validMoves); +} + window.onload = () => { + const socket = new WebSocket("ws://localhost:3456"); + socket.addEventListener("moves", (event) => addMoves(event.data)); + // socket.addEventListener("do_move", (event) => addMoves(event.data)); + const output = document.getElementById("output"); const board = document.getElementById("board"); for (let i = 0; i < 64; i++) { @@ -96,6 +126,11 @@ window.onload = () => { } const square = document.createElement("div"); square.classList.add("square"); + + const renderingMoveMarker = document.createElement("div"); + renderingMoveMarker.classList.add("rendering_marker"); + square.appendChild(renderingMoveMarker); + const shift = Math.floor(i / 8); square.classList.add((i + shift) % 2 ? "dark" : "light"); const bitIndex = (i % 8) - 8 * Math.floor(i / 8) + 56; @@ -112,20 +147,26 @@ window.onload = () => { } return; } + const piece = checkForPiece(square, bitIndex, false); if ( (hoveringPiece < 0 && piece == null) || (hoveringPiece >= 0 && piece != null) ) return; if (hoveringPiece < 0) { + if (validMoves[bitIndex]) { + renderingMoves = validMoves[bitIndex]; + } setHoverpiece(piece); square.style.backgroundImage = `none`; bitboards[piece] &= ~(1n << BigInt(bitIndex)); } else { + renderingMoves = []; square.style.backgroundImage = `url(${assets[hoveringPiece]})`; bitboards[hoveringPiece] |= (1n << BigInt(bitIndex)); setHoverpiece(-1); } + updateRenderingMoves(); }; board.appendChild(square); } @@ -34,10 +34,21 @@ .selected { background-color: var(--selected-color); } + .rendering_marker { + width: 2rem; + height: 2rem; + border-radius: 50%; + } + .possible_move { + background-color: #0f0f0f55; + } .square { width: var(--square-side-length); height: var(--square-side-length); background-size: cover; + display: flex; + justify-content: center; + align-items: center; } .label { width: var(--square-side-length); diff --git a/src/search.h b/src/search.h index 5648e99..85311f1 100644 --- a/src/search.h +++ b/src/search.h @@ -10,6 +10,7 @@ typedef struct { square_t from; square_t to; } move_t; +void position_make_move(position_t* position, move_t* move); typedef struct { move_t* moves; diff --git a/src/search/bishop_moves.c b/src/search/bishop_moves.c index 29fe3a6..207535e 100644 --- a/src/search/bishop_moves.c +++ b/src/search/bishop_moves.c @@ -68,5 +68,10 @@ void get_bishop_moves(moves_t* moves, position_t position) { friendly_bishops = position.bitboards[BLACK_BISHOP]; } - __forloop_bishop_moves_gen(moves, friendly_bishops, friendly_pieces, enemy_pieces); + __forloop_bishop_moves_gen( + moves, + friendly_bishops, + friendly_pieces, + enemy_pieces + ); } diff --git a/src/search/moves.c b/src/search/moves.c index 7089886..c0cdb4e 100644 --- a/src/search/moves.c +++ b/src/search/moves.c @@ -2,6 +2,10 @@ #include <assert.h> #include <stdlib.h> +void position_make_move(position_t* position, move_t* move) { + +} + moves_t moves_init() { return moves_init_wcapacity(16); } diff --git a/src/search/queen_moves.c b/src/search/queen_moves.c index f1e773a..973c5bc 100644 --- a/src/search/queen_moves.c +++ b/src/search/queen_moves.c @@ -16,6 +16,16 @@ void get_queen_moves(moves_t* moves, position_t position) { friendly_queens = position.bitboards[BLACK_QUEEN]; } - __forloop_rook_moves_gen(moves, friendly_queens, friendly_pieces, enemy_pieces); - __forloop_bishop_moves_gen(moves, friendly_queens, friendly_pieces, enemy_pieces); + __forloop_rook_moves_gen( + moves, + friendly_queens, + friendly_pieces, + enemy_pieces + ); + __forloop_bishop_moves_gen( + moves, + friendly_queens, + friendly_pieces, + enemy_pieces + ); } diff --git a/src/search/rook_moves.c b/src/search/rook_moves.c index 778c6a1..3e25526 100644 --- a/src/search/rook_moves.c +++ b/src/search/rook_moves.c @@ -68,5 +68,10 @@ void get_rook_moves(moves_t* moves, position_t position) { friendly_rooks = position.bitboards[BLACK_ROOK]; } - __forloop_rook_moves_gen(moves, friendly_rooks, friendly_pieces, enemy_pieces); + __forloop_rook_moves_gen( + moves, + friendly_rooks, + friendly_pieces, + enemy_pieces + ); } diff --git a/src/server.c b/src/server.c new file mode 100644 index 0000000..8409611 --- /dev/null +++ b/src/server.c @@ -0,0 +1,5 @@ + + +int main() { + +} |
