Example #1
0
        private void AssignValuesToLeaves()
        {
            int[]       evalutations = { 5, 6, 7, 4, 5, 3, 6, 6, 9, 7, 5, 9, 8, 6 };
            string[]    names        = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N" };
            List <Node> leaves       = dvonnTree.GetAllLeaves();

            for (int i = 0; i < 14; i++)
            {
                leaves[i].testValue = evalutations[i];
                leaves[i].name      = names[i];
            }
        }
Example #2
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);
        }