Bitboard for the 3x3 Tic-Tac-Toe game
.EagleDawn.
9,732 views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Bitboard for the 3x3 Tic-Tac-Toe game
This is a simple bitboard representation for the 3x3 Tic-Tac-Toe game.
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
class Board {
constructor() {
// dimensions
this.rows = 3;
this.cols = 3;
// boards
this.x_player = 0b000000000;
this.o_player = 0b000000000;
this.full_board = 0b111111111;
// win conditions
this.win_conditions = [
0b111000000,
0b000111000,
0b000000111,
0b100100100,
0b010010010,
0b001001001,
0b100010001,
0b001010100
];
}
maskOf(idx) {
return 1 << idx;
}
playX(idx) {
let mask = this.maskOf(idx);
this.x_player |= mask;
}
playO(idx) {
let mask = this.maskOf(idx);
this.o_player |= mask;
}
fillX(...idxs) {
for (let idx of idxs) {
this.playX(idx);
}
}
fillO(...idxs) {
for (let idx of idxs) {
this.playO(idx);
}
}
reset() {
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content