コード例 #1
0
 public AttackTransferMove(String playerName, Region fromRegion, Region toRegion, int armies, int priority)
 {
     base.PlayerName = playerName;
     this.fromRegion = fromRegion;
     this.toRegion = toRegion;
     this.armies = armies;
     this.priority = priority;
     this.locked = false;
 }
コード例 #2
0
ファイル: Map.cs プロジェクト: psenough/warlight_ai_challenge
 /**
  * Add a Region to the map
  * @param region : Region to be Added
  */
 public void Add(Region region)
 {
     foreach (Region r in regions)
         if (r.Id == region.Id)
         {
             Console.Error.WriteLine("Region cannot be Added: id already exists.");
             return;
         }
     regions.Add(region);
 }
コード例 #3
0
 public void AddSubRegion(Region subRegion)
 {
     if (!subRegions.Contains(subRegion))
         subRegions.Add(subRegion);
 }
コード例 #4
0
ファイル: Map.cs プロジェクト: psenough/warlight_ai_challenge
 /**
  * @return : a new Map object exactly the same as this one
  */
 public Map GetMapCopy()
 {
     Map newMap = new Map();
     foreach (SuperRegion sr in superRegions) //copy superRegions
     {
         SuperRegion newSuperRegion = new SuperRegion(sr.Id, sr.ArmiesReward);
         newMap.Add(newSuperRegion);
     }
     foreach (Region r in regions) //copy regions
     {
         try
         {
             Region newRegion = new Region(r.Id, newMap.GetSuperRegion(r.SuperRegion.Id), r.PlayerName, r.Armies);
             newMap.Add(newRegion);
         }
         catch (Exception exc) {
             Console.Error.WriteLine(exc.Message);
             Console.Error.WriteLine("couldn't copy region");
             Console.Error.WriteLine("id: " + r.Id);
             Console.Error.WriteLine("parent: " + r.SuperRegion.Id);
             Console.Error.WriteLine("playername: " + r.PlayerName);
             Console.Error.WriteLine("armies: " + r.Armies);
         }
     }
     foreach (Region r in regions) //Add neighbors to copied regions
     {
         Region newRegion = newMap.GetRegion(r.Id);
         foreach (Region neighbor in r.Neighbors)
             newRegion.AddNeighbor(newMap.GetRegion(neighbor.Id));
     }
     return newMap;
 }
コード例 #5
0
 /**
  * @param region a Region object
  * @return True if this Region is a neighbor of given Region, false otherwise
  */
 public bool IsNeighbor(Region region)
 {
     if (neighbors.Contains(region))
         return true;
     return false;
 }
コード例 #6
0
 public void AddNeighbor(Region neighbor)
 {
     if (!neighbors.Contains(neighbor))
     {
         neighbors.Add(neighbor);
         neighbor.AddNeighbor(this);
     }
 }
コード例 #7
0
        public int ScheduleNeutralAttack(Region attacker, Region target, int armiesAvailable)
        {
            int usedArmies = 0;

            // validate our inputs
            if (!attacker.OwnedByPlayer(MyPlayerName) || target.OwnedByPlayer("unknown") || target.OwnedByPlayer(MyPlayerName) || armiesAvailable < 0)
            {
                // there must have been an error somewhere on the algo
                Console.Error.WriteLine("trying to schedule a neutral attack with invalid inputs (on round " + RoundNumber + ")");
                return 0;
            }

            // armies needed to attack neutral
            int neededToAttack = target.Armies * 2;
            int neededToDeploy = neededToAttack - attacker.Armies - attacker.PledgedArmies + attacker.ReservedArmies + 1;

            if (neededToDeploy > armiesAvailable + 1) {
                // there must have been an error somewhere on the algo
                Console.Error.WriteLine("trying to schedule a neutral attack without enough armies to carry it through (on round " + RoundNumber + ")");
                return 0;
            }

            if (neededToDeploy < 0)
            {
                neededToDeploy = 0;
            }

            attacker.PledgedArmies += neededToDeploy;
            usedArmies += neededToDeploy;

            attacker.ReservedArmies += neededToAttack;
            scheduledAttack.Add(new Tuple<int, int ,int>(attacker.Id, target.Id, neededToAttack));

            attackedOneNeutral = true;

            return usedArmies;
        }
コード例 #8
0
        public void ScheduleFullAttack(Region attacker, Region target, int armiesDeployed)
        {
            // validate our inputs
            if (!attacker.OwnedByPlayer(MyPlayerName) || target.OwnedByPlayer("unknown") || target.OwnedByPlayer(MyPlayerName))
            {
                // there must have been an error somewhere on the algo
                Console.Error.WriteLine("trying to schedule a full attack with invalid inputs (on round " + RoundNumber + ")");
                return;
            }

            // count total armies available
            int totalArmies = attacker.Armies + attacker.PledgedArmies - attacker.ReservedArmies + armiesDeployed - 1;

            attacker.PledgedArmies += armiesDeployed;

            attacker.ReservedArmies += totalArmies;
            scheduledAttack.Add(new Tuple<int, int, int>(attacker.Id, target.Id, totalArmies));
        }
コード例 #9
0
        public void ScheduleAttack(Region attacker, Region target, int deployArmies, int attackArmies)
        {
            // validate our inputs
            if (!attacker.OwnedByPlayer(MyPlayerName) || target.OwnedByPlayer("unknown") || target.OwnedByPlayer(MyPlayerName))
            {
                // there must have been an error somewhere on the algo
                Console.Error.WriteLine("trying to schedule an attack with invalid inputs (on round " + RoundNumber + ")");
                return;
            }

            attacker.PledgedArmies += deployArmies;

            attacker.ReservedArmies += attackArmies;
            scheduledAttack.Add(new Tuple<int, int, int>(attacker.Id, target.Id, attackArmies));
        }