示例#1
0
        public static void PlayLoop(string botName, GameIDType gameID, PlayerIDType playerID)
        {
            var settings = HumanGameAPI.GetGameSettings(gameID);

            int  turnNumber    = int.MinValue;
            bool checkedAccept = false;

            while (true)
            {
                var status = HumanGameAPI.GetGameStatus(gameID);
                if (status.Item2 == GameState.WaitingForPlayers)
                {
                    if (!checkedAccept)
                    {
                        var game = HumanGameAPI.GetGameInfo(gameID, null);
                        if (game.Players[playerID].State == GamePlayerState.Invited)
                        {
                            AILog.Log("PlayHuman", "Accepting invite...");
                            HumanGameAPI.AcceptGame(gameID);
                            AILog.Log("PlayHuman", "Accepted invite");
                        }

                        checkedAccept = true;
                    }
                }
                else if (status.Item2 == GameState.Finished)
                {
                    AILog.Log("PlayHuman", "Game finished");
                    break;
                }
                else if (status.Item1 > turnNumber)
                {
                    var game = HumanGameAPI.GetGameInfo(gameID, null);

                    if (!EntryPoint.PlayGame(botName, game, MeID, settings.Item1, settings.Item2, picks =>
                    {
                        HumanGameAPI.SendPicks(game.ID, picks);
                        AILog.Log("PlayHuman", "Sent picks");
                    }, orders =>
                    {
                        HumanGameAPI.SendOrders(game.ID, orders, game.NumberOfTurns + 1);
                        AILog.Log("PlayHuman", "Sent orders");
                    }))
                    {
                        AILog.Log("PlayHuman", "We're no longer alive");
                        break;
                    }
                    turnNumber = status.Item1;
                }

                Thread.Sleep(10000);
            }
        }
        public static GameOrderAttackTransfer Create(PlayerIDType playerID, TerritoryIDType from, TerritoryIDType to, AttackTransferEnum attackTransfer, bool byPercent, Armies armies, bool attackTeammates)
        {
            var r = new GameOrderAttackTransfer();

            r.PlayerID        = playerID;
            r.From            = from;
            r.To              = to;
            r.AttackTransfer  = attackTransfer;
            r.ByPercent       = byPercent;
            r.NumArmies       = armies;
            r.AttackTeammates = attackTeammates;
            return(r);
        }
        public static GameOrderAttackTransfer Create(PlayerIDType playerID, TerritoryIDType from, TerritoryIDType to, AttackTransferEnum attackTransfer, Armies armies, String reason)
        {
            var r = new GameOrderAttackTransfer();

            r.PlayerID        = playerID;
            r.From            = from;
            r.To              = to;
            r.AttackTransfer  = attackTransfer;
            r.ByPercent       = false;
            r.NumArmies       = armies;
            r.AttackTeammates = true;
            r.Reason          = reason;
            return(r);
        }
示例#4
0
        public static void SendOrders(GameIDType gameID, PlayerIDType playerID, IEnumerable <GameOrder> orders, int turnNumber)
        {
            var ordersArray = new JArray();

            foreach (var order in orders)
            {
                var jOrder = new JObject();
                Communication.WriteOrder(jOrder, order);
                ordersArray.Add(jOrder);
            }
            var input = new JObject();

            input["gameID"]     = (int)gameID;
            input["playerID"]   = (int)playerID;
            input["orders"]     = ordersArray;
            input["turnNumber"] = turnNumber;

            var response = Communication.Call("SendOrdersBotGame", input);

            Assert.Fatal(response["success"] != null);
        }
示例#5
0
        /// <summary>
        /// Determines who controls this bonus. Will return null if nobody does or at least one territory is fogged
        /// </summary>
        public PlayerIDType?ControlsBonus(GameStanding standing)
        {
            Assert.Fatal(standing != null, "standing is null");

            PlayerIDType playerID = (PlayerIDType)int.MinValue;

            foreach (var territoryID in this.Territories)
            {
                TerritoryStanding cs = standing.Territories[territoryID];
                if (cs.OwnerPlayerID == TerritoryStanding.AvailableForDistribution)
                {
                    return(null);
                }
                if (cs.IsNeutral)
                {
                    return(null);
                }
                else if (cs.OwnerPlayerID == TerritoryStanding.FogPlayerID)
                {
                    return(null);
                }
                else if ((int)playerID == int.MinValue)
                {
                    playerID = cs.OwnerPlayerID;
                }
                else if (playerID != cs.OwnerPlayerID)
                {
                    return(null);
                }
            }

            Assert.Fatal(playerID != TerritoryStanding.FogPlayerID && playerID != TerritoryStanding.NeutralPlayerID);
            if ((int)playerID == int.MinValue)
            {
                throw new Exception("Bonus " + this.Name + " (" + this.ID + ") has no territories assigned");
            }

            return(new Nullable <PlayerIDType>(playerID));
        }
