blob: 6a5e6fba36c2a96e9d24d62f205901c6aa2a3db7 (
plain)
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
|
import { board } from "../board.js"
import { Vector2 } from "../engine/visual/vector2.js"
import { Link } from "../link.js"
import { PLAYER } from "../constants.js"
import { isMoveLegal } from "../engine/moves.js"
export let playerTurn = ""
export function nextTurn() {
changeTurn()
placeLinks()
}
function changeTurn() {
playerTurn = playerTurn == PLAYER.BLACK ? PLAYER.WHITE : PLAYER.BLACK
}
function placeLinks() {
resetLink()
board.links = [...Array(board.size)].map(_ => Array(board.size))
for (let row = 0; row < board.size; row++) {
for (let col = 0; col < board.size; col++) {
tryLink(new Vector2(row, col))
}
}
}
function resetLink() {
Array.from(board.links).forEach(x => {
Array.from(x)
.filter((x) => x !== undefined)
.map(y => {
y.removeLink()
})
})
}
function tryLink(position) {
if (!isMoveLegal({
position: position,
team: playerTurn
})) {
return
}
new Link({
position: position,
})
}
|