-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboard.js
51 lines (38 loc) · 1.31 KB
/
board.js
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
function Board(){
this.grid = Array.from({ length: 8 }, () => Array(8).fill(null))
this.grid[4][3] = this.grid[3][4] = 0
this.grid[3][3] = this.grid[4][4] = 1
this.place = function(row, col, toFlip){
players[1-turn]++
this.grid[row][col] = turn
for (let i = 0; i < toFlip.length; i++){
let flipR = toFlip[i][0]
let flipC = toFlip[i][1]
this.grid[flipR][flipC] = turn
players[turn]--
players[1-turn]++
}
turn = 1 - turn
calculateValid()
}
this.draw = function(){
push()
let boardLength = height * 0.8
let offsetX = (width - boardLength) / 2
let offsetY = height - boardLength - 20
translate(offsetX, offsetY)
for (let row = 0; row < 8; row++){
for (let col = 0; col < 8; col++){
let color = this.grid[row][col]
if (color === null) continue
fill(0)
if (color) fill(255)
strokeWeight(2.5)
ellipse(col * (boardLength / 8) + boardLength / 16,
row * (boardLength / 8) + boardLength / 16,
0.8* boardLength / 8);
}
}
pop()
}
}