From 2303968dc24664d1fb4383d019420e7ddcf06b8a Mon Sep 17 00:00:00 2001 From: nil Date: Wed, 18 Dec 2024 17:53:17 +0100 Subject: progress --- src/engine/death.js | 8 ++++++++ src/engine/getPiece.js | 6 ++++++ src/engine/liberty.js | 10 ++-------- src/engine/turns.js | 10 ++++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 src/engine/death.js create mode 100644 src/engine/getPiece.js (limited to 'src/engine') diff --git a/src/engine/death.js b/src/engine/death.js new file mode 100644 index 0000000..a67c48e --- /dev/null +++ b/src/engine/death.js @@ -0,0 +1,8 @@ +import {} from "../engine/liberty.js" +import { getPiece } from "../engine/getPiece.js" +import { PLAYER } from "../constants.js" + +export function removeDeadStones(move) { + let team = PLAYER.OPPOSITE(getPiece(move).team) + console.log(team) +} diff --git a/src/engine/getPiece.js b/src/engine/getPiece.js new file mode 100644 index 0000000..ac736cc --- /dev/null +++ b/src/engine/getPiece.js @@ -0,0 +1,6 @@ +import {board} from "../board.js" + +export function getPiece(position) { + return board.stones[position.y][position.x] +} + diff --git a/src/engine/liberty.js b/src/engine/liberty.js index 0947ab0..3af21e2 100644 --- a/src/engine/liberty.js +++ b/src/engine/liberty.js @@ -1,5 +1,5 @@ -import { board } from "../board.js" import { Vector2 } from "../engine/vector2.js" +import { getPiece } from "../engine/getPiece.js" import { PLAYER } from "../constants.js" const SURROUNDING = [ @@ -93,9 +93,7 @@ function getSurroundingGroups(position, team) { function getGroupSurroundingEnemies(group, playerTeam) { if (group.length == 0) return [] - let team = playerTeam == PLAYER.BLACK ? - PLAYER.WHITE : - PLAYER.BLACK + let team = PLAYER.OPPOSITE(playerTeam) let surroundingEnemies = group .map(p => getSurroundingGroups(p, team)) @@ -115,10 +113,6 @@ function getGroupSurroundingEnemies(group, playerTeam) { }) } -function getPiece(position) { - return board.stones[position.y][position.x] -} - function getSurroundingSquares(position) { return Array.from(SURROUNDING) .map(v => Vector2.sum(v, position)) diff --git a/src/engine/turns.js b/src/engine/turns.js index 0018417..0906932 100644 --- a/src/engine/turns.js +++ b/src/engine/turns.js @@ -1,10 +1,16 @@ import { PLAYER } from "../constants.js" import { placeLinks } from "../engine/placeLinks.js" +import { removeDeadStones } from "../engine/death.js" -export let playerTurn = "" +export let playerTurn = "black" -export function nextTurn() { +export function nextTurn({move = null}) { + if (move != null) removeDeadStones(move) changeTurn() + startTurn() +} + +export function startTurn() { placeLinks() } -- cgit v1.2.3