summaryrefslogtreecommitdiff
path: root/src/engine/turns.js
diff options
context:
space:
mode:
authorniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-12 13:51:59 +0100
committerniliara-edu <nil.jimeno@estudiant.fjaverianas.com>2024-12-12 13:51:59 +0100
commiteb460fbb161e76052b7bdd2c57afc65e2e99bc2e (patch)
tree2d8bd718d099a3c9202ac63fb9146754b07e4ef4 /src/engine/turns.js
parentfa377bcc6d4793dcd79ae5c07a43a1193aa2613a (diff)
place pieces
Diffstat (limited to 'src/engine/turns.js')
-rw-r--r--src/engine/turns.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/engine/turns.js b/src/engine/turns.js
new file mode 100644
index 0000000..7026dcc
--- /dev/null
+++ b/src/engine/turns.js
@@ -0,0 +1,35 @@
+import { board } from "../board.js"
+import { Vector2 } from "../engine/visual/vector2.js"
+import { Link } from "../link.js"
+import { PLAYER } from "../constants.js"
+
+export let turn = ""
+
+export function nextTurn() {
+ turn = turn == PLAYER.BLACK ? PLAYER.WHITE : PLAYER.BLACK
+ placeLinks()
+}
+
+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) {
+ new Link({
+ position: position,
+ })
+}