Add solution for "Day 15: Warehouse Woes", part 2
This commit is contained in:
37
include/aoc/WarehouseBoxPusher.hpp
Normal file
37
include/aoc/WarehouseBoxPusher.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2025 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 <string>
|
||||
#include <vector>
|
||||
|
||||
#include <aoc/Lines.hpp>
|
||||
#include <aoc/Point2.hpp>
|
||||
|
||||
class WarehouseBoxPusher
|
||||
{
|
||||
public:
|
||||
WarehouseBoxPusher(const char boxChar, const char wallChar, const char emptyChar);
|
||||
virtual ~WarehouseBoxPusher(){};
|
||||
virtual void processMovements(Lines& warehouseMap, const std::string& line);
|
||||
virtual void processMovement(Lines& warehouseMap, const Point2& direction);
|
||||
void setRobotPosition(const Point2& robotPosition);
|
||||
protected:
|
||||
Point2 robotPosition_;
|
||||
const char boxChar_;
|
||||
const char wallChar_;
|
||||
const char emptyChar_;
|
||||
};
|
||||
30
include/aoc/WarehouseWideBoxPusher.hpp
Normal file
30
include/aoc/WarehouseWideBoxPusher.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// Solutions to the Advent Of Code 2024.
|
||||
// Copyright (C) 2025 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 <aoc/WarehouseBoxPusher.hpp>
|
||||
|
||||
class WarehouseWideBoxPusher
|
||||
: public WarehouseBoxPusher
|
||||
{
|
||||
public:
|
||||
WarehouseWideBoxPusher(const char leftWideBoxChar, const char rightWideBoxChar, const char wallChar,
|
||||
const char emptyChar);
|
||||
virtual void processMovement(Lines& warehouseMap, const Point2& direction) override;
|
||||
protected:
|
||||
const char leftWideBoxChar_;
|
||||
const char rightWideBoxChar_;
|
||||
};
|
||||
@@ -15,7 +15,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <aoc/Lines.hpp>
|
||||
#include <aoc/LinesSolver.hpp>
|
||||
#include <aoc/WarehouseBoxPusher.hpp>
|
||||
#include <aoc/WarehouseWideBoxPusher.hpp>
|
||||
|
||||
class WarehouseWoes
|
||||
: public LinesSolver
|
||||
@@ -28,11 +31,18 @@ class WarehouseWoes
|
||||
virtual void finish() override;
|
||||
private:
|
||||
bool isProcessingMap_;
|
||||
Point2 robotPosition_;
|
||||
bool isSearchingStartPosition_;
|
||||
Lines lines2_;
|
||||
WarehouseBoxPusher warehouseBoxPusher1_;
|
||||
WarehouseWideBoxPusher warehouseBoxPusher2_;
|
||||
static constexpr char getRobotChar();
|
||||
static constexpr char getBoxChar();
|
||||
static constexpr char getLeftWideBoxChar();
|
||||
static constexpr char getRightWideBoxChar();
|
||||
static constexpr char getWallChar();
|
||||
static constexpr char getEmptyChar();
|
||||
void processDirections(const std::string& line);
|
||||
int calcGpsCoordinate(const size_t x, const size_t y);
|
||||
void checkStartingPosition(const std::string& line);
|
||||
void addWarehouseMap2Line(const std::string& line);
|
||||
long long int calcAllGpsCoordinates(Lines& warehouseMap, const char boxChar);
|
||||
long long int calcGpsCoordinate(const size_t x, const size_t y);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user