Ejemplo n.º 1
0
        private void twoAiPlay(CheckersAI p1, CheckersAI p2)
        {
            while (winner == null && !tie)
            {
                aiMakeMove(p1);
                aiMakeMove(p2);
            }

            gameSummary.Text = summary(p1, p2);
        }
Ejemplo n.º 2
0
 private void aiMakeMove(CheckersAI ai)
 {
     while (turn.Equals(ai.getPlayer()))
     {
         currentMove = ai.getAiMove(getCurrentBoard());
         if (currentMove != null)
         {
             if (checkMove())
             {
                 makeMove();
             }
         }
     }
 }
Ejemplo n.º 3
0
        private void startNewGame(object sender, RoutedEventArgs e)
        {
            clearBoard();
            buildBoard();
            turn        = "black";
            currentMove = null;
            winner      = null;

            int treeDepth = int.Parse(treeDepthBox.Text);

            if (minmaxVSPlayer.IsChecked == true)
            {
                if (firstH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 1, true);
                }

                if (secondH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 2, true);
                }

                if (thirdH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 3, true);
                }
            }

            if (minmaxVSMinmax.IsChecked == true)
            {
                CheckersAI ai2 = null;

                if (firstH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 1, true);
                }

                if (secondH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 2, true);
                }

                if (thirdH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 3, true);
                }

                if (firstHeuristic.IsChecked == true)
                {
                    ai2 = new CheckersAI("black", treeDepth, 1, true);
                }

                if (secondHeuristic.IsChecked == true)
                {
                    ai2 = new CheckersAI("black", treeDepth, 2, true);
                }

                if (thirdHeuristic.IsChecked == true)
                {
                    ai2 = new CheckersAI("black", treeDepth, 3, true);
                }

                twoAiPlay(ai2, ai);
            }

            if (minmaxVSAlfabeta.IsChecked == true)
            {
                CheckersAI ai2        = null;
                CheckersAI alphabeta1 = null;

                if (firstH.IsChecked == true)
                {
                    ai2 = new CheckersAI("black", treeDepth, 1, true);
                }

                if (secondH.IsChecked == true)
                {
                    ai2 = new CheckersAI("black", treeDepth, 2, true);
                }

                if (thirdH.IsChecked == true)
                {
                    ai2 = new CheckersAI("black", treeDepth, 1, true);
                }

                if (firstHeuristic.IsChecked == true)
                {
                    alphabeta1 = new CheckersAI("red", treeDepth, 1, false);
                }

                if (secondHeuristic.IsChecked == true)
                {
                    alphabeta1 = new CheckersAI("red", treeDepth, 2, false);
                }

                if (thirdHeuristic.IsChecked == true)
                {
                    alphabeta1 = new CheckersAI("red", treeDepth, 3, false);
                }

                twoAiPlay(ai2, alphabeta1);
            }

            if (alfabetaVSPlayer.IsChecked == true)
            {
                if (firstH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 1, false);
                }

                if (secondH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 2, false);
                }

                if (thirdH.IsChecked == true)
                {
                    ai = new CheckersAI("red", treeDepth, 3, false);
                }
            }

            if (alfabetaVSAlfabeta.IsChecked == true)
            {
                CheckersAI alphabeta2 = null;
                CheckersAI alphabeta1 = null;

                if (firstH.IsChecked == true)
                {
                    alphabeta2 = new CheckersAI("black", treeDepth, 1, false);
                }

                if (secondH.IsChecked == true)
                {
                    alphabeta2 = new CheckersAI("black", treeDepth, 2, false);
                }

                if (thirdH.IsChecked == true)
                {
                    alphabeta2 = new CheckersAI("black", treeDepth, 1, false);
                }

                if (firstHeuristic.IsChecked == true)
                {
                    alphabeta1 = new CheckersAI("red", treeDepth, 1, false);
                }

                if (secondHeuristic.IsChecked == true)
                {
                    alphabeta1 = new CheckersAI("red", treeDepth, 2, false);
                }

                if (thirdHeuristic.IsChecked == true)
                {
                    alphabeta1 = new CheckersAI("red", treeDepth, 3, false);
                }


                twoAiPlay(alphabeta2, alphabeta1);
            }
        }
Ejemplo n.º 4
0
        private string summary(CheckersAI p1, CheckersAI p2)
        {
            var summary = "Trees' depth = " + treeDepthBox.Text + "\n";

            if (winner.Equals(p1.getPlayer()))
            {
                summary += "Winner: " + p1.getPlayer() + " heuristic " + p1.getHeuristic() + "\n";

                if (p1.useMinMax())
                {
                    summary += " minmax made: ";
                }
                else
                {
                    summary += " alfa beta made: ";
                }

                summary += p1.getNumOfMoves() + "moves \n";
                summary += "Time " + p1.getTime() + "\n";

                summary += "Loser: " + p2.getPlayer() + " heuristic " + p2.getHeuristic() + "\n";

                if (p2.useMinMax())
                {
                    summary += " minmax made: ";
                }
                else
                {
                    summary += " alfa beta made: ";
                }

                summary += p2.getNumOfMoves() + "moves \n";
                summary += "Time " + p2.getTime() + "\n";
            }
            else
            {
                summary += "Winner: " + p2.getPlayer() + " heuristic " + p2.getHeuristic() + "\n";

                if (p2.useMinMax())
                {
                    summary += " minmax made: ";
                }
                else
                {
                    summary += " alfa beta made: ";
                }

                summary += p2.getNumOfMoves() + "moves \n";
                summary += "Time " + p2.getTime() + "\n";

                summary += "Loser: " + p1.getPlayer() + " heuristic " + p1.getHeuristic() + "\n";

                if (p1.useMinMax())
                {
                    summary += " minmax made: ";
                }
                else
                {
                    summary += " alfa beta made: ";
                }

                summary += p1.getNumOfMoves() + "moves \n";
                summary += "Time " + p1.getTime() + "\n";
            }

            return(summary);
        }