Skip to content

Commit

Permalink
Pacru: Fix orientation highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
Perlkonig committed Feb 12, 2025
1 parent 9e53809 commit 141205f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { shuffle } from "./shuffle";
import { UserFacingError } from "./errors";
import { HexTriGraph, SnubSquareGraph, SquareOrthGraph, SquareDiagGraph, SquareGraph, Square3DGraph, SquareDirectedGraph, SquareFanoronaGraph, BaoGraph, SowingNoEndsGraph } from "./graphs";
import { wng } from "./namegenerator";
import { projectPoint, ptDistance, smallestDegreeDiff, normDeg, deg2rad, rad2deg, toggleFacing, calcBearing, matrixRectRot90, matrixRectRotN90, transposeRect, circle2poly, midpoint, distFromCircle, deg2dir, dir2deg } from "./plotting";
import { projectPoint, ptDistance, smallestDegreeDiff, normDeg, deg2rad, rad2deg, toggleFacing, calcBearing, matrixRectRot90, matrixRectRotN90, transposeRect, circle2poly, midpoint, distFromCircle, deg2dir, dir2deg, rotateFacing } from "./plotting";
import { hexhexAi2Ap, hexhexAp2Ai, triAi2Ap, triAp2Ai } from "./aiai";
import stringify from "json-stringify-deterministic";
import fnv from "fnv-plus";

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 };
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 };

export type DirectionCardinal = "N" | "E" | "S" | "W";
export type DirectionDiagonal = "NE" | "SE" | "SW" | "NW";
Expand Down
7 changes: 7 additions & 0 deletions src/common/plotting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export const dir2deg = new Map<Direction, number>([
["NW", 315],
]);

// Delta is only parsed as a multiple of 45 degrees
export const rotateFacing = (facing: Direction, delta: number): Direction => {
delta = Math.floor(delta / 45) * 45;
const newdeg = normDeg(dir2deg.get(facing)! + delta);
return deg2dir.get(newdeg)!;
}

/**
* Ensures a degree measurement lies [0, 360)
*/
Expand Down
11 changes: 8 additions & 3 deletions src/games/pacru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GameBase, IAPGameState, IClickResult, IIndividualState, IScores, IStatu
import { APGamesInformation } from "../schemas/gameinfo";
import { APRenderRep, RowCol } from "@abstractplay/renderer/src/schemas/schema";
import { APMoveResult } from "../schemas/moveresults";
import { deg2dir, dir2deg, Direction, normDeg, oppositeDirections, RectGrid, replacer, reviver, shuffle, smallestDegreeDiff, UserFacingError } from "../common";
import { deg2dir, dir2deg, Direction, normDeg, oppositeDirections, RectGrid, replacer, reviver, rotateFacing, shuffle, smallestDegreeDiff, UserFacingError } from "../common";
import i18next from "i18next";
import { PacruGraph } from "./pacru/graph";
import { Glyph } from "@abstractplay/renderer/build";
Expand Down Expand Up @@ -1126,8 +1126,13 @@ export class PacruGame extends GameBase {
// orienting first
if (isOrienting) {
// add neighbouring cells
for (const cell of g.neighbours(from)) {
this.highlights.push(cell);
const {chevron} = this.board.get(from)!;
const dirs = [-90, -45, 45, 90].map(d => rotateFacing(chevron!.facing, d));
for (const dir of dirs) {
const ray = g.ray(from, dir);
if (ray.length > 0) {
this.highlights.push(ray[0]);
}
}
const [fx, fy] = g.algebraic2coords(from);
if (fx === 0) {
Expand Down

0 comments on commit 141205f

Please sign in to comment.