Add day 6, part 2 WIP
This commit is contained in:
25
include/aoc/GridPathData.hpp
Normal file
25
include/aoc/GridPathData.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2024 Stefan Müller
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it under
|
||||
// the terms of the GNU General Public License as published by the Free Software
|
||||
// Foundation, either version 3 of the License, or (at your option) any later
|
||||
// version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
|
||||
class GridPathData
|
||||
{
|
||||
public:
|
||||
bool isVisited{ false };
|
||||
std::bitset<4> isLoopingInDirection{ 0 };
|
||||
};
|
||||
@@ -15,7 +15,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <aoc/Grid.hpp>
|
||||
#include <aoc/GridPathData.hpp>
|
||||
#include <aoc/LinesSolver.hpp>
|
||||
#include <aoc/Point2.hpp>
|
||||
|
||||
class GuardGallivant
|
||||
: public LinesSolver
|
||||
@@ -29,8 +34,12 @@ class GuardGallivant
|
||||
Point2 start_{};
|
||||
const size_t getStartDirectionIndex() const;
|
||||
const char getStartChar() const;
|
||||
const char getVisitedChar() const;
|
||||
const char getObstructionChar() const;
|
||||
void visitPosition(const Point2& current);
|
||||
size_t turnDirection(const size_t current) const;
|
||||
void tracePath();
|
||||
void visitPosition(const Point2& current, const size_t directionIndex, Grid<GridPathData>& pathGrid);
|
||||
void backtracePath(const Point2& current, const size_t directionIndex, Grid<GridPathData>& pathGrid);
|
||||
void backtraceTurn(const Point2& current, const size_t reverseTurnDirectionIndex, Grid<GridPathData>& pathGrid);
|
||||
size_t turnDirectionRight(const size_t currentDirectionIndex) const;
|
||||
size_t turnDirectionLeft(const size_t currentDirectionIndex) const;
|
||||
size_t revertDirection(const size_t currentDirectionIndex) const;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
class Point2
|
||||
{
|
||||
public:
|
||||
@@ -42,3 +44,5 @@ class Point2
|
||||
Point2& operator-=(const Point2& rhs);
|
||||
Point2& operator*=(const int rhs);
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Point2& rhs);
|
||||
|
||||
Reference in New Issue
Block a user