Пример #1
0
        public ParetoTreeNode(Playfield state, ParetoTreeNode parent, int childIndex, RandomRoller roller,
                              ParetoTreePolicy treePolicy, Random rnd, ParetoMCTSPlayer a_player)
        {
            this.m_player = a_player;
            this.state    = state;
            this.parent   = parent;
            this.m_rnd    = rnd;
            //children = new ParetoTreeNode[ParetoMCTSParameters.NUM_ACTIONS];
            this.roller      = roller;
            this.mTreePolicy = treePolicy;
            pa = new ParetoArchive();
            this.childIndex       = childIndex;
            this.m_prunedChildren = new bool[ParetoMCTSParameters.NUM_ACTIONS];
            this.m_numIters       = 0;
            //this.m_pi = pi;

            isTerminal           = false;
            isExpanded           = false;
            isExhausted          = false;
            numExpandedChildren  = 0;
            numExhaustedChildren = 0;
            nodeNum = GameManager.Instance.nodeCount;
            GameManager.Instance.nodeCount++;

            totValue = new double[ParetoMCTSParameters.NUM_TARGETS];
        }
Пример #2
0
 public ParetoTreeChanceNode(Playfield state, ParetoTreeNode parent, int childIndex, RandomRoller roller,
                             ParetoTreePolicy treePolicy, Random rnd, ParetoMCTSPlayer a_player, Action chanceAction, int childrenSize) :
     this(state, parent, childIndex, roller,
          treePolicy, rnd, a_player, chanceAction)
 {
     this.children = new List <ParetoTreeNode>(childrenSize);
 }
Пример #3
0
 public TreeNode(Playfield state, TreeNode parent, RandomRoller RandomRoller, ParetoTreePolicy ParetoTreePolicy, ParetoMCTSPlayer a_ParetoMCTSPlayer)
 {
     this.m_ParetoMCTSPlayer = a_ParetoMCTSPlayer;
     this.parent             = parent;
     totValue              = new double[ParetoMCTSParameters.NUM_TARGETS];
     this.RandomRoller     = RandomRoller;
     this.paretoTreePolicy = ParetoTreePolicy;
     // System.out.println("Made a TreeNode of depth " + depth() + ", arity " + children.Length);
 }
Пример #4
0
        public int expand(Node p, HeuristicType ht)
        {
            Playfield afterState = new Playfield(p.state);

            ParetoMCTSPlayer m_player = new ParetoMCTSPlayer(new ParetoTreePolicy(0.7), GameManager.getRNG(), afterState, ht);

            m_player.run(afterState, 30000, false);
            //m_player.m_root.printStats();
            //Helpfunctions.Instance.logg("turn: " + p.state.isOwnTurn);
            int memberSize = m_player.m_root.pa.m_members.size(); // will it always > 0?

            for (int i = 0; i < memberSize; i++)                  // this is other's turn
            {
                Node      afterNode;
                Playfield pf = m_player.m_root.pa.m_members.get(i).m_state;
                if (ht == HeuristicType.DrawCard)
                {
                    if (pf.moveTrigger.newHandcardList.Count == 0)
                    {
                        continue;
                    }

                    afterNode = new ChanceNode(p, pf, null, p.depth, 1); //last param is wrong
                    pf.printActions();
                }
                else if (ht == HeuristicType.LethalCheck)
                {
                    if (pf.getLethalScore() == 1.0)
                    {
                        afterNode = new Node(p, pf, null, p.depth + 1);
                    }
                    continue;
                }
                else
                {
                    afterNode = new Node(p, pf, null, p.depth + 1);
                }
                p.children.Add(afterNode);
            }

            return(p.children.Count);
        }
Пример #5
0
 public SimpleTreeNode(Playfield state, RandomRoller RandomRoller, ParetoTreePolicy ParetoTreePolicy, ParetoMCTSPlayer a_ParetoMCTSPlayer)
 {
     this(state, null, RandomRoller, ParetoTreePolicy, a_ParetoMCTSPlayer);
     this.RandomRoller     = RandomRoller;
     this.paretoTreePolicy = ParetoTreePolicy;
     pa = new ParetoArchive();
 }
Пример #6
0
        public int expand(Node p, HeuristicType ht, int numberIter)
        {
            Playfield afterState = new Playfield(p.state);

            ParetoMCTSPlayer m_player = new ParetoMCTSPlayer(new ParetoTreePolicy(0.7), GameManager.getRNG(), afterState, ht);

            m_player.run(afterState, numberIter, false);
            //m_player.m_root.printStats();
            //Helpfunctions.Instance.logg("turn: " + p.state.isOwnTurn);
            int memberSize = m_player.m_root.pa.m_members.size(); // will it always > 0?

            //if (ht == HeuristicType.Boardvalue)
            //    m_player.m_root.pa.printArchive();


            if (ht == HeuristicType.DrawCard)
            {
                Console.WriteLine("chance: " + memberSize);
                if (memberSize > 1)
                {
                    chanceCount += memberSize - 1;
                }
                m_player.m_root.pa.printArchive();
            }
            for (int i = 0; i < memberSize; i++) // this is other's turn
            {
                Node      afterNode;
                Playfield pf = m_player.m_root.pa.m_members.get(i).m_state;
                if (ht == HeuristicType.DrawCard)
                {
                    if (pf.moveTrigger.newHandcardList.Count == 0)
                    {
                        continue;
                    }

                    if ((pf.isOwnTurn && pf.homeDeck.Count > 0) ||
                        (!pf.isOwnTurn && pf.awayDeck.Count > 0))
                    {
                        List <Action> actionList = pf.getActions();
                        Playfield     tempPf     = new Playfield(afterState);
                        for (int j = tempPf.getActions().Count; j < actionList.Count - 1; j++)
                        {
                            tempPf.doAction(actionList[j]);
                        }
                        afterNode = new ChanceNode(p, tempPf, actionList[actionList.Count - 1], p.depth, pf.moveTrigger.newHandcardList.Count);
                    }
                    else
                    {
                        afterNode = new Node(p, pf, null, p.depth);
                    }

                    if (memberSize > 1)
                    {
                        pf.printActions();
                    }
                    //pf.printActions();
                }
                else if (ht == HeuristicType.LethalCheck)
                {
                    if (pf.getLethalScore() == 1.0)
                    {
                        afterNode = new Node(p, pf, null, p.depth + 1);
                    }
                    continue;
                }
                else
                {
                    if ((pf.isOwnTurn && pf.homeDeck.Count > 0) ||
                        (!pf.isOwnTurn && pf.awayDeck.Count > 0))
                    {
                        afterNode = new ChanceNode(p, pf, null, p.depth + 1, 1);
                    }
                    else
                    {
                        pf.drawTurnStartCard();
                        afterNode = new Node(p, pf, null, p.depth + 1);
                    }
                }
                p.children.Add(afterNode);
            }

            return(p.children.Count);
        }