示例#6
0
        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);
        }
示例#7
0
        public static GameOrderPlayCardGift Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType terrID, PlayerIDType giftTo)
        {
            var o = new GameOrderPlayCardGift();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = playerID;
            o.TerritoryID    = terrID;
            o.GiftTo         = giftTo;
            return(o);
        }
        public static GameOrderPlayCardReinforcement Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID)
        {
            var o = new GameOrderPlayCardReinforcement();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = playerID;
            return(o);
        }
示例#9
0
        public static GameOrderPlayCardAirlift Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType fromTerritoryID, TerritoryIDType toTerritoryID, Armies numArmies)
        {
            var o = new GameOrderPlayCardAirlift();

            o.CardInstanceID  = cardInstanceID;
            o.PlayerID        = playerID;
            o.FromTerritoryID = fromTerritoryID;
            o.ToTerritoryID   = toTerritoryID;
            o.NumArmies       = numArmies;
            return(o);
        }
示例#10
0
 public bool AffectsPlayer(PlayerIDType p)
 {
     return(p == PlayerOne || p == PlayerTwo);
 }
示例#11
0
        public static Tuple <GameSettings, MapDetails, GameObject> GetBotExportedGame(GameIDType gameID, string exportedGame, PlayerIDType playerID, int?turnNumber)
        {
            var input = new JObject();

            input["exportedGame"] = exportedGame;
            input["playerID"]     = (int)playerID;

            if (turnNumber.HasValue)
            {
                input["turnNumber"] = turnNumber;
            }

            var response = Communication.Call("GetBotExportedGameInfo", input);

            var game     = Communication.ReadGameObject(response, gameID);
            var settings = Communication.ReadSettings(response["settings"]);
            var map      = Communication.ReadMap(response["map"]);

            return(new Tuple <GameSettings, MapDetails, GameObject>(settings, map, game));
        }
示例#12
0
        public static GameOrderPlayCardBomb Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType targetTerritoryID)
        {
            var o = new GameOrderPlayCardBomb();

            o.CardInstanceID    = cardInstanceID;
            o.PlayerID          = (PlayerIDType)playerID;
            o.TargetTerritoryID = targetTerritoryID;
            return(o);
        }
示例#13
0
        public static GameOrderPlayCardSpy Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, PlayerIDType targetPlayerID)
        {
            var o = new GameOrderPlayCardSpy();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = playerID;
            o.TargetPlayerID = targetPlayerID;
            return(o);
        }
示例#14
0
        public static GameOrderPlayCardDiplomacy Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, PlayerIDType playerOne, PlayerIDType playerTwo)
        {
            var o = new GameOrderPlayCardDiplomacy();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = (PlayerIDType)playerID;
            o.PlayerOne      = playerOne;
            o.PlayerTwo      = playerTwo;
            return(o);
        }
示例#15
0
 public int NumResources(PlayerIDType playerID, ResourceType type)
 {
     return(0); //not implemented
 }
        public static GameOrderPlayCardSurveillance Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, BonusIDType targetBonus)
        {
            var o = new GameOrderPlayCardSurveillance();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = playerID;
            o.TargetBonus    = targetBonus;
            return(o);
        }
示例#17
0
        public static GameOrderPlayCardReconnaissance Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, TerritoryIDType targetTerritory)
        {
            var o = new GameOrderPlayCardReconnaissance();

            o.CardInstanceID  = cardInstanceID;
            o.PlayerID        = playerID;
            o.TargetTerritory = targetTerritory;
            return(o);
        }
示例#18
0
        public static GameOrderPlayCardOrderDelay Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID)
        {
            var o = new GameOrderPlayCardOrderDelay();

            o.CardInstanceID = cardInstanceID;
            o.PlayerID       = playerID;
            return(o);
        }
        public static GameOrderPlayCardSanctions Create(CardInstanceIDType cardInstanceID, PlayerIDType playerID, PlayerIDType sanctionPlayer)
        {
            var o = new GameOrderPlayCardSanctions();

            o.CardInstanceID     = cardInstanceID;
            o.PlayerID           = (PlayerIDType)playerID;
            o.SanctionedPlayerID = sanctionPlayer;
            return(o);
        }