#include "factory/core/pathfinder.h"
#include "factory/core/puzzles.h"
#include "factory/core/simulation.h"
#include <cassert>
#include <iostream>
int main() {
  const auto project = factory::makePuzzle(0, true);
  const auto path = factory::findPath(project, {1, 3}, {14, 3});
  auto detour = project;
  detour.setTile({7, 3}, factory::Tile::Wall);
  for (int x = 6; x <= 8; ++x)
    detour.setTile({x, 2}, factory::Tile::Road);
  const auto longer = factory::findPath(detour, {1, 3}, {14, 3});
  assert(longer.size() > path.size());
  factory::Simulation slower(detour);
  while (slower.snapshot().outcome == factory::Outcome::Running)
    slower.step();
  assert(slower.snapshot().outcome == factory::Outcome::Won);
  for (const auto neighbor : detour.neighbors({14, 3}))
    detour.setTile(neighbor, factory::Tile::Wall);
  assert(factory::findPath(detour, {1, 3}, {14, 3}).empty());
  factory::Simulation simulation(project);
  while (simulation.snapshot().outcome == factory::Outcome::Running)
    simulation.step();
  assert(slower.snapshot().tick > simulation.snapshot().tick);
  std::cout << "path_cells=" << path.size() << '\n';
  std::cout << "delivered=" << simulation.snapshot().delivered << '\n';
  std::cout << "outcome="
            << (simulation.snapshot().outcome == factory::Outcome::Won ? "won"
                                                                       : "lost")
            << '\n';
}
