Esempio n. 1
0
        public void ThinkAboutNextAction()
        {
            if (actionToDo != NONE)
            {
                return;
            }

            player = AIplayer.DummyPlayer;

            visited[player.Location.X, player.Location.Y] = true;

            BuildTree(BUILDTREEPERACTION);

            // Decide next action
            MeesGame.PlayerAction action = NONE;
            foreach (NodeActionPair NAP in entryPoint.next)
            {
                if (NAP.Value.maxScore > entryPoint.maxScore && AIplayer.DummyPlayer.PossibleActions.Contains(action))
                {
                    action = NAP.Key;
                    break;
                }
            }
            actionToDo = action;
        }
Esempio n. 2
0
        /// <summary>
        /// This function should be called at least once before checking the best possible move.
        /// </summary>
        public void BuildTree()
        {
            MeesGame.IPlayer dummy  = player.Clone();
            Point            curLoc = dummy.Location;
            int  iterations         = 0;
            Node curNode            = entryPoint;

            nodeStack = new Stack <Node>();
            nodeStack.Push(curNode);
            MeesGame.PlayerAction lastAction = NONE;

            while (iterations < MAXITERATIONS)
            {
                iterations += 1;
                // pick a random action to perform
                MeesGame.PlayerAction chosenAction = dummy.PossibleActions[GameEnvironment.Random.Next(dummy.PossibleActions.Count)];
                if (chosenAction == NONE /* || (GetReverseAction(chosenAction) == lastAction)*/)
                {
                    continue;
                }

                //perform action
                dummy.PerformAction(chosenAction);
                nodeStack.Push(curNode);
                curNode = goToNextNode(curNode, chosenAction, dummy.Location);
                curLoc  = dummy.Location;
                if (!visited[curLoc.X, curLoc.Y])
                {
                    curNode.maxScore = getScore(curLoc);
                    break;
                }
                lastAction = chosenAction;
            }

            //max number of iterations reached, or broken out of the loop
            updateScore();
        }