/// <param name="income">We can pass a null PlayerIncome class, but none of the methods on this class should be called until one is supplied via SupplyIncome</param> public PlayerIncomeTracker(PlayerIncome income, MapDetails map) { _income = income; _map = map; _armiesUsedOnBonuses = new Dictionary <BonusIDType, int>(); _freeArmiesUsedOn = new Dictionary <TerritoryIDType, int>(); }
public BonusDetails(MapDetails parent, BonusIDType id, int armiesReward) { this.Parent = parent; this.ID = id; this.Amount = armiesReward; this.Territories = new List <TerritoryIDType>(); }
public TerritoryDetails(MapDetails parent, TerritoryIDType id) { this.Parent = parent; this.ID = id; this.PartOfBonuses = new HashSet <BonusIDType>(); this.ConnectedTo = new Dictionary <TerritoryIDType, object>(); }
public static MapDetails ReadMap(JToken mapNode) { var map = new MapDetails(); map.ID = (MapIDType)(int)mapNode["id"]; map.Name = (string)mapNode["name"]; foreach (var terrNode in (JArray)mapNode["territories"]) { var td = new TerritoryDetails(map, (TerritoryIDType)(int)terrNode["id"]); td.Name = (string)terrNode["name"]; td.ConnectedTo = terrNode["connectedTo"].As <JArray>().Select(o => (TerritoryIDType)(int)o).ToDictionary(o => o, o => (object)null); map.Territories.Add(td.ID, td); } foreach (var bonusNode in (JArray)mapNode["bonuses"]) { var bd = new BonusDetails(map, (BonusIDType)(int)bonusNode["id"], (int)bonusNode["value"]); bd.Name = (string)bonusNode["name"]; bd.Territories = bonusNode["territoryIDs"].As <JArray>().Select(o => (TerritoryIDType)(int)o).ToList(); map.Bonuses.Add(bd.ID, bd); foreach (var terrID in bd.Territories) { map.Territories[terrID].PartOfBonuses.Add(bd.ID); } } foreach (var distNode in (JArray)mapNode["distributionModes"]) { var d = new DistributionMode(); d.ID = (DistributionIDType)(int)distNode["id"]; d.Name = (string)distNode["name"]; d.Type = (string)distNode["type"]; if (distNode["territories"] != null) { d.Territories = distNode["territories"].Cast <JProperty>().ToDictionary(o => (TerritoryIDType)int.Parse(o.Name), o => (ushort)(int)o.Value); } map.DistributionModes.Add(d.ID, d); } return(map); }
/* * Bot1: setup_map super_regions 1 5 2 4 3 1 4 3 5 4 6 3 7 3 8 2 9 3 10 3 11 6 12 5 13 4 * Bot1: setup_map regions 1 1 2 1 3 1 4 1 5 1 6 2 7 2 8 2 9 2 10 3 11 3 12 3 13 3 14 4 15 4 16 4 17 4 18 4 19 4 20 5 21 5 22 5 23 5 24 6 25 6 26 6 27 6 28 7 29 7 30 7 31 7 32 7 33 8 34 8 35 8 36 8 37 9 38 9 39 9 40 9 41 10 42 10 43 10 44 10 45 10 46 10 47 11 48 11 49 11 50 11 51 11 52 11 53 11 54 12 55 12 56 12 57 12 58 12 59 13 60 13 61 13 62 13 63 13 64 13 * Bot1: setup_map neighbors 1 3,2,6 2 3,5,4,8,6 3 4 4 24,5,25 5 24,20,7,8 6 8,7 7 9,8,20 9 20,21 10 11,12 11 12,13 12 13,29 13 29,28 14 15 15 18,28,16 16 17,18 17 18,33,19 18 33,28,34,29,30 19 33 20 21,22,24,26,23 21 23 22 26,23,38,24,59 24 26,27,25,38 25 27 27 37 28 30,29 29 31,30,34,32 31 48,32,51 32 34 33 35,34 34 36,35 35 36 37 38,39,40 38 40,55,60 39 54,40,49 40 55,54,56 41 44,42,46,62 42 44,43,45 43 45 44 61,62,45 45 59,61 46 62 47 48,50 48 51,50 49 50,56,54 50 56,51,52,53 51 52 52 53 53 56,58 54 56 55 57,56 56 58,57 57 58 59 61,63,64,60 60 63 61 62,64 62 64 63 64 * Bot1: setup_map wastelands 5 13 40 49 62 */ private static void SetupMap(string[] mapInput) { if (Map == null) { Map = new MapDetails(); } if (mapInput[1] == "super_regions") { for (var i = 2; i < mapInput.Length; i++) { var bonusID = (BonusIDType)int.Parse(mapInput[i]); i++; var reward = int.Parse(mapInput[i]); Map.Bonuses.Add(bonusID, new BonusDetails(Map, bonusID, reward)); } } else if (mapInput[1] == "regions") { for (var i = 2; i < mapInput.Length; i++) { var terrID = (TerritoryIDType)int.Parse(mapInput[i]); i++; var bonusID = (BonusIDType)int.Parse(mapInput[i]); Map.Territories.Add(terrID, new TerritoryDetails(Map, terrID)); Map.Bonuses[bonusID].Territories.Add(terrID); Map.Territories[terrID].PartOfBonuses.Add(bonusID); } } else if (mapInput[1] == "neighbors") { for (var i = 2; i < mapInput.Length; i++) { var terrID = (TerritoryIDType)int.Parse(mapInput[i++]); var terr = Map.Territories[terrID]; mapInput[i].Split(',').Select(o => (TerritoryIDType)int.Parse(o)).ForEach(o => terr.ConnectedTo.Add(o, null)); foreach (var conn in terr.ConnectedTo.Keys) { Map.Territories[conn].ConnectedTo[terrID] = null; } } //Map is now done being read DistributionStanding = new GameStanding(); foreach (var terr in Map.Territories.Values) { DistributionStanding.Territories.Add(terr.ID, TerritoryStanding.Create(terr.ID, TerritoryStanding.NeutralPlayerID, new Armies(2))); } } else if (mapInput[1] == "wastelands") { foreach (var terrID in mapInput.Skip(2).Select(o => (TerritoryIDType)int.Parse(o)).ToList()) { DistributionStanding.Territories[terrID].NumArmies = new Armies(6); } } else if (mapInput[1] == "opponent_starting_regions") { /* don't care */ } else { throw new Exception("Unexpected map input: " + mapInput[1]); } }
public static bool PlayGame(string botName, GameObject game, PlayerIDType playerID, GameSettings settings, MapDetails map, Action <List <TerritoryIDType> > sendPicks, Action <List <GameOrder> > sendOrders) { if (game.State == GameState.WaitingForPlayers) { return(true); } if (!game.Players.ContainsKey(playerID)) { return(false); //not in game } if (game.Players[playerID].State == GamePlayerState.Invited) { throw new NotImplementedException("TODO: Accept the invite"); } if (game.Players[playerID].State != GamePlayerState.Playing) { return(false); //not alive anymore } var bot = BotFactory.Construct(botName); bot.Init(game.ID, playerID, game.Players, map, game.LatestInfo.DistributionStanding, settings, game.NumberOfTurns, game.LatestInfo.Income, game.LatestInfo.LatestTurn == null ? null : game.LatestInfo.LatestTurn.Orders, game.LatestInfo.LatestStanding, game.LatestInfo.PreviousTurnStanding, game.LatestInfo.TeammatesOrders, game.LatestInfo.Cards, game.LatestInfo.CardsMustUse, Stopwatch.StartNew(), new List <string>()); AILog.Log("PlayGame", "State=" + game.State + ", numTurns=" + game.NumberOfTurns + ", income=" + game.LatestInfo.Income[playerID] + ", cardsMustUse=" + game.LatestInfo.CardsMustUse); if (game.State == GameState.DistributingTerritories) { sendPicks(_speeds.GetOrAdd(botName, _ => new Speeds()).Record(true, () => bot.GetPicks())); } else if (game.State == GameState.Playing) { sendOrders(_speeds.GetOrAdd(botName, _ => new Speeds()).Record(false, () => bot.GetOrders())); } return(true); }