Skip to content

Commit 4ff2b2f

Browse files
committed
chore: get grid symbol using aoc getCoordinateSymbol
1 parent 8e32f5a commit 4ff2b2f

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/2024/2024-12-14/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Visit the Advent of Code website for more information on this puzzle at:
1616
**Board** class
1717

1818
- Manages the `Grid`-like 2D string array, methods, and properties in which robots run
19-
- **`getTileValue()`** - Returns the value of the number or character in the `point` coordinate, or `undefined` if the `point` coordinate is out of the grid bounds
2019
- **`setTileValue()`** - Sets the string value in the 2D `this.grid[][]` array
2120
- **`setRobot()`** - Sets a new robot into the `Board`'s robots list and marks its position in `this.grid[][]` array
2221
- **`moveRobot()`** - Moves a robot from a tile and updates the current and new tile's robot count

src/2024/2024-12-14/lib/board.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { GridDimensions } from '@/aoc/grid/types.js'
2-
import { isOutOfBounds, printGrid } from '@/aoc/grid/utils.js'
32
import type { Point } from '@/aoc/point/types.js'
43
import type { Quadrant, RobotProperty } from './types.js'
4+
55
import { arrayMiddleIndex } from '@/aoc/array/utils.js'
6+
import { getCoordinateSymbol, isOutOfBounds, printGrid } from '@/aoc/grid/utils.js'
67

78
/**
89
* @class Board
@@ -24,6 +25,7 @@ export class Board {
2425
/** List (array) of robots coordinate and velocity data */
2526
robots: RobotProperty[] = []
2627

28+
/** Start and end coordinates of `this.grid` 4 main quadrants */
2729
quadrants: Quadrant[] = []
2830

2931
/**
@@ -40,17 +42,6 @@ export class Board {
4042
this.quadrants = this.findQuadrants()
4143
}
4244

43-
/**
44-
* Returns the value of the number or character in the `point` coordinate, or
45-
* `undefined` if the `point` coordinate is out of the grid bounds
46-
* @param {Point} point - Object containing (y,x) point coordinate
47-
* @returns {string | undefined} Value of the number or character
48-
*/
49-
getTileValue (point: Point): string | undefined {
50-
if (isOutOfBounds(point, this.settings)) return
51-
return this.grid[point.y]![point.x]
52-
}
53-
5445
/**
5546
* Sets the string value in the 2D `this.grid[][]` array
5647
* @param {Point} point - Object containing (y,x) point coordinate
@@ -69,7 +60,7 @@ export class Board {
6960
*/
7061
setRobot (robotData: RobotProperty): void | undefined {
7162
const { x, y } = robotData
72-
const tileValue = this.getTileValue(robotData)
63+
const tileValue = getCoordinateSymbol({ x, y }, this.grid)?.symbol
7364

7465
if (!tileValue) return
7566

@@ -91,8 +82,8 @@ export class Board {
9182
if (robotIndex < 0 || robotIndex > this.robots.length) return
9283

9384
const robotData = this.robots[robotIndex] as RobotProperty
94-
const currentTileValue = this.getTileValue(robotData)
95-
const newPositionTileValue = this.getTileValue(point)
85+
const currentTileValue = getCoordinateSymbol(robotData, this.grid)?.symbol
86+
const newPositionTileValue = getCoordinateSymbol(robotData, this.grid)?.symbol
9687

9788
if (!currentTileValue || !newPositionTileValue) return
9889

0 commit comments

Comments
 (0)