示例#1
0
 public List <Point> RunAStar(Point start, Point end)
 {
     return(Precomputer.GetPath(Level, start, end, false).ToList());
 }
示例#2
0
        // 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);
        }