Ejemplo n.º 1
0
        //for test purposes:
        //--------------------------------------------------------------


        private void CreateTestTree()
        {
            dvonnTree = new PositionTree();
            Node a = new Node();
            Node b = new Node();
            Node c = new Node();
            Node d = new Node();
            Node e = new Node();
            Node f = new Node();
            Node g = new Node();
            Node h = new Node();
            Node i = new Node();
            Node j = new Node();
            Node k = new Node();
            Node l = new Node();
            Node m = new Node();
            Node n = new Node();
            Node o = new Node();
            Node p = new Node();
            Node q = new Node();
            Node r = new Node();
            Node s = new Node();

            dvonnTree.root = a;
            dvonnTree.InsertChild(b, a);
            dvonnTree.InsertChild(c, a);
            dvonnTree.InsertChild(d, a);

            dvonnTree.InsertChild(e, b);
            dvonnTree.InsertChild(f, b);

            dvonnTree.InsertChild(g, c);
            dvonnTree.InsertChild(h, c);

            dvonnTree.InsertChild(i, d);
            dvonnTree.InsertChild(j, d);

            dvonnTree.InsertChild(k, e);
            dvonnTree.InsertChild(l, e);

            dvonnTree.InsertChild(m, f);

            dvonnTree.InsertChild(n, g);
            dvonnTree.InsertChild(o, g);

            dvonnTree.InsertChild(p, h);

            dvonnTree.InsertChild(q, i);

            dvonnTree.InsertChild(r, j);
            dvonnTree.InsertChild(s, j);

            dvonnTree.InsertChild(new Node(), k);
            dvonnTree.InsertChild(new Node(), k);

            dvonnTree.InsertChild(new Node(), l);
            dvonnTree.InsertChild(new Node(), l);
            dvonnTree.InsertChild(new Node(), l);

            dvonnTree.InsertChild(new Node(), m);

            dvonnTree.InsertChild(new Node(), n);

            dvonnTree.InsertChild(new Node(), o);
            dvonnTree.InsertChild(new Node(), o);

            dvonnTree.InsertChild(new Node(), p);

            dvonnTree.InsertChild(new Node(), q);

            dvonnTree.InsertChild(new Node(), r);
            dvonnTree.InsertChild(new Node(), r);

            dvonnTree.InsertChild(new Node(), s);
        }
Ejemplo n.º 2
0
 public TreeCrawler(PositionTree tree, GamePhase gamePhase, PieceID aiResponsibleColor)
 {
     this.tree               = tree;
     this.gamePhase          = gamePhase;
     this.aiResponsibleColor = aiResponsibleColor;
 }
Ejemplo n.º 3
0
        public Move ComputeAiMove(Position currentPosition, PieceID playerToMove)
        {
            Move chosenMove = new Move();

            depthCounter      = 0;
            this.playerToMove = playerToMove;
            tempPlayerToMove  = playerToMove;
            dvonnTree         = new PositionTree(currentPosition);
            aiBoard.ReceivePosition(currentPosition);
            int legalMoveCount  = aiBoard.FindLegalMoves(playerToMove).Count;
            int emptyStackCount = 49 - aiBoard.FindNotEmptyStacks().Count;

            currentGamePhase = DetermineGamePhase(emptyStackCount);

            Console.WriteLine();
            Console.WriteLine("AI: Legal moves count: " + legalMoveCount);
            Console.WriteLine("AI: Empty stacks count: " + emptyStackCount);
            Console.WriteLine("AI: Game Phase: " + currentGamePhase);
            Console.WriteLine();
            Console.WriteLine("AI: Computation begun.");
            var watch_1 = System.Diagnostics.Stopwatch.StartNew();

            if (currentGamePhase == GamePhase.EarlyGame)
            {
                CreateTree(3, 8000);
                PruneAndEvaluate();
                dvonnTree.RefreshAlphaBeta();
                if (dvonnTree.GetAllLeaves().Count < 1500)
                {
                    CreateTree(2, 8000);
                    PruneAndEvaluate();
                }
                chosenMove = PerformMiniMax();
            }

            if (currentGamePhase == GamePhase.Apex)
            {
                CreateTree(3, 7000);
                PruneAndEvaluate();
                dvonnTree.RefreshAlphaBeta();
                if (dvonnTree.GetAllLeaves().Count < 1000)
                {
                    CreateTree(2, 5000);
                    PruneAndEvaluate();
                }
                chosenMove = PerformMiniMax();
            }

            if (currentGamePhase == GamePhase.PostApex)
            {
                int allLeavesCount;
                do
                {
                    CreateTree(3, 9000);
                    PruneAndEvaluate();
                    dvonnTree.RefreshAlphaBeta();
                    allLeavesCount = dvonnTree.GetAllLeaves().Count;
                } while (allLeavesCount < 2500);

                int percentage = (int)((allLeavesCount - 1000) * 100 / (float)allLeavesCount);
                Console.WriteLine("AI: Hard prune percentage set to: " + percentage);
                HardPrune(percentage);
                dvonnTree.RemoveAllStubs();
                CreateTree(2, 3500);
                PruneAndEvaluate();
                chosenMove = PerformMiniMax();
            }

            if (currentGamePhase == GamePhase.EndGame)
            {
                CreateTree(15, 10000);
                EvaluateEndPoints();

                chosenMove = PerformMiniMax();
            }

            watch_1.Stop();
            var elapsedMs_1 = watch_1.ElapsedMilliseconds;

            Console.WriteLine("AI: Computation ended.");
            Console.WriteLine("AI: Total computation took: " + elapsedMs_1 + " milliseconds");
            Console.WriteLine("Outer endpoint depth: " + dvonnTree.GetDepthReach());
            WaitForUser();

            return(chosenMove);
        }