From 16e02376e2273eeb25a6461f84641e96a485f652 Mon Sep 17 00:00:00 2001 From: nil Date: Thu, 12 Dec 2024 18:20:22 +0100 Subject: add legal movements and organize --- src/engine/turns.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/engine/turns.js') diff --git a/src/engine/turns.js b/src/engine/turns.js index 7026dcc..6a5e6fb 100644 --- a/src/engine/turns.js +++ b/src/engine/turns.js @@ -2,14 +2,19 @@ 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 turn = "" +export let playerTurn = "" export function nextTurn() { - turn = turn == PLAYER.BLACK ? PLAYER.WHITE : PLAYER.BLACK + changeTurn() placeLinks() } +function changeTurn() { + playerTurn = playerTurn == PLAYER.BLACK ? PLAYER.WHITE : PLAYER.BLACK +} + function placeLinks() { resetLink() board.links = [...Array(board.size)].map(_ => Array(board.size)) @@ -22,13 +27,22 @@ function placeLinks() { function resetLink() { Array.from(board.links).forEach(x => { - Array.from(x).filter((x) => x !== undefined).map(y => { - y.removeLink() - }) + 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, }) -- cgit v1.2.3