コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: AIGamesParser.cs プロジェクト: Norman1/WarLightAI
        private static void ReadOpponentMoves(string[] moveInput)
        {
            var orders = new List <GameOrder>();

            for (var i = 1; i < moveInput.Length; i++)
            {
                GameOrder order;
                if (moveInput[i + 1] == "place_armies")
                {
                    var playerID = ToPlayerID(moveInput[i]);
                    var terrID   = (TerritoryIDType)int.Parse(moveInput[i + 2]);
                    var armies   = int.Parse(moveInput[i + 3]);
                    i += 3;

                    var existing = orders.OfType <GameOrderDeploy>().FirstOrDefault(o => o.DeployOn == terrID);
                    if (existing != null)
                    {
                        //Don't allow dupe deploy orders.  Just add it to the existing one
                        Assert.Fatal(existing.PlayerID == playerID);
                        existing.NumArmies += armies;
                        continue;
                    }

                    order = GameOrderDeploy.Create(armies, playerID, terrID);
                }
                else
                {
                    if (moveInput[i + 1] == "attack/transfer")
                    {
                        var fromTerrID = (TerritoryIDType)int.Parse(moveInput[i + 2]);
                        var toTerrID   = (TerritoryIDType)int.Parse(moveInput[i + 3]);


                        var playerID = ToPlayerID(moveInput[i]);
                        var armies   = int.Parse(moveInput[i + 4]);
                        order = GameOrderAttackTransfer.Create(playerID, fromTerrID, toTerrID, AttackTransferEnum.AttackTransfer, false, new Armies(armies), false);
                        i    += 4;
                    }
                    else
                    {
                        throw new Exception("Unexpected order type");
                    }
                }

                orders.Add(order);
            }
            PrevTurn = orders.ToArray();
        }
コード例 #3
0
        public static GameOrder ReadOrder(JToken jOrder)
        {
            var type = (string)jOrder["type"];

            var playerID = (PlayerIDType)(int)jOrder["playerID"];

            if (type == "GameOrderDeploy")
            {
                var terrID = (TerritoryIDType)(int)jOrder["deployOn"];
                var armies = (int)jOrder["armies"];
                return(GameOrderDeploy.Create(armies, playerID, terrID));
            }

            if (type == "GameOrderAttackTransfer")
            {
                var from            = (TerritoryIDType)(int)jOrder["from"];
                var to              = (TerritoryIDType)(int)jOrder["to"];
                var armies          = ToArmies((string)jOrder["numArmies"]);
                var attackTeammates = (bool)jOrder["attackTeammates"];
                var byPercent       = (bool)jOrder["byPercent"];
                var attackTransfer  = (AttackTransferEnum)Enum.Parse(typeof(AttackTransferEnum), (string)jOrder["attackTransfer"]);
                return(GameOrderAttackTransfer.Create(playerID, from, to, attackTransfer, byPercent, armies, attackTeammates));
            }

            if (type.StartsWith("GameOrderPlayCard"))
            {
                var cardInstanceID = (CardInstanceIDType)Guid.Parse((string)jOrder["cardInstanceID"]);
                switch (type)
                {
                case "GameOrderPlayCardReinforcement":
                    return(GameOrderPlayCardReinforcement.Create(cardInstanceID, playerID));

                case "GameOrderPlayCardAbandon":
                    return(GameOrderPlayCardAbandon.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritoryID"]));

                case "GameOrderPlayCardAirlift":
                    return(GameOrderPlayCardAirlift.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["from"], (TerritoryIDType)(int)jOrder["to"], ToArmies((string)jOrder["armiesToAirlift"])));

                case "GameOrderPlayCardBlockade":
                    return(GameOrderPlayCardBlockade.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritoryID"]));

                case "GameOrderPlayCardBomb":
                    return(GameOrderPlayCardBomb.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritoryID"]));

                case "GameOrderPlayCardDiplomacy":
                    return(GameOrderPlayCardDiplomacy.Create(cardInstanceID, playerID, (PlayerIDType)(int)jOrder["playerOne"], (PlayerIDType)(int)jOrder["playerTwo"]));

                case "GameOrderPlayCardGift":
                    return(GameOrderPlayCardGift.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["territoryID"], (PlayerIDType)(int)jOrder["giftTo"]));

                case "GameOrderPlayCardOrderDelay":
                    return(GameOrderPlayCardOrderDelay.Create(cardInstanceID, playerID));

                case "GameOrderPlayCardOrderPriority":
                    return(GameOrderPlayCardOrderPriority.Create(cardInstanceID, playerID));

                case "GameOrderPlayCardReconnaissance":
                    return(GameOrderPlayCardReconnaissance.Create(cardInstanceID, playerID, (TerritoryIDType)(int)jOrder["targetTerritory"]));

                case "GameOrderPlayCardSanctions":
                    return(GameOrderPlayCardSanctions.Create(cardInstanceID, playerID, (PlayerIDType)(int)jOrder["sanctionedPlayerID"]));

                case "GameOrderPlayCardSpy":
                    return(GameOrderPlayCardSpy.Create(cardInstanceID, playerID, (PlayerIDType)(int)jOrder["targetPlayerID"]));

                case "GameOrderPlayCardSurveillance":
                    return(GameOrderPlayCardSurveillance.Create(cardInstanceID, playerID, (BonusIDType)(int)jOrder["targetBonus"]));

                case "GameOrderPlayCardFogged":
                    return(GameOrderPlayCardFogged.Create(playerID, cardInstanceID));
                }
            }


            switch (type)
            {
            case "GameOrderReceiveCard":

                var ret = new GameOrderReceiveCard();
                ret.PlayerID         = (PlayerIDType)(int)jOrder["playerID"];
                ret.InstancesCreated = new List <CardInstance>();
                foreach (var card in (JArray)jOrder["cardsMadeWhole"])
                {
                    var inst = new CardInstance();
                    inst.ID     = (CardInstanceIDType)Guid.Parse((string)card["cardInstanceID"]);
                    inst.CardID = (CardIDType)(int)card["cardID"];
                    ret.InstancesCreated.Add(inst);
                }
                return(ret);

            case "GameOrderStateTransition":
                var stateTrans = new GameOrderStateTransition();
                stateTrans.PlayerID = (PlayerIDType)(int)jOrder["playerID"];
                stateTrans.NewState = (GamePlayerState)Enum.Parse(typeof(GamePlayerState), (string)jOrder["newState"]);
                return(stateTrans);

            case "ActiveCardWoreOff":
                var active = new ActiveCardWoreOff();
                active.PlayerID       = (PlayerIDType)(int)jOrder["playerID"];
                active.CardInstanceID = (CardInstanceIDType)Guid.Parse((string)jOrder["cardInstanceID"]);
                return(active);

            case "GameOrderDiscard":
                return(GameOrderDiscard.Create((PlayerIDType)(int)jOrder["playerID"], (CardInstanceIDType)Guid.Parse((string)jOrder["cardInstanceID"])));
            }

            throw new Exception("Need handler for order type " + type);
        }
コード例 #4
0
ファイル: AIGamesParser.cs プロジェクト: Norman1/WarLightAI
 static string GetAttackString(GameOrderAttackTransfer attack)
 {
     return(ToPlayerString(attack.PlayerID) + " attack/transfer " + attack.From + " " + attack.To + " " + attack.NumArmies.NumArmies);
 }