예제 #1
0
        public void start(Board board, Agent agent, Territory start, Territory finish)
        {
            // must create a path from start territory to finish territory
            TerritoryList territories = board.Territories;

            OpenSet.Add(new StarTile(start.Name, start));

            Dictionary<string, int> sldMap = CalculateSLD(finish.Name);

            // loop through A* steps until goal is reached
            while (!IsGoalFound)
            {
                StarTile current = GetMinFValue();

                // there are no more members of the OpenSet to examine
                if(current == null)
                {
                    break;
                }

                // current territory is finish territory
                if(current.Id == finish.Name)
                {
                    // do something?
                }

                List<StarTile> frontier = GetFrontier(current);

                // loop through frontier and calculate heuristic for current territory
                foreach(StarTile t in frontier)
                {
                    // associate frontier territory to parent tile
                    t.Parent = current; // is this really necessary since we do it below?

                    // enemy territories are considered empty tiles, available to be conquered
                    if(t.Territory.Owner != current.Territory.Owner)
                    {
                        CalculateHeuristic(t, start, finish);

                        t.Parent = current;
                    }
                    
                    // goal territory is reached
                    else if(t.Territory.Name == finish.Name)
                    {
                        t.Parent = current;

                        IsGoalFound = true;

                        Path = ConstructPath(t);
                    }

                    // self owned territory, seen as obstacle because it is already
                    else if(t.Territory.Owner == current.Territory.Owner)
                    {
                        // do not need to calculate anything, just skip
                    }
                }
            }
        }
예제 #2
0
 public static void ApplyCardBonus(Agent agent, Board board)
 {
     if(agent.CanCashIn())
     {
         agent.ApplyCardBonus(board);
     }
 }
예제 #3
0
 public AStar(Board board)
 {
     OpenSet = new List<StarTile>();
     CloseSet = new List<StarTile>();
     IsGoalFound = false;
     Path = new List<string>();
     bfs = new BreadthFirstSearch(board);
 }
예제 #4
0
        public void ApplyCardBonus(Board board)
        {
            List<string> cards = CardsToCashIn();

            foreach (string card in cards)
            {
                this.cards.Remove(card);
            }

            board.UpdateCardBonus();
        }
예제 #5
0
        static void Main(string[] args)
        {
            finished = false;
            Agents = InitializeAgents(NUM_AGENTS, NUM_START_TROOPS);
            Board = InitializeBoard(TERRITORY_FILE_PATH, CONTINENT_FILE_PATH);

            DistributeTerritoriesToAgents(Agents, (Board)Board.Clone());
            UpdateBoard(Agents, Board);
            EquallyDistributeTroops(Agents);
            UpdateBoard(Agents, Board);

            BreadthFirstSearch bfs = new BreadthFirstSearch((Board)Board.Clone());

            bfs.Start("alaska");
            List<BfsTile> tiles = bfs.Tiles;
            foreach (BfsTile t in tiles)
            {
                Console.WriteLine(t.Id + " : " + t.Distance);
            }

            do
            {
                foreach (Agent a in Agents)
                {
                    // continent bonus 
                    Mechanics.ApplyContinentBonus(a, (Board)Board.Clone());

                    // cash in cards, if possible
                    Mechanics.ApplyCardBonus(a, Board); // not fully tested

                    // collect territory reinforcements
                    Mechanics.GetReinforcements(a);

                    // place reinforcements (no intelligent mechanism for now)
                    Mechanics.PlaceReinforcements(a);

                    // update territories on board
                    Mechanics.UpdateBoard(Agents, Board);
                    

                    // perform attacking

                    // tactical move

                    // end turn
                }
            } while (!finished);
        }
예제 #6
0
        private int CalculateContinentBonus(Board board)
        {
            int bonus = 0;
            foreach (Continent c in board.Continents)
            {
                // get all territories of a given continent
                var result = from Territory t in board.Territories where t.Continent == c.Name select board.Territories[t.Name];

                // get all controlled territories of the continent
                var cTerritories = from Territory t in board.Territories where (t.Continent == c.Name) && (t.Owner == Name) select board.Territories[t.Name];

                if (result.Count<Territory>() > 0 && cTerritories.Count<Territory>() > 0 && result.Count<Territory>() == cTerritories.Count<Territory>())
                {
                    bonus += c.Bonus;
                }
            }
            return bonus;
        }
예제 #7
0
 public void ApplyContinentBonus(Board board)
 {
     AvailableTroops += CalculateContinentBonus(board);
 }
예제 #8
0
 public static void ApplyContinentBonus(Agent agent, Board board)
 {
     agent.ApplyContinentBonus(board);
 }
예제 #9
0
        public static Board InitializeBoard(string territoryFilePath, string continentFilePath)
        {
            // instantiate board graph
            Board board = new Board(); 

            // read json data from file, create a territory, continent object for each member of json collection
            List<Territory> territories = JsonConvert.DeserializeObject<List<Territory>>(File.ReadAllText(territoryFilePath));
            List<Continent> continents = JsonConvert.DeserializeObject<List<Continent>>(File.ReadAllText(continentFilePath));

            // add territory object to board graph
            foreach (Territory t in territories)
            {
                board.AddNode(t);
            }

            foreach (Continent c in continents)
            {
                board.AddNode(c);
            }

            return board;
        }
예제 #10
0
 public static void UpdateBoard(List<Agent> agents, Board board)
 {
     foreach (Agent a in agents)
     {
         foreach (KeyValuePair<string, int> kvp in a.ControlledTerritories)
         {
             board.Territories[kvp.Key].UpdateOwner(a.Name, kvp.Value);
         }
     }
 }
예제 #11
0
 private static void DistributeTerritoriesToAgents(List<Agent> agents, Board board)
 {
     Mechanics.DistributeTerritories(agents, board.Territories, MAX_NUM_TERRITORIES);
 }
예제 #12
0
 private static void UpdateBoard(List<Agent> agents, Board board)
 {
     Mechanics.UpdateBoard(agents, board);
 }
예제 #13
0
 public BreadthFirstSearch(Board board)
 {
     Tiles = InitializeTiles(board.Territories);
     Queue = new Queue<BfsTile>();
 }