private void CreateAllPossibleMoves() { if (allPossible != null) { return; } var all = new List <AgentCommand>(); Direction[] directions = new Direction[4] { Direction.N, Direction.E, Direction.S, Direction.W }; foreach (Direction d in directions) { all.Add(AgentCommand.CreateMove(d)); foreach (Direction d2 in directions) { if (d == d2) { all.Add(AgentCommand.CreatePush(d, d2)); } else if (d2.Opposite() == d) { all.Add(AgentCommand.CreatePull(d, d2)); } else { all.Add(AgentCommand.CreatePull(d, d2)); all.Add(AgentCommand.CreatePush(d, d2)); } } } allPossible = all; }
internal static List <AgentCommand> RightHandBoxSwimming(Direction d) { return(new List <AgentCommand>() { AgentCommand.CreateMove(Opposite(d)), AgentCommand.CreatePull(d, Clockwise(d)), AgentCommand.CreatePush(Clockwise(d), Opposite(d)), AgentCommand.CreatePull(CounterClockwise(d), d), AgentCommand.CreatePush(d, Clockwise(d)) }); }
private void MoveToLocation(List <Point> path, List <AgentCommand> commands, int agentIndex) { for (int i = 0; i < path.Count - 1; ++i) { Point agentPos = path[i]; Point nextAgentPos = path[i + 1]; Direction agentDir = PointsToDirection(agentPos, nextAgentPos); commands.Add(AgentCommand.CreateMove(agentDir)); MoveAgent(nextAgentPos, agentIndex); } }
// GOD FUNCTION TROIS public List <AgentCommands> Solve() { List <AgentCommand> solution = new List <AgentCommand>(); State currentState = Level.InitialState; foreach (Entity e in currentState.Entities) { if (e.Color != Agent.Color) { Level.AddPermanentWalll(e.Pos); } } Point[] meisterPath = Precomputer.GetPath(Level, Agent.Pos, End, false); Point freeSpot = meisterPath[1]; foreach (Point nextPoint in meisterPath) { if (nextPoint == meisterPath.First()) { continue; } Direction nextDir = LessNaiveSolver.PointsToDirection(Agent.Pos, nextPoint); Direction freeSpotDir = LessNaiveSolver.PointsToDirection(Agent.Pos, freeSpot); if (nextDir == freeSpotDir) { solution.Add(AgentCommand.CreateMove(nextDir)); freeSpot = Agent.Pos; Agent = Agent.Move(nextPoint); continue; } else if (BoxSwimming.Opposite(nextDir) == freeSpotDir) { if (BoxSwimming.CanLeftHandBoxSwim(nextDir, Agent.Pos, Level)) { solution.AddRange(BoxSwimming.LeftHandBoxSwimming(nextDir)); } else if (BoxSwimming.CanRightHandBoxSwim(nextDir, Agent.Pos, Level)) { solution.AddRange(BoxSwimming.RightHandBoxSwimming(nextDir)); } else { throw new Exception("Box swimming operations failed."); } freeSpot = Agent.Pos; Agent = Agent.Move(nextPoint); continue; } else if (BoxSwimming.CounterClockwise(nextDir) == freeSpotDir) { if (BoxSwimming.CanLeftHandBoxSwim(nextDir, Agent.Pos, Level)) { solution.AddRange(BoxSwimming.SwimLeft(BoxSwimming.Opposite(freeSpotDir))); } else { throw new Exception("Box swimming operations failed."); } freeSpot = Agent.Pos; Agent = Agent.Move(nextPoint); continue; } else if (BoxSwimming.Clockwise(nextDir) == freeSpotDir) { if (BoxSwimming.CanRightHandBoxSwim(nextDir, Agent.Pos, Level)) { solution.AddRange(BoxSwimming.SwimRight(BoxSwimming.Opposite(freeSpotDir))); } else { throw new Exception("Box swimming operations failed."); } //{ // He's got gotten! //solution.Add(AgentCommand.CreateMove(freeSpotDir)); //solution.Add(AgentCommand.CreatePull) // Considering that FORWARD right NOW is the opposite of freeSpot /* Move into freeSpot * Pull left-back box into free spot * Push left-box into left-back * Move nextDir * if agent isn't at nextPoint, then L/R BoxSwim in nextDir */ //} freeSpot = Agent.Pos; Agent = Agent.Move(nextPoint); continue; } else { break; } } EndSolution = new List <AgentCommands>() { new AgentCommands(solution, 0) }; return(EndSolution); }