Skip to content

Commit 141205f

Browse files
committed
Pacru: Fix orientation highlighting
1 parent 9e53809 commit 141205f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/common/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { shuffle } from "./shuffle";
55
import { UserFacingError } from "./errors";
66
import { HexTriGraph, SnubSquareGraph, SquareOrthGraph, SquareDiagGraph, SquareGraph, Square3DGraph, SquareDirectedGraph, SquareFanoronaGraph, BaoGraph, SowingNoEndsGraph } from "./graphs";
77
import { wng } from "./namegenerator";
8-
import { projectPoint, ptDistance, smallestDegreeDiff, normDeg, deg2rad, rad2deg, toggleFacing, calcBearing, matrixRectRot90, matrixRectRotN90, transposeRect, circle2poly, midpoint, distFromCircle, deg2dir, dir2deg } from "./plotting";
8+
import { projectPoint, ptDistance, smallestDegreeDiff, normDeg, deg2rad, rad2deg, toggleFacing, calcBearing, matrixRectRot90, matrixRectRotN90, transposeRect, circle2poly, midpoint, distFromCircle, deg2dir, dir2deg, rotateFacing } from "./plotting";
99
import { hexhexAi2Ap, hexhexAp2Ai, triAi2Ap, triAp2Ai } from "./aiai";
1010
import stringify from "json-stringify-deterministic";
1111
import fnv from "fnv-plus";
1212

13-
export { RectGrid, StackSet, reviver, replacer, sortingReplacer, shuffle, UserFacingError, HexTriGraph, SnubSquareGraph, SquareOrthGraph, SquareDiagGraph, SquareGraph, Square3DGraph, SquareDirectedGraph, SquareFanoronaGraph, BaoGraph, SowingNoEndsGraph, wng, projectPoint, ptDistance, smallestDegreeDiff, normDeg, deg2rad, rad2deg, toggleFacing, calcBearing, matrixRectRot90, matrixRectRotN90, transposeRect, hexhexAi2Ap, hexhexAp2Ai, triAi2Ap, triAp2Ai, circle2poly, midpoint, distFromCircle, dir2deg, deg2dir };
13+
export { RectGrid, StackSet, reviver, replacer, sortingReplacer, shuffle, UserFacingError, HexTriGraph, SnubSquareGraph, SquareOrthGraph, SquareDiagGraph, SquareGraph, Square3DGraph, SquareDirectedGraph, SquareFanoronaGraph, BaoGraph, SowingNoEndsGraph, wng, projectPoint, ptDistance, smallestDegreeDiff, normDeg, deg2rad, rad2deg, toggleFacing, calcBearing, matrixRectRot90, matrixRectRotN90, transposeRect, hexhexAi2Ap, hexhexAp2Ai, triAi2Ap, triAp2Ai, circle2poly, midpoint, distFromCircle, dir2deg, deg2dir, rotateFacing };
1414

1515
export type DirectionCardinal = "N" | "E" | "S" | "W";
1616
export type DirectionDiagonal = "NE" | "SE" | "SW" | "NW";

src/common/plotting.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export const dir2deg = new Map<Direction, number>([
2424
["NW", 315],
2525
]);
2626

27+
// Delta is only parsed as a multiple of 45 degrees
28+
export const rotateFacing = (facing: Direction, delta: number): Direction => {
29+
delta = Math.floor(delta / 45) * 45;
30+
const newdeg = normDeg(dir2deg.get(facing)! + delta);
31+
return deg2dir.get(newdeg)!;
32+
}
33+
2734
/**
2835
* Ensures a degree measurement lies [0, 360)
2936
*/

src/games/pacru.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { GameBase, IAPGameState, IClickResult, IIndividualState, IScores, IStatu
22
import { APGamesInformation } from "../schemas/gameinfo";
33
import { APRenderRep, RowCol } from "@abstractplay/renderer/src/schemas/schema";
44
import { APMoveResult } from "../schemas/moveresults";
5-
import { deg2dir, dir2deg, Direction, normDeg, oppositeDirections, RectGrid, replacer, reviver, shuffle, smallestDegreeDiff, UserFacingError } from "../common";
5+
import { deg2dir, dir2deg, Direction, normDeg, oppositeDirections, RectGrid, replacer, reviver, rotateFacing, shuffle, smallestDegreeDiff, UserFacingError } from "../common";
66
import i18next from "i18next";
77
import { PacruGraph } from "./pacru/graph";
88
import { Glyph } from "@abstractplay/renderer/build";
@@ -1126,8 +1126,13 @@ export class PacruGame extends GameBase {
11261126
// orienting first
11271127
if (isOrienting) {
11281128
// add neighbouring cells
1129-
for (const cell of g.neighbours(from)) {
1130-
this.highlights.push(cell);
1129+
const {chevron} = this.board.get(from)!;
1130+
const dirs = [-90, -45, 45, 90].map(d => rotateFacing(chevron!.facing, d));
1131+
for (const dir of dirs) {
1132+
const ray = g.ray(from, dir);
1133+
if (ray.length > 0) {
1134+
this.highlights.push(ray[0]);
1135+
}
11311136
}
11321137
const [fx, fy] = g.algebraic2coords(from);
11331138
if (fx === 0) {

0 commit comments

Comments
 (0)