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; }
/** * 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); }
public void AddSubRegion(Region subRegion) { if (!subRegions.Contains(subRegion)) subRegions.Add(subRegion); }
/** * @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; }
/** * @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; }
public void AddNeighbor(Region neighbor) { if (!neighbors.Contains(neighbor)) { neighbors.Add(neighbor); neighbor.AddNeighbor(this); } }
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; }
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)); }
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)); }