public static void Solve(State state, bool debug) { State.OriginalUnpaintedCount = state.UnpaintedCount; state.Priority[state.Position] = 0; state.Board.BreadthFirstSearch( state.Position, (path) => { state.Priority[path.Point] = path.Depth; return(false); }); var moves = 0; while (state.UnpaintedCount > 0) { var planDebug = false; if (debug) { Console.WriteLine(); Console.WriteLine($"{moves} {state}"); //Console.WriteLine(state.Board); //planDebug = Console.ReadKey().KeyChar == 'x'; } var plan = Plan(state, planDebug && debug); moves += plan.Count; var planString = string.Join("", plan); Console.Write(planString); state = state.MultiMove(planString); } }
public void TestBoardInit() { var fileName = @"C:\Users\cashto\Documents\GitHub\icfp2019\problems\prob-003.desc"; var desc = File.ReadAllText(fileName); var state = new State(desc); state = state.MultiMove("DDDDDDDDDDDDDDDDD"); Console.WriteLine(state.Board.ToString(state.Position)); }
public void TestNotAllPainted() { var fileName = @"C:\Users\cashto\Documents\GitHub\icfp2019\problems\block-10.desc"; var desc = File.ReadAllText(fileName); var state = new State(desc); var moves = File.ReadAllText(@"C:\Users\cashto\Documents\GitHub\icfp2019\solutions\block-10.sol"); var endState = state.MultiMove(moves); Console.WriteLine(endState); }
public static List <string> PlanCImpl(State state, bool debug) { var ans = new List <string>(); var planA = PlanA(state, debug); if (planA != null) { ans.AddRange(planA); state = state.MultiMove(string.Join("", planA)); } var sections = new List <HashSet <Point> >(); foreach (var point in state.Board.AllPoints.Where(p => !state.Board.IsWall(p))) { if (!state.Board.IsPainted(point) && !sections.Any(section => section.Contains(point))) { var newSection = new HashSet <Point>() { point }; state.Board.BreadthFirstSearch(point, (path) => { newSection.Add(path.Point); return(false); }, (path) => state.Board.IsWall(path.Point) || state.Board.IsPainted(path.Point)); sections.Add(newSection); } } var smallestSection = sections .OrderBy(section => section.Count) .ThenBy(section => state.Position.Distance(section.First())) .FirstOrDefault(); if (sections.Count > 1) { var planB = PlanB(state, debug, (meta) => smallestSection.Contains(meta.State.Position)); if (planB != null) { ans.AddRange(planB); } } return(ans.Any() ? ans : null); }
public static List <string> PlanD(State state, bool debug) { var board = state.Board.Clone(); var ans = PlanB(state, debug, (meta) => !board.IsWall(meta.State.Position) && !board.IsPainted(meta.State.Position)); if (ans == null) { return(new List <string>() { "Z" }); } var newState = state.MultiMove(string.Join("", ans)); state.Board = board; if (state.Boosts.Contains(Board.Drill)) { var move = $"L"; var altState = state.MultiMove(move); var searchSucceeded = true; var altPath = PlanB(altState, debug, (meta) => { if (meta.Depth == ans.Count) { searchSucceeded = false; return(true); } return(meta.State.Position == newState.Position); }); if (altPath != null && searchSucceeded && altPath.Count + 10 < ans.Count) { ans = new List <string>() { move }; ans.AddRange(altPath); } } foreach (var tele in state.Teleports) { var move = $"T{tele}"; var altState = state.MultiMove(move); var searchSucceeded = true; var altPath = PlanB(altState, debug, (meta) => { if (meta.Depth == ans.Count) { searchSucceeded = false; return(true); } return(meta.State.Position == newState.Position); }); if (altPath != null && searchSucceeded && altPath.Count + 1 < ans.Count) { ans = new List <string>() { move }; ans.AddRange(altPath); } } return(ans); }