diff options
author | nil <niljo@airmail.cc> | 2024-12-18 17:53:17 +0100 |
---|---|---|
committer | nil <niljo@airmail.cc> | 2024-12-18 17:53:17 +0100 |
commit | 2303968dc24664d1fb4383d019420e7ddcf06b8a (patch) | |
tree | dfd0193a6cc1178c193ed1c6ccce0c427cf4f0fd | |
parent | 7b005bc02b1e73c71f8cb8f4e03b6fe6ff420c67 (diff) |
-rw-r--r-- | src/constants.js | 3 | ||||
-rw-r--r-- | src/engine/death.js | 8 | ||||
-rw-r--r-- | src/engine/getPiece.js | 6 | ||||
-rw-r--r-- | src/engine/liberty.js | 10 | ||||
-rw-r--r-- | src/engine/turns.js | 10 | ||||
-rwxr-xr-x | src/index.js | 4 | ||||
-rw-r--r-- | src/link.js | 2 |
7 files changed, 30 insertions, 13 deletions
diff --git a/src/constants.js b/src/constants.js index bb70c8e..5364410 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,6 +1,9 @@ export const PLAYER = { BLACK: "black", WHITE: "white", + OPPOSITE: function(color) { + return color == PLAYER.BLACK ? PLAYER.WHITE : PLAYER.BLACK + }, } export const ASSETS_BLACK = "assets/black.png" 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() } diff --git a/src/index.js b/src/index.js index 5a376ac..4a3ef3f 100755 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,10 @@ import { prepareBoard } from "./board.js" -import { nextTurn } from "./engine/turns.js" +import { startTurn } from "./engine/turns.js" function start() { prepareBoard() - nextTurn() + startTurn() } diff --git a/src/link.js b/src/link.js index 051527c..cb61549 100644 --- a/src/link.js +++ b/src/link.js @@ -21,7 +21,7 @@ export class Link { position: position, team: this.team }) - nextTurn() + nextTurn({move: position}) }); this.update() |