Пример #1
0
        public Node tryDoAction(Node cur, PlayerKeyInfo.ActionKeyInfo keyInfo)
        {
            Node      ret     = null;
            Action    action  = CreateActionFromInfo(cur.pf, keyInfo);
            Playfield temp    = null;
            bool      noError = true;

            if (action != null)
            {
                try
                {
                    temp = new Playfield(cur.pf);
                    temp.getNextEntity();
                    temp.doAction(action);
                }
                catch (NullReferenceException e)
                {
                    noError = false;
                }
                if (noError)
                {
                    if (action.actionType == actionEnum.playcard || action.actionType == actionEnum.useHeroPower)
                    {
                        ret = new Node(temp, cur, cur.pcAction + 1, cur.nonPCaction, action);
                    }
                    else
                    {
                        ret = new Node(temp, cur, cur.pcAction, cur.nonPCaction + 1, action);
                    }
                }
            }
            return(ret);
        }
Пример #2
0
        public Action CreateActionFromInfo(Playfield pf, PlayerKeyInfo.ActionKeyInfo keyInfo)
        {
            Handmanager.Handcard card = null;
            Player mPlayer            = pf.getCurrentPlayer(true);
            Player ePlayer            = pf.getCurrentPlayer(false);

            if (keyInfo.cardEntitiy != -10 && keyInfo.cardEntitiy != -1)
            {
                foreach (Handmanager.Handcard hc in mPlayer.owncards)
                {
                    if (hc.entity == keyInfo.cardEntitiy)
                    {
                        card = hc;
                        break;
                    }
                }
                if (card == null)
                {
                    foreach (Handmanager.Handcard hc in mPlayer.owncards)
                    {
                        if (hc.card.name.ToString() == keyInfo.cardName)
                        {
                            card = hc;
                            break;
                        }
                    }
                }
                if (card == null)
                {
                    return(null);
                }
            }

            Minion ownMinion = null;

            if (keyInfo.ownEntity != -10)
            {
                foreach (Minion m in mPlayer.ownMinions)
                {
                    if (m.entitiyID == keyInfo.ownEntity)
                    {
                        ownMinion = m;
                        break;
                    }
                }
                if (ownMinion == null)
                {
                    foreach (Minion m in mPlayer.ownMinions)
                    {
                        if (m.handcard.card.name.ToString() == keyInfo.ownName)
                        {
                            ownMinion = m;
                            break;
                        }
                    }
                }
                if (ownMinion == null)
                {
                    return(null);
                }
            }

            Minion target = null;

            if (keyInfo.targetEntity == 0 || keyInfo.targetEntity == 1)
            {
                target = ePlayer.ownHero;
            }
            else if (keyInfo.targetEntity != -10)
            {
                bool found = false;
                foreach (Minion m in ePlayer.ownMinions)
                {
                    if (m.entitiyID == keyInfo.targetEntity)
                    {
                        target = m;
                        found  = true;
                        break;
                    }
                }
                foreach (Minion m in mPlayer.ownMinions)
                {
                    if (m.entitiyID == keyInfo.targetEntity)
                    {
                        target = m;
                        found  = true;
                        break;
                    }
                }
                if (target == null)
                {
                    foreach (Minion m in ePlayer.ownMinions)
                    {
                        if (m.handcard.card.name.ToString() == keyInfo.targetName)
                        {
                            target = m;
                            found  = true;
                            break;
                        }
                    }
                    foreach (Minion m in mPlayer.ownMinions)
                    {
                        if (m.handcard.card.name.ToString() == keyInfo.targetName)
                        {
                            target = m;
                            found  = true;
                            break;
                        }
                    }
                }
                if (target == null)
                {
                    return(null);
                }
            }

            return(new Action(keyInfo.actionType, card, ownMinion, keyInfo.place, target, 0, 1, keyInfo.manaCost));
        }
Пример #3
0
        public LinkedList <Action> searchValidSeq(Playfield pf, PlayerKeyInfo p1Info)
        {
            //this.debugCounter++;
            //Console.WriteLine(this.debugCounter);
            //if (this.debugCounter == 11)
            //{
            //    this.debug = true;
            //}
            Playfield  tempPf        = new Playfield(pf);
            Player     mPlayer       = tempPf.getCurrentPlayer(true);
            Player     ePlayer       = tempPf.getCurrentPlayer(false);
            List <int> pcActionId    = new List <int>();
            List <int> nonPcActionId = new List <int>();

            for (int i = 0; i < p1Info.playedActionJsonList.Count; i++)
            {
                PlayerKeyInfo.ActionKeyInfo keyInfo = p1Info.playedActionJsonList[i];
                if (keyInfo.actionType == actionEnum.useHeroPower || keyInfo.actionType == actionEnum.playcard)
                {
                    pcActionId.Add(i);
                }
                else
                {
                    nonPcActionId.Add(i);
                }
            }

            Node root = new Node(new Playfield(pf), null, 0, 0, null);
            Node cur  = root;

            while (cur.pcAction + cur.nonPCaction < p1Info.playedActionJsonList.Count)
            {
                if (this.debug)
                {
                    Console.WriteLine("pc:" + cur.pcAction + "/" + pcActionId.Count + "| nonPc:" + cur.nonPCaction + "/" + nonPcActionId.Count);
                }
                Node nextNode = null;
                if (cur.pcAction < pcActionId.Count && !cur.triedLeft)
                {
                    //try left
                    cur.triedLeft = true;
                    nextNode      = tryDoAction(cur, p1Info.playedActionJsonList[pcActionId[cur.pcAction]]);
                }
                else if (cur.nonPCaction < nonPcActionId.Count && !cur.triedRight)
                {
                    cur.triedRight = true;
                    nextNode       = tryDoAction(cur, p1Info.playedActionJsonList[nonPcActionId[cur.nonPCaction]]);
                }
                else
                {
                    nextNode = cur.par;
                }
                if (nextNode != null)
                {
                    cur = nextNode;
                }
            }

            LinkedList <Action> ret = new LinkedList <Action>();

            while (cur.action != null)
            {
                ret.AddFirst(cur.action);
                cur = cur.par;
            }
            return(ret);
        }