struct GridPosition: Hashable, Equatable, Codable {
    let x: Int
    let y: Int

    func offset(by direction: Direction) -> GridPosition {
        switch direction {
        case .up:    return GridPosition(x: x, y: y - 1)
        case .down:  return GridPosition(x: x, y: y + 1)
        case .left:  return GridPosition(x: x - 1, y: y)
        case .right: return GridPosition(x: x + 1, y: y)
        }
    }
}
