1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bitboard editor</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);
}
.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;
}
</style>
</head>
<body>
<div id="board">
</div>
<div id="output">
</div>
<script>
const output = document.getElementById("output");
let bitboard = 0n;
function trackBitboard(i, selected) {
const mask = 1n << BigInt(i);
if (selected) {
bitboard |= mask;
} else {
bitboard &= ~mask;
}
output.textContent = bitboard.toString();
}
const selectedAction = trackBitboard;
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");
square.onclick = () => {
const selected = square.classList.contains("selected");
selectedAction(i, !selected);
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);
}
</script>
</body>
</html>
|