Esempio n. 1
0
 //constructor initialises the grid array
 public Level()
 {
     tiles = new int[gridSize, gridSize];
     for (int i = 0; i < gridSize; i++)
     {
         for (int j = 0; j < gridSize; j++)
         {
             tiles[i, j] = 0;
         }
     }
     aStar    = new AStar();
     dijkstra = new Dijkstra();
     scentMap = new ScentMap(40, 40);
 }
Esempio n. 2
0
        protected override void ChooseNextGridLocation(Map level, Player plr)
        {
            try
            {
                if (level.pathfinder.GetAlgorithm() != PathfinderAlgorithm.ScentMap)
                {
                    throw new Exception("Wrong bot used for pathfinding algorithm.");
                }

                // Get a copy of the scent map
                ScentMap map = (level.pathfinder as ScentMap);

                // Get neighbouring coordinates
                Coord2[] neighbours = GetNeighbours();

                Coord2 highest    = new Coord2(0, 0);
                bool   validFound = false;
                for (int i = 0; i < neighbours.Length; i++) // Ensures a valid position is initially selected
                {
                    if (level.ValidPosition(neighbours[i]))
                    {
                        highest    = neighbours[i];
                        validFound = true;
                        break;
                    }
                }

                if (validFound) // Only update if at least one neighbouring positon is in fact valid on the map
                {
                    // Find the highest neighbouring coorindate
                    for (int i = 0; i < neighbours.Length; i++)
                    {
                        if (level.ValidPosition(neighbours[i]))
                        {
                            if (map.Scents.data[neighbours[i].X, neighbours[i].Y] > map.Scents.data[highest.X, highest.Y])
                            {
                                highest = neighbours[i];
                            }
                        }
                    }

                    SetNextGridPosition(highest, level);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Bot Exception: " + e.Message);
            }
        }