예제 #1
0
        public void Encode(string fileName)
        {
            StreamReader file  = new StreamReader(fileName);
            string       line  = null;
            int          count = 0;

            while ((line = file.ReadLine()) != null)
            {
                if (count % 100 == 0)
                {
                    Console.WriteLine("Read " + count + " lines.");
                }

                GameRecord          gameRecord = JsonConvert.DeserializeObject <GameRecord>(line);
                List <StateKeyInfo> playSec    = new List <StateKeyInfo>();

                int lastEntity = 1000;
                foreach (StateKeyInfo stKeyInfo in gameRecord.playSec)
                {
                    PlayerKeyInfo p1Info = stKeyInfo.attackPlayer;
                    PlayerKeyInfo p2Info = stKeyInfo.defensePlayer;

                    bool isOwnTurn = p1Info.turn == 0 ? true : false;

                    Playfield tempPf = null;
                    if (isOwnTurn)
                    {
                        tempPf = new Playfield(lastEntity, isOwnTurn, p1Info, p2Info);
                    }
                    else
                    {
                        tempPf = new Playfield(lastEntity, isOwnTurn, p2Info, p1Info);
                    }

                    stKeyInfo.nextEntity = tempPf.nextEntity;
                    stKeyInfo.turnSt     = 1;
                    Player mPlayer = tempPf.getCurrentPlayer(true);
                    Player ePlayer = tempPf.getCurrentPlayer(false);

                    int length = stKeyInfo.attackPlayer.handcardJsonList.Count;
                    stKeyInfo.attackPlayer.handcardJsonList.Clear();

                    foreach (Handmanager.Handcard hc in mPlayer.owncards)
                    {
                        PlayerKeyInfo.CardKeyInfo hcInfo = new PlayerKeyInfo.CardKeyInfo(hc, true, tempPf);
                        stKeyInfo.attackPlayer.handcardJsonList.Add(hcInfo);
                    }

                    length = stKeyInfo.defensePlayer.handcardJsonList.Count;
                    stKeyInfo.defensePlayer.handcardJsonList.Clear();

                    foreach (Handmanager.Handcard hc in ePlayer.owncards)
                    {
                        PlayerKeyInfo.CardKeyInfo hcInfo = new PlayerKeyInfo.CardKeyInfo(hc, true, tempPf);
                        stKeyInfo.defensePlayer.handcardJsonList.Add(hcInfo);
                    }

                    //hero power
                    stKeyInfo.attackPlayer.canPlayHeroPower = new List <int>();
                    bool canPlayHeroPower = mPlayer.ownAbilityReady && mPlayer.mana >= 2;
                    if (canPlayHeroPower)
                    {
                        stKeyInfo.attackPlayer.canPlayHeroPower.Add(1);
                    }
                    else
                    {
                        stKeyInfo.attackPlayer.canPlayHeroPower.Add(0);
                    }

                    foreach (PlayerKeyInfo.ActionKeyInfo actionKeyInfo in p1Info.playedActionJsonList)
                    {
                        Action action = CreateActionFromInfo(tempPf, actionKeyInfo);

                        tempPf.getNextEntity();
                        tempPf.doAction(action);

                        PlayerKeyInfo ownkeyInfo, enemykeyInfo;
                        if (isOwnTurn)
                        {
                            ownkeyInfo   = new PlayerKeyInfo(tempPf.playerFirst, tempPf.homeDeck, true, tempPf);
                            enemykeyInfo = new PlayerKeyInfo(tempPf.playerSecond, tempPf.awayDeck, false, tempPf);
                        }
                        else
                        {
                            ownkeyInfo   = new PlayerKeyInfo(tempPf.playerSecond, tempPf.awayDeck, false, tempPf);
                            enemykeyInfo = new PlayerKeyInfo(tempPf.playerFirst, tempPf.homeDeck, true, tempPf);
                        }
                        StateKeyInfo interState = new StateKeyInfo(tempPf.nextEntity, ownkeyInfo, enemykeyInfo,
                                                                   false, 0.0);
                        //playSec.Add(interState);
                        if (action.own != null)
                        {
                            actionKeyInfo.ownName = action.own.name.ToString();
                        }
                        if (action.target != null)
                        {
                            actionKeyInfo.targetName = action.target.name.ToString();
                        }
                        if (action.actionType == actionEnum.playcard || action.actionType == actionEnum.useHeroPower)
                        {
                            if (stKeyInfo.attackPlayer.handcardChange == null)
                            {
                                stKeyInfo.attackPlayer.handcardChange = new List <List <PlayerKeyInfo.CardKeyInfo> >();
                            }
                            stKeyInfo.attackPlayer.handcardChange.Add(interState.attackPlayer.handcardJsonList);

                            canPlayHeroPower = mPlayer.ownAbilityReady && mPlayer.mana >= 2;
                            if (action.actionType == actionEnum.useHeroPower)
                            {
                                Debug.Assert(canPlayHeroPower == false);
                                actionKeyInfo.cardName = "fireblast";
                            }
                            else
                            {
                                actionKeyInfo.cardName = action.card.card.name.ToString();
                            }

                            if (canPlayHeroPower)
                            {
                                stKeyInfo.attackPlayer.canPlayHeroPower.Add(1);
                            }
                            else
                            {
                                stKeyInfo.attackPlayer.canPlayHeroPower.Add(0);
                            }
                        }
                    }

                    playSec.Add(stKeyInfo);
                    lastEntity = tempPf.getNextEntity() + 1;
                    //Console.WriteLine("===================");
                    //Console.WriteLine("End turn Next Entity:" + lastEntity);
                    //Console.WriteLine("===================");
                }
                gameRecord.playSec = playSec;
                count++;
                Helpfunctions.Instance.WriteResultToFileAbs(fileName + ".2.txt", JsonConvert.SerializeObject(gameRecord));
            }
        }
예제 #2
0
 public string getCardKeyInfo(Handmanager.Handcard handcard)
 {
     PlayerKeyInfo.CardKeyInfo keyInfo = new PlayerKeyInfo.CardKeyInfo(handcard);
     return(new JavaScriptSerializer().Serialize(keyInfo));
 }
예제 #3
0
        public void EncodeModified(string fileName)
        {
            StreamReader file  = new StreamReader(fileName);
            string       line  = null;
            int          count = 0;

            while ((line = file.ReadLine()) != null)
            {
                //Helpfunctions.Instance.logg(line);
                if (count % 1000 == 0)
                {
                    Console.WriteLine("Finished " + count + " lines.");
                }

                GameRecord gameRecord = JsonConvert.DeserializeObject <GameRecord>(line);
                int        lastEntity = 1000;
                foreach (StateKeyInfo stKeyInfo in gameRecord.playSec)
                {
                    PlayerKeyInfo p1Info = stKeyInfo.attackPlayer;
                    PlayerKeyInfo p2Info = stKeyInfo.defensePlayer;

                    bool isOwnTurn = p1Info.turn == 0 ? true : false;
                    lastEntity = stKeyInfo.nextEntity;
                    Playfield tempPf = null;
                    if (isOwnTurn)
                    {
                        tempPf = new Playfield(lastEntity, isOwnTurn, p1Info, p2Info);
                    }
                    else
                    {
                        tempPf = new Playfield(lastEntity, isOwnTurn, p2Info, p1Info);
                    }

                    stKeyInfo.turnSt = 1;
                    Player mPlayer = tempPf.getCurrentPlayer(true);
                    Player ePlayer = tempPf.getCurrentPlayer(false);

                    int length = stKeyInfo.attackPlayer.handcardJsonList.Count;
                    stKeyInfo.attackPlayer.handcardJsonList.Clear();

                    foreach (Handmanager.Handcard hc in mPlayer.owncards)
                    {
                        PlayerKeyInfo.CardKeyInfo hcInfo = new PlayerKeyInfo.CardKeyInfo(hc, true, tempPf);
                        stKeyInfo.attackPlayer.handcardJsonList.Add(hcInfo);
                    }

                    length = stKeyInfo.defensePlayer.handcardJsonList.Count;
                    stKeyInfo.defensePlayer.handcardJsonList.Clear();

                    foreach (Handmanager.Handcard hc in ePlayer.owncards)
                    {
                        PlayerKeyInfo.CardKeyInfo hcInfo = new PlayerKeyInfo.CardKeyInfo(hc, true, tempPf);
                        stKeyInfo.defensePlayer.handcardJsonList.Add(hcInfo);
                    }

                    LinkedList <Action> actionSeq = searchValidSeq(tempPf, p1Info);
                    stKeyInfo.attackPlayer.canPlayHeroPower     = new List <int>();
                    stKeyInfo.attackPlayer.playedActionJsonList = new List <PlayerKeyInfo.ActionKeyInfo>();
                    stKeyInfo.attackPlayer.handcardChange       = new List <List <PlayerKeyInfo.CardKeyInfo> >();

                    foreach (Action action in actionSeq)
                    {
                        if (action.actionType == actionEnum.useHeroPower || action.actionType == actionEnum.playcard)
                        {
                            PlayerKeyInfo ownkeyInfo, enemykeyInfo;
                            if (isOwnTurn)
                            {
                                ownkeyInfo   = new PlayerKeyInfo(tempPf.playerFirst, tempPf.homeDeck, true, tempPf);
                                enemykeyInfo = new PlayerKeyInfo(tempPf.playerSecond, tempPf.awayDeck, false, tempPf);
                            }
                            else
                            {
                                ownkeyInfo   = new PlayerKeyInfo(tempPf.playerSecond, tempPf.awayDeck, false, tempPf);
                                enemykeyInfo = new PlayerKeyInfo(tempPf.playerFirst, tempPf.homeDeck, true, tempPf);
                            }
                            StateKeyInfo interState = new StateKeyInfo(tempPf.nextEntity, ownkeyInfo, enemykeyInfo, false, 0.0);
                            stKeyInfo.attackPlayer.handcardChange.Add(interState.attackPlayer.handcardJsonList);
                            bool canPlayHeroPower = mPlayer.ownAbilityReady && mPlayer.mana >= 2;
                            if (canPlayHeroPower)
                            {
                                stKeyInfo.attackPlayer.canPlayHeroPower.Add(1);
                            }
                            else
                            {
                                stKeyInfo.attackPlayer.canPlayHeroPower.Add(0);
                            }
                        }

                        Debug.Assert(stKeyInfo.attackPlayer.canPlayHeroPower.Count == stKeyInfo.attackPlayer.handcardChange.Count);

                        tempPf.getNextEntity();
                        tempPf.doAction(action);
                        stKeyInfo.attackPlayer.playedActionJsonList.Add(new PlayerKeyInfo.ActionKeyInfo(action));
                        if (debug)
                        {
                            action.print();
                        }
                    }
                    lastEntity = tempPf.getNextEntity() + 1;
                    //Console.WriteLine("===================");
                    //Console.WriteLine("End turn Next Entity:" + lastEntity);
                    //Console.WriteLine("===================");
                }
                count++;
                Helpfunctions.Instance.WriteResultToFileAbs(fileName + ".3.txt", JsonConvert.SerializeObject(gameRecord));
            }
        }