Esempio n. 1
0
 // Constructor
 public AINodeData(int column, int row)
 {
     coordinate = new Haxxit.Maps.Point(column, row);
     isAvailable = false;
     hasSilicoin = false;
     hasData = false;
     isSpawn = false;
     occupiedBy = null;
     aStarTrackStatus = AStarStatus.Unlisted;
     parent = null;
     f = int.MaxValue;
     g = int.MaxValue;
     h = int.MaxValue;
 }
Esempio n. 2
0
        // Reassembles the Map data in a format that allows the AI easy access to program and node info
        private void GetMapData()
        {
            friendlyPrograms.Clear();
            enemyPrograms.Clear();
            mapData = new AINodeData[map.XSize, map.YSize]; // Instantiate the Map data grid
            for (int column = 0; column < map.XSize; column++)
            {
                for (int row = 0; row < map.YSize; row++)
                {
                    mapData[column, row] = new AINodeData(column, row); // Create an AINode for each grid location
                    Haxxit.Maps.MapNode checkNode = map.GetNode(column, row);

                    // Typechecking of nodes from original Haxxit.Maps class
                    Type checkType = checkNode.GetType();
                    if(checkType == typeof(Haxxit.Maps.UnavailableNode))
                    {
                        continue;
                    }
                    else if (checkType == typeof(Haxxit.Maps.ProgramTailNode))
                    {
                        while (true)
                        {
                            if (((Haxxit.Maps.ProgramNode)checkNode).Head != null)
                            {
                                checkNode = ((Haxxit.Maps.ProgramNode)checkNode).Head;
                            }
                            else
                            {
                                break;
                            }
                        }
                        mapData[column, row].OccupiedBy = (Haxxit.Maps.ProgramHeadNode)checkNode;
                    }
                    else if (checkType == typeof(Haxxit.Maps.ProgramHeadNode))
                    {
                        mapData[column, row].OccupiedBy = (Haxxit.Maps.ProgramHeadNode)checkNode;
                        if (((Haxxit.Maps.ProgramHeadNode)checkNode).Player == map.CurrentPlayer)
                        {
                            friendlyPrograms.Add((Haxxit.Maps.ProgramHeadNode)checkNode);
                        }
                        else
                        {
                            enemyPrograms.Add((Haxxit.Maps.ProgramHeadNode)checkNode);
                        }
                    }
                    else if (checkType == typeof(Haxxit.Maps.SpawnNode))
                    {
                        mapData[column, row].IsSpawn = true;
                    }
                    else if (checkType == typeof(Haxxit.Maps.SilicoinNode))
                    {
                        mapData[column, row].HasSilicoin = true;
                    }
                    else if (checkType == typeof(Haxxit.Maps.DataNode))
                    {
                        mapData[column, row].HasData = true;
                    }
                    else // Nothing else on the node, so it must be available
                    {
                        mapData[column, row].IsAvailable = true;
                    }
                }
            }
        }
Esempio n. 3
0
 // Non-recursive helper function for AStar algorithm.  Implemented to prevent code duplication for each direction above.
 private void AStarHelp(AINodeData currentNode, AINodeData checkNode, List<AINodeData> openList, List<AINodeData> closeList, Haxxit.Maps.ProgramHeadNode program, Haxxit.Maps.Point destination)
 {
     AINodeData.AStarStatus checkNodeStatus = checkNode.AStarTrackStatus;
     if (checkNodeStatus != AINodeData.AStarStatus.Closed && checkNode.canHoldCurrentProgram(program))
     {
         if (checkNodeStatus == AINodeData.AStarStatus.Unlisted)
         {
             openList.Add(checkNode);
             checkNode.Parent = currentNode;
             checkNode.AStarTrackStatus = AINodeData.AStarStatus.Open;
             checkNode.G = currentNode.G + 1;
             checkNode.H = Math.Abs(destination.X - checkNode.Coordinate.X) + Math.Abs(destination.Y - checkNode.Coordinate.Y);
             checkNode.F = checkNode.G + checkNode.H;
         }
         else
         {
             int checkG = currentNode.G + 1;
             if (checkG < checkNode.G)
             {
                 checkNode.Parent = currentNode;
                 checkNode.G = checkG;
                 checkNode.F = checkNode.G + checkNode.H;
             }
         }
     }
 }