From 4de44f6207f53848ea709e428284bab9fab080aa Mon Sep 17 00:00:00 2001
From: Gottschali
Date: Sat, 2 Apr 2022 22:20:23 +0200
Subject: [PATCH 1/2] OOP Hex
---
.../src/client/components/WelcomeInsect.tsx | 6 +-
cra-hive/src/client/lab/BackgroundCanvas.tsx | 4 +-
cra-hive/src/client/pages/TutorialPage.tsx | 88 +++---
cra-hive/src/shared/hexlib.ts | 292 +++++++-----------
cra-hive/src/shared/model/action.ts | 6 +-
cra-hive/src/shared/model/hive.ts | 18 +-
cra-hive/src/shared/model/state.ts | 6 +-
7 files changed, 172 insertions(+), 248 deletions(-)
diff --git a/cra-hive/src/client/components/WelcomeInsect.tsx b/cra-hive/src/client/components/WelcomeInsect.tsx
index 1ee88b0..42150a4 100644
--- a/cra-hive/src/client/components/WelcomeInsect.tsx
+++ b/cra-hive/src/client/components/WelcomeInsect.tsx
@@ -10,9 +10,9 @@ export default function WelcomeInsect() {
+ hex={new HEX.Hex(0, 0)}
+ stone={{ "team": "white", "insect": "bee" }}
+ />
)
diff --git a/cra-hive/src/client/lab/BackgroundCanvas.tsx b/cra-hive/src/client/lab/BackgroundCanvas.tsx
index b51a563..9bfa911 100644
--- a/cra-hive/src/client/lab/BackgroundCanvas.tsx
+++ b/cra-hive/src/client/lab/BackgroundCanvas.tsx
@@ -4,7 +4,7 @@ import { State } from '../../shared/model/state'
const orientation = HEX.orientation_pointy;
-const layout = HEX.Layout(orientation, HEX.Point(10, 10), HEX.Point(500, 250))
+const layout = HEX.Layout(orientation, new HEX.Point(10, 10), new HEX.Point(500, 250))
export default function BackgroundCanvas() {
const state = new State();
@@ -17,7 +17,7 @@ export default function BackgroundCanvas() {
ctx.beginPath()
const corners = HEX.polygon_corners(layout, hex);
ctx.moveTo(corners[5].x + 50, corners[5].y + 50);
- corners.forEach( p => {
+ corners.forEach(p => {
ctx.lineTo(p.x + 50, p.y + 50);
})
ctx.fill();
diff --git a/cra-hive/src/client/pages/TutorialPage.tsx b/cra-hive/src/client/pages/TutorialPage.tsx
index 0c27aaf..3d58c79 100644
--- a/cra-hive/src/client/pages/TutorialPage.tsx
+++ b/cra-hive/src/client/pages/TutorialPage.tsx
@@ -6,11 +6,11 @@ import Insect from '../../shared/model/insects'
import Team from '../../shared/model/teams'
import { Drop } from '../../shared/model/action'
import TestGame from '../lab/TestGame';
-import {Hex} from '../../shared/hexlib'
-import {DropInsectMenuTeam, iconMap} from '../components/DropInsectMenu'
+import { Hex } from '../../shared/hexlib'
+import { DropInsectMenuTeam, iconMap } from '../components/DropInsectMenu'
import { Button } from 'semantic-ui-react'
-export default function TutorialPage () {
+export default function TutorialPage() {
// Idea: define terms
// Make chapers: click to next page
// Boxes for emphasis
@@ -41,70 +41,70 @@ export default function TutorialPage () {
}
-function TutorialLayout({left, right}) {
+function TutorialLayout({ left, right }) {
return
-
- {left}
-
-
- {right}
-
+
+ {left}
+
+ {right}
+
+
}
function Introduction() {
const state = new State();
- state.apply(new Drop(new Stone(Insect.GRASSHOPPER, Team.WHITE), Hex(0, 0)));
- state.apply(new Drop(new Stone(Insect.ANT, Team.BLACK), Hex(1, 0)));
+ state.apply(new Drop(new Stone(Insect.GRASSHOPPER, Team.WHITE), new Hex(0, 0)));
+ state.apply(new Drop(new Stone(Insect.ANT, Team.BLACK), new Hex(1, 0)));
const left = <>
Introduction
- Hive is a strategic boardgame for two players (red and blue).
- Each turn they can either place or move a stone on the board. We will refer to placing an insect as "dropping".
- We will call the stones "insects" from now on. Each of the insects
- has its own set of rules how to move.
- In the beginning there is void and the starting player can select any of his insects to drop.>;
- const right = ;
+ Hive is a strategic boardgame for two players (red and blue).
+ Each turn they can either place or move a stone on the board. We will refer to placing an insect as "dropping".
+ We will call the stones "insects" from now on. Each of the insects
+ has its own set of rules how to move.
+ In the beginning there is void and the starting player can select any of his insects to drop.>;
+ const right = ;
return
}
function Dropping() {
const state = new State();
- state.apply(new Drop(new Stone(Insect.GRASSHOPPER, Team.WHITE), Hex(0, 0)));
- state.apply(new Drop(new Stone(Insect.ANT, Team.BLACK), Hex(1, 0)));
+ state.apply(new Drop(new Stone(Insect.GRASSHOPPER, Team.WHITE), new Hex(0, 0)));
+ state.apply(new Drop(new Stone(Insect.ANT, Team.BLACK), new Hex(1, 0)));
const left = <>
-
Dropping
-
- You can select an insect from this menu to drop. Note the numbers denoting how many of each type you still have available.
- >;
+
Dropping
+
+ You can select an insect from this menu to drop. Note the numbers denoting how many of each type you still have available.
+ >;
const right = [h, 0])}
- canvasHeight="200px" interactive={false} cameraOpts={ {position: [0, -3, 4]} } />;
+ team={state.team}
+ highlighted={state.generateDrops().map(h => [h, 0])}
+ canvasHeight="200px" interactive={false} cameraOpts={{ position: [0, -3, 4] }} />;
return
}
function GoalOfGame() {
const hive = new HiveModel();
- hive.addStone(Hex(0, 0), new Stone(Insect.GRASSHOPPER, Team.WHITE));
- hive.addStone(Hex(1, 0), new Stone(Insect.BEE, Team.BLACK));
- hive.addStone(Hex(0, 1), new Stone(Insect.BEE, Team.WHITE));
- hive.addStone(Hex(1, 1), new Stone(Insect.ANT, Team.BLACK));
- hive.addStone(Hex(1, -1), new Stone(Insect.SPIDER, Team.WHITE));
- hive.addStone(Hex(2, 0), new Stone(Insect.BEETLE, Team.BLACK));
- hive.addStone(Hex(2, -1), new Stone(Insect.ANT, Team.WHITE));
+ hive.addStone(new Hex(0, 0), new Stone(Insect.GRASSHOPPER, Team.WHITE));
+ hive.addStone(new Hex(1, 0), new Stone(Insect.BEE, Team.BLACK));
+ hive.addStone(new Hex(0, 1), new Stone(Insect.BEE, Team.WHITE));
+ hive.addStone(new Hex(1, 1), new Stone(Insect.ANT, Team.BLACK));
+ hive.addStone(new Hex(1, -1), new Stone(Insect.SPIDER, Team.WHITE));
+ hive.addStone(new Hex(2, 0), new Stone(Insect.BEETLE, Team.BLACK));
+ hive.addStone(new Hex(2, -1), new Stone(Insect.ANT, Team.WHITE));
const left = <>
-
The Goal of the Game
-
The goal of the game is to surround the bee of the enemy.
+
The Goal of the Game
+
The goal of the game is to surround the bee of the enemy.
- All six adjacent hexes have to be occupied.
-
In the example the blue player has lost as his bee is completely surrounded.
- Note that the color of the surrounding insects does not matter. Also the own insects count.
- It can happen that the bees get surrounded at the same time. In this case it is a draw.
- >;
+ All six adjacent hexes have to be occupied.
+
In the example the blue player has lost as his bee is completely surrounded.
+ Note that the color of the surrounding insects does not matter. Also the own insects count.
+ It can happen that the bees get surrounded at the same time. In this case it is a draw.
+ >;
- const right = ;
+ const right = ;
return
@@ -114,8 +114,8 @@ function GoalOfGame() {
function singleStone(stone) {
const hive = new HiveModel();
- hive.addStone(Hex(0, 0), stone);
- return ;
+ hive.addStone(new Hex(0, 0), stone);
+ return ;
}
function ExplainBee() {
diff --git a/cra-hive/src/shared/hexlib.ts b/cra-hive/src/shared/hexlib.ts
index a85f73e..e9e7303 100644
--- a/cra-hive/src/shared/hexlib.ts
+++ b/cra-hive/src/shared/hexlib.ts
@@ -1,221 +1,142 @@
// Generated code -- CC0 -- No Rights Reserved -- http://www.redblobgames.com/grids/hexagons/
-export interface Hex {
- q: number;
- r: number;
- s: number;
-}
-export function Point(x, y) {
- return { x: x, y: y };
-}
-// eslint-disable-next-line
-export function Hex(q:number , r: number, s?: number) {
- s = - (q + r)
- if (Math.round(q + r + s) !== 0) throw Error("q + r + s must be 0");
- return { q: q, r: r, s: s };
-}
-
-export function hex_compare(a, b) {
- return a.q === b.q && a.r === b.r
-}
-
-export function hex_add(a, b) {
- return Hex(a.q + b.q, a.r + b.r, a.s + b.s);
-}
+export class Point {
+ x: number;
+ y: number;
-export function hex_subtract(a, b) {
- return Hex(a.q - b.q, a.r - b.r, a.s - b.s);
-}
-
-export function hex_scale(a, k) {
- return Hex(a.q * k, a.r * k, a.s * k);
-}
-
-export function hex_rotate_left(a) {
- return Hex(-a.s, -a.q, -a.r);
-}
-
-function hex_rotate_right(a) {
- return Hex(-a.r, -a.s, -a.q);
-}
-
-export const hex_directions = [
- Hex(1, 0, -1),
- Hex(1, -1, 0),
- Hex(0, -1, 1),
- Hex(-1, 0, 1),
- Hex(-1, 1, 0),
- Hex(0, 1, -1)
-];
-
-function hex_direction(direction) {
- return hex_directions[direction];
-}
-
-function hex_neighbor(hex, delta) {
- return hex_add(hex, delta);
-}
-
-export function hex_neighbors(hex) {
- return hex_directions.map(d => hex_neighbor(hex, d))
-}
-export function hex_circle_iterator(hex) {
- const neighbors = hex_neighbors(hex);
- let result = [];
- for (let i = 0; i < 6; i++) {
- result.push([neighbors[i], neighbors[(i + 1) % 6], neighbors[(i + 2) % 6]]);
+ constructor(x: number, y: number) {
+ this.x = x;
+ this.y = y;
}
- return result;
}
-const hex_diagonals = [
- Hex(2, -1, -1),
- Hex(1, -2, 1),
- Hex(-1, -1, 2),
- Hex(-2, 1, 1),
- Hex(-1, 2, -1),
- Hex(1, 1, -2)
-];
-
-function hex_diagonal_neighbor(hex, direction) {
- return hex_add(hex, hex_diagonals[direction]);
-}
+export class Hex {
+ q: number;
+ r: number;
+ s: number;
-function hex_length(hex) {
- return (Math.abs(hex.q) + Math.abs(hex.r) + Math.abs(hex.s)) / 2;
-}
-function hex_distance(a, b) {
- return hex_length(hex_subtract(a, b));
-}
-
-export function hex_round(h) {
- let qi = Math.round(h.q);
- let ri = Math.round(h.r);
- let si = Math.round(h.s);
- const q_diff = Math.abs(qi - h.q);
- const r_diff = Math.abs(ri - h.r);
- const s_diff = Math.abs(si - h.s);
- if (q_diff > r_diff && q_diff > s_diff) {
- qi = -ri - si;
+ constructor(q: number, r: number, s?: number) {
+ s = - (q + r)
+ if (Math.round(q + r + s) !== 0)
+ throw Error("q + r + s must be 0");
+ this.q = q;
+ this.r = r;
+ this.s = s;
}
- else
- if (r_diff > s_diff) {
- ri = -qi - si;
- }
- else {
- si = -qi - ri;
- }
- return Hex(qi, ri, si);
-}
-function hex_lerp(a, b, t) {
- return Hex(a.q * (1.0 - t) + b.q * t, a.r * (1.0 - t) + b.r * t, a.s * (1.0 - t) + b.s * t);
-}
-
-function hex_linedraw(a, b) {
- const N = hex_distance(a, b);
- const a_nudge = Hex(a.q + 1e-06, a.r + 1e-06, a.s - 2e-06);
- const b_nudge = Hex(b.q + 1e-06, b.r + 1e-06, b.s - 2e-06);
- let results = [];
- const step = 1.0 / Math.max(N, 1);
- for (let i = 0; i <= N; i++) {
- results.push(hex_round(hex_lerp(a_nudge, b_nudge, step * i)));
+ compareTo(other: Hex): boolean {
+ return this.q === other.q && this.r === other.r;
}
- return results;
-}
-
+ add(other: Hex): Hex {
+ return new Hex(this.q + other.q, this.r + other.r, this.s + other.s);
+ }
+ subtract(other: Hex): Hex {
+ return new Hex(this.q - other.q, this.r - other.r, this.s - other.s);
+ }
-function OffsetCoord(col, row) {
- return { col: col, row: row };
-}
+ scale(scale: number): Hex {
+ return new Hex(this.q * scale, this.r * scale, this.s * scale);
+ }
-const EVEN = 1;
-const ODD = -1;
+ rotate_left() {
+ return new Hex(-this.s, -this.q, -this.r);
+ }
-function qoffset_from_cube(offset, h) {
- const col = h.q;
- const row = h.r + (h.q + offset * (h.q & 1)) / 2;
- if (offset !== EVEN && offset !== ODD) {
- throw Error("offset must be EVEN (+1) or ODD (-1)");
+ rotate_right() {
+ return new Hex(-this.r, -this.s, -this.q);
}
- return OffsetCoord(col, row);
-}
-function qoffset_to_cube(offset, h) {
- const q = h.col;
- const r = h.row - (h.col + offset * (h.col & 1)) / 2;
- const s = -q - r;
- if (offset !== EVEN && offset !== ODD) {
- throw Error("offset must be EVEN (+1) or ODD (-1)");
+ abs() {
+ return (Math.abs(this.q) + Math.abs(this.r) + Math.abs(this.s)) / 2;
}
- return Hex(q, r, s);
-}
-function roffset_from_cube(offset, h) {
- const col = h.q + (h.r + offset * (h.r & 1)) / 2;
- const row = h.r;
- if (offset !== EVEN && offset !== ODD) {
- throw Error("offset must be EVEN (+1) or ODD (-1)");
+ distance(hex: Hex) {
+ return (this.subtract(hex)).abs();
}
- return OffsetCoord(col, row);
-}
-function roffset_to_cube(offset, h) {
- const q = h.col - (h.row + offset * (h.row & 1)) / 2;
- const r = h.row;
- const s = -q - r;
- if (offset !== EVEN && offset !== ODD) {
- throw Error("offset must be EVEN (+1) or ODD (-1)");
+ *circleIterator() {
+ const neighbors = hex_neighbors(this);
+ for (let i = 0; i < 6; i++) {
+ yield [neighbors[i], neighbors[(i + 1) % 6], neighbors[(i + 2) % 6]];
+ }
}
- return Hex(q, r, s);
-}
+ round(): Hex {
+ let qi = Math.round(this.q);
+ let ri = Math.round(this.r);
+ let si = Math.round(this.s);
+ const q_diff = Math.abs(qi - this.q);
+ const r_diff = Math.abs(ri - this.r);
+ const s_diff = Math.abs(si - this.s);
+ if (q_diff > r_diff && q_diff > s_diff) {
+ qi = -ri - si;
+ }
+ else
+ if (r_diff > s_diff) {
+ ri = -qi - si;
+ }
+ else {
+ si = -qi - ri;
+ }
+ return new Hex(qi, ri, si);
+ }
+ diagonal_neighbor(direction: number) {
+ return this.add(hex_diagonals[direction]);
+ }
+ lerp(b: Hex, t: number) {
+ return new Hex(this.q * (1.0 - t) + b.q * t, this.r * (1.0 - t) + b.r * t, this.s * (1.0 - t) + b.s * t);
+ }
-function DoubledCoord(col, row) {
- return { col: col, row: row };
-}
+ linedraw(b: Hex) {
+ const N = this.distance(b)
+ const a_nudge = new Hex(this.q + 1e-06, this.r + 1e-06, this.s - 2e-06);
+ const b_nudge = new Hex(b.q + 1e-06, b.r + 1e-06, b.s - 2e-06);
+ let results = [];
+ const step = 1.0 / Math.max(N, 1);
+ for (let i = 0; i <= N; i++) {
+ results.push(a_nudge.lerp(b_nudge, step * i).round());
+ }
+ return results;
+ }
-function qdoubled_from_cube(h) {
- const col = h.q;
- const row = 2 * h.r + h.q;
- return DoubledCoord(col, row);
}
-function qdoubled_to_cube(h) {
- const q = h.col;
- const r = (h.row - h.col) / 2;
- const s = -q - r;
- return Hex(q, r, s);
-}
+export const hex_directions = [
+ new Hex(1, 0, -1),
+ new Hex(1, -1, 0),
+ new Hex(0, -1, 1),
+ new Hex(-1, 0, 1),
+ new Hex(-1, 1, 0),
+ new Hex(0, 1, -1)
+];
-function rdoubled_from_cube(h) {
- const col = 2 * h.q + h.r;
- const row = h.r;
- return DoubledCoord(col, row);
+function hex_direction(direction: number) {
+ return hex_directions[direction];
}
-function rdoubled_to_cube(h) {
- const q = (h.col - h.row) / 2;
- const r = h.row;
- const s = -q - r;
- return Hex(q, r, s);
+export function hex_neighbors(hex: Hex) {
+ return hex_directions.map(d => d.add(hex));
}
-
+const hex_diagonals = [
+ new Hex(2, -1, -1),
+ new Hex(1, -2, 1),
+ new Hex(-1, -1, 2),
+ new Hex(-2, 1, 1),
+ new Hex(-1, 2, -1),
+ new Hex(1, 1, -2)
+];
export function Orientation(f0, f1, f2, f3, b0, b1, b2, b3, start_angle) {
return { f0: f0, f1: f1, f2: f2, f3: f3, b0: b0, b1: b1, b2: b2, b3: b3, start_angle: start_angle };
}
-
-
-
export function Layout(orientation, size, origin) {
return { orientation: orientation, size: size, origin: origin };
}
@@ -229,24 +150,24 @@ export function hex_to_pixel(layout, h) {
const origin = layout.origin;
const x = (M.f0 * h.q + M.f1 * h.r) * size.x;
const y = (M.f2 * h.q + M.f3 * h.r) * size.y;
- return Point(x + origin.x, y + origin.y);
+ return new Point(x + origin.x, y + origin.y);
}
export function pixel_to_hex(layout, p) {
const M = layout.orientation;
const size = layout.size;
const origin = layout.origin;
- const pt = Point((p.x - origin.x) / size.x, (p.y - origin.y) / size.y);
+ const pt = new Point((p.x - origin.x) / size.x, (p.y - origin.y) / size.y);
const q = M.b0 * pt.x + M.b1 * pt.y;
const r = M.b2 * pt.x + M.b3 * pt.y;
- return Hex(q, r, -q - r);
+ return new Hex(q, r, -q - r);
}
export function hex_corner_offset(layout, corner) {
const M = layout.orientation;
const size = layout.size;
const angle = 2.0 * Math.PI * (M.start_angle - corner) / 6.0;
- return Point(size.x * Math.cos(angle), size.y * Math.sin(angle));
+ return new Point(size.x * Math.cos(angle), size.y * Math.sin(angle));
}
export function polygon_corners(layout, h) {
@@ -254,17 +175,18 @@ export function polygon_corners(layout, h) {
const center = hex_to_pixel(layout, h);
for (let i = 0; i < 6; i++) {
const offset = hex_corner_offset(layout, i);
- corners.push(Point(center.x + offset.x, center.y + offset.y));
+ corners.push(new Point(center.x + offset.x, center.y + offset.y));
}
return corners;
}
-export const layoutFlat = Layout(orientation_flat, Point(1, 1), Point(0, 0))
-export const layoutPointy = Layout(orientation_pointy, Point(1, 1), Point(0, 0))
+export const layoutFlat = Layout(orientation_flat, new Point(1, 1), new Point(0, 0))
+export const layoutPointy = Layout(orientation_pointy, new Point(1, 1), new Point(0, 0))
// Tests
+/*
function complain(name) {
console.log("FAIL", name);
}
@@ -325,6 +247,7 @@ function test_hex_rotate_left() {
equal_hex("hex_rotate_left", hex_rotate_left(Hex(1, -3, 2)), Hex(-2, -1, 3));
}
+
function test_hex_round() {
const a = Hex(0.0, 0.0, 0.0);
const b = Hex(1.0, -1.0, 0.0);
@@ -414,3 +337,4 @@ test_all()
// Exports for node/browserify modules:
+*/
diff --git a/cra-hive/src/shared/model/action.ts b/cra-hive/src/shared/model/action.ts
index 99afe46..cc45d61 100644
--- a/cra-hive/src/shared/model/action.ts
+++ b/cra-hive/src/shared/model/action.ts
@@ -1,4 +1,4 @@
-import { Hex, hex_compare } from '../hexlib';
+import { Hex } from '../hexlib';
import Stone from './stone';
export abstract class Action {
@@ -17,7 +17,7 @@ export class Move extends Action {
compareTo(action: Action): boolean {
if (!(action instanceof Move))
return false
- return hex_compare(this.origin, action.origin) && hex_compare(this.destination, action.destination)
+ return this.origin.compareTo(action.origin) && this.destination.compareTo(action.destination)
}
}
@@ -34,7 +34,7 @@ export class Drop extends Action {
compareTo(action: Action): boolean {
if (!(action instanceof Drop))
return false
- return this.stone.team === action.stone.team && this.stone.insect === action.stone.insect && hex_compare(this.destination, action.destination)
+ return this.stone.team === action.stone.team && this.stone.insect === action.stone.insect && this.destination.compareTo(action.destination)
}
}
diff --git a/cra-hive/src/shared/model/hive.ts b/cra-hive/src/shared/model/hive.ts
index d0cef6f..44ecc34 100644
--- a/cra-hive/src/shared/model/hive.ts
+++ b/cra-hive/src/shared/model/hive.ts
@@ -60,13 +60,13 @@ export class Hive {
generateSingleWalks(hex: HEX.Hex, ignore = null): Array {
let result = []
- for (const [a, b, c] of HEX.hex_circle_iterator(hex)) {
+ for (const [a, b, c] of hex.circleIterator()) {
if (this.map.has(b)) continue
if (ignore === null) {
if (this.map.has(a) !== this.map.has(c)) result.push(b)
} else {
// ignore was probably not working because object comparison
- if ((this.map.has(a) && !HEX.hex_compare(a, ignore)) !== (this.map.has(c) && !HEX.hex_compare(c, ignore))) {
+ if ((this.map.has(a) && !a.compareTo(ignore)) !== (this.map.has(c) && !c.compareTo(ignore))) {
result.push(b)
}
}
@@ -88,7 +88,7 @@ export class Hive {
distance.set(n, distance.get(vertex) + 1)
queue.push(n)
}
- if (target === -1 && !HEX.hex_compare(vertex, start)) {
+ if (target === -1 && !vertex.compareTo(start)) {
result.push(vertex)
} else {
let d = distance.get(vertex)
@@ -105,10 +105,10 @@ export class Hive {
generateJumps(hex: HEX.Hex): Array {
let result = []
for (const offset of HEX.hex_directions) {
- if (this.map.has(HEX.hex_add(hex, offset))) {
+ if (this.map.has(hex.add(offset))) {
let i = 2
- while (this.map.has(HEX.hex_add(hex, HEX.hex_scale(offset, i)))) i++
- result.push(HEX.hex_add(hex, HEX.hex_scale(offset, i)))
+ while (this.map.has(hex.add(offset.scale(i)))) i++
+ result.push(hex.add(offset.scale(i)))
}
}
return result
@@ -117,13 +117,13 @@ export class Hive {
let result = []
let hh = this.height(hex)
if (hh > 1) {
- for (const [a, b, c] of HEX.hex_circle_iterator(hex)) {
+ for (const [a, b, c] of hex.circleIterator()) {
if (this.height(b) < hh) {
if ((this.height(a) < hh) || (this.height(c) < hh)) result.push(b)
}
}
} else result.concat(this.generateSingleWalks(hex))
- for (const [a, b, c] of HEX.hex_circle_iterator(hex)) {
+ for (const [a, b, c] of hex.circleIterator()) {
let ha = this.height(a)
let hb = this.height(b)
let hc = this.height(c)
@@ -158,7 +158,7 @@ export class Hive {
lowLink.set(node, counter)
let children = 0
for (const n of this.neighbors(node)) {
- if (parent && HEX.hex_compare(n, parent)) continue
+ if (parent && n.compareTo(parent)) continue
if (visited.has(n)) lowLink.set(node, Math.min(lowLink.get(node), index.get(n)))
else {
dfs(n, node, counter)
diff --git a/cra-hive/src/shared/model/state.ts b/cra-hive/src/shared/model/state.ts
index 95403cd..9188f85 100644
--- a/cra-hive/src/shared/model/state.ts
+++ b/cra-hive/src/shared/model/state.ts
@@ -68,8 +68,8 @@ export class State {
return this._beeMove.get(this.team)
}
generateDrops(): Array {
- if (this.turnNumber === 0) return [HEX.Hex(0, 0)];
- else if (this.turnNumber === 1) return [HEX.Hex(0, -1)];
+ if (this.turnNumber === 0) return [new HEX.Hex(0, 0)];
+ else if (this.turnNumber === 1) return [new HEX.Hex(0, -1)];
return this.hive.generateDrops(this.team)
}
_getActions(): Array {
@@ -167,7 +167,7 @@ export class State {
if (this.moveAllowed) {
for (const action of this.actions) {
if (action instanceof Move) {
- if (HEX.hex_compare(action.origin, hex)) {
+ if (action.origin.compareTo(hex)) {
return true;
}
}
From 60ff18ba900fd3ca939cfc470b69850656c63735 Mon Sep 17 00:00:00 2001
From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com>
Date: Wed, 1 Jun 2022 22:35:59 +0000
Subject: [PATCH 2/2] Bump eventsource from 1.1.0 to 1.1.1 in /cra-hive
Bumps [eventsource](https://github.com/EventSource/eventsource) from 1.1.0 to 1.1.1.
- [Release notes](https://github.com/EventSource/eventsource/releases)
- [Changelog](https://github.com/EventSource/eventsource/blob/master/HISTORY.md)
- [Commits](https://github.com/EventSource/eventsource/compare/v1.1.0...v1.1.1)
---
updated-dependencies:
- dependency-name: eventsource
dependency-type: indirect
...
Signed-off-by: dependabot[bot]
---
cra-hive/package-lock.json | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/cra-hive/package-lock.json b/cra-hive/package-lock.json
index 3c7c70a..6a7888c 100644
--- a/cra-hive/package-lock.json
+++ b/cra-hive/package-lock.json
@@ -7874,9 +7874,9 @@
}
},
"node_modules/eventsource": {
- "version": "1.1.0",
- "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.1.0.tgz",
- "integrity": "sha512-VSJjT5oCNrFvCS6igjzPAt5hBzQ2qPBFIbJ03zLI9SE0mxwZpMw6BfJrbFHm1a141AavMEB8JHmBhWAd66PfCg==",
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.1.1.tgz",
+ "integrity": "sha512-qV5ZC0h7jYIAOhArFJgSfdyz6rALJyb270714o7ZtNnw2WSJ+eexhKtE0O8LYPRsHZHf2osHKZBxGPvm3kPkCA==",
"dependencies": {
"original": "^1.0.0"
},
@@ -26150,9 +26150,9 @@
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q=="
},
"eventsource": {
- "version": "1.1.0",
- "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.1.0.tgz",
- "integrity": "sha512-VSJjT5oCNrFvCS6igjzPAt5hBzQ2qPBFIbJ03zLI9SE0mxwZpMw6BfJrbFHm1a141AavMEB8JHmBhWAd66PfCg==",
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.1.1.tgz",
+ "integrity": "sha512-qV5ZC0h7jYIAOhArFJgSfdyz6rALJyb270714o7ZtNnw2WSJ+eexhKtE0O8LYPRsHZHf2osHKZBxGPvm3kPkCA==",
"requires": {
"original": "^1.0.0"
}
@@ -27517,8 +27517,7 @@
"integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ=="
},
"immer": {
- "version": "8.0.1",
- "resolved": "https://registry.npmjs.org/immer/-/immer-8.0.1.tgz",
+ "version": "https://registry.npmjs.org/immer/-/immer-8.0.1.tgz",
"integrity": "sha512-aqXhGP7//Gui2+UrEtvxZxSquQVXTpZ7KDxfCcKAF3Vysvw0CViVaW9RZ1j1xlIYqaaaipBoqdqeibkc18PNvA=="
},
"import-cwd": {