Beispiel #1
0
        static void Main(string[] args)
        {
            Board        b       = new Board();
            SantoriniNAN nn      = new SantoriniNAN();
            Player       player1 = new Player();

            player1.Pawns.Add(new Pawn(0, 0, 1));
            nn.TakeTurn(b, player1);


            PlaySantorini();
        }
Beispiel #2
0
        public static void PlaySantorini()
        {
            Program               p        = new Program();
            SantoriniQLearn       quintin1 = new SantoriniQLearn();
            SantoriniQLearn       quintin2 = new SantoriniQLearn();
            SantoriniPseudoRandom randy    = new SantoriniPseudoRandom(Rnd.Range(0, 5000));
            SantoriniUtilityAI    Ursa     = new SantoriniUtilityAI();
            SantoriniNAN          Nana     = new SantoriniNAN();

            WinRatio wins            = new WinRatio();
            WinRatio winsIncremental = new WinRatio();

            string ProgressBarMine = "";
            bool   printstuff      = false;
            //for (int i = 1; i < 1000000; i++)
            //{
            int  i             = 1;
            int  yx            = 0;
            bool doneTraining  = false;
            bool doneExploring = false;

            while (!doneTraining)
            {
                i++;
                Player player1 = new Player();
                player1.Pawns.Add(new Pawn(0, 0, 1));
                Player player2 = new Player();
                player2.Pawns.Add(new Pawn(2, 2, 2));
                Board b = new Board();
                int   timesINeedToWin             = 3;
                bool  ActivateIntelligentOpponent = false;
                //Visuals
                if (i % 1000 == 0)
                {
                    Console.Clear();
                    //quintin1.ExplorationChance--;
                    //if (doneExploring)
                    //{
                    //    quintin1.ExplorationChance = 0;
                    //    yx++;
                    //}
                    //if (yx > 7)
                    //{
                    //    doneTraining = true;
                    //}
                    //if (i%900000 == 0)
                    //{
                    //    quintin1.ExplorationChance = 0;
                    //}

                    ProgressBarMine += "\n \nPlayer1Wins: " + winsIncremental.Player1 + "\nPlayer2Wins: " + winsIncremental.Player2 + "\nNew Board States: " + MathF.Abs(winsIncremental.Draw - quintin1.Policies.Count);
                    Console.WriteLine(ProgressBarMine);
                    Console.WriteLine("Exploration chance: " + quintin1.ExplorationChance);

                    //Hvor mange nye stadier skal vi over før vi kan gå igang med at spille?
                    //if (MathF.Abs(winsIncremental.Draw - quintin1.Policies.Count) < 500000)
                    //{
                    //    ProgressBarMine += "\nsaving";
                    //    //p.SaveKnowledge(quintin1);
                    //    ProgressBarMine += "\n Done saving";


                    //    doneExploring = true;
                    //}

                    //     winsIncremental.Draw = quintin1.Policies.Count;
                    winsIncremental.Player2 = 0;
                    winsIncremental.Player1 = 0;
                    if (!ActivateIntelligentOpponent && winsIncremental.Player2 > 7600)
                    {
                        timesINeedToWin--;
                        if (timesINeedToWin == 0)
                        {
                            ActivateIntelligentOpponent = false;
                        }
                    }
                    //      quintin1.PrintEverything = true;
                    //      printstuff = true;
                }



                bool winner = false;
                while (winner == false)
                {
                    if (b.GetAvailableMoveForPlayer(player1).Count == 0)
                    {
                        winner = true;
                        //    Console.WriteLine("Player 2 killed player 1");
                        wins.Player2++;
                        winsIncremental.Player2++;
                        //if (ActivateIntelligentOpponent)
                        //{
                        //    quintin2.Reward(-1);
                        //}
                        //quintin1.Reward(-1);
                    }
                    else
                    {
                        b.MakeMove(Nana.TakeTurn(b, player1), player1.Pawns[0]);

                        if (printstuff)
                        {
                            b.DrawBoard();
                        }
                        foreach (Pawn item in player1.Pawns)
                        {
                            if (b.BoardState[item.X, item.Y, 0] == 3)
                            {
                                winner = true;
                                //             Console.WriteLine("Player 1 Climbed the tower");
                                wins.Player1++;
                                winsIncremental.Player1++;
                                if (ActivateIntelligentOpponent)
                                {
                                    quintin2.Reward(1);
                                }
                                quintin1.Reward(1);

                                break;
                            }
                        }
                    }
                    if (winner == false)
                    {
                        if (b.GetAvailableMoveForPlayer(player2).Count == 0)
                        {
                            winner = true;
                            //wins.Player1++;
                            //winsIncremental.Player1++;
                            //if (ActivateIntelligentOpponent)
                            //{
                            //    quintin2.Reward(10);
                            //}
                            //quintin1.Reward(1);

                            //        Console.WriteLine("Player 1 killed player 2");
                        }
                        else
                        {
                            //                      MAKE DET MOVE MOND!
                            if (doneExploring)
                            {
                                b.MakeMove(randy.TakeTurn(b.GetAvailableMoveForPlayer(player2), b), player2.Pawns[0]);
                            }
                            else
                            {
                                b.MakeMove(randy.TakeTurn(b.GetAvailableMoveForPlayer(player2), b), player2.Pawns[0]);
                            }

                            if (printstuff)
                            {
                                b.DrawBoard();
                            }
                            foreach (Pawn item in player2.Pawns)
                            {
                                if (b.BoardState[item.X, item.Y, 0] == 3)
                                {
                                    winner = true;
                                    //              Console.WriteLine("Player 2 climbed the tower!");
                                    wins.Player2++;
                                    winsIncremental.Player2++;

                                    quintin1.Reward(-1);
                                    if (ActivateIntelligentOpponent)
                                    {
                                        quintin2.Reward(-1);
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                //   b.DrawBoard();
            }

            Console.WriteLine("Player 1 Wins:" + wins.Player1);
            Console.WriteLine("Player 2 Wins:" + wins.Player2);
            Console.WriteLine("Board states known: " + quintin1.Policies.Count);
            Console.WriteLine("Press any key");
            //  p.SaveKnowledge(quintin1);
            Console.ReadKey();

            for (int hy = 0; hy < 1000; hy++)
            {
                Player player1 = new Player();
                player1.Pawns.Add(new Pawn(0, 0, 1));
                Player player2 = new Player();
                player2.Pawns.Add(new Pawn(2, 2, 2));
                Board b = new Board();
                Console.Clear();

                b.DrawBoard();
                Console.ReadKey();
                bool winner = false;
                while (winner == false)
                {
                    if (b.GetAvailableMoveForPlayer(player1).Count == 0)
                    {
                        winner = true;
                        //    Console.WriteLine("Player 2 killed player 1");
                        wins.Player2++;
                        winsIncremental.Player2++;

                        quintin1.Reward(10);
                    }
                    else
                    {
                        b.MakeMove(quintin1.TakeTurn(b, player1), player1.Pawns[0]);   //b.GetAvailableMoveForPlayer(player1), b); ; ;, player1.Pawns[0]);
                        b.DrawBoard();

                        foreach (Pawn item in player1.Pawns)
                        {
                            if (b.BoardState[item.X, item.Y, 0] == 3)
                            {
                                winner = true;
                                Console.WriteLine("Player 1 Climbed the tower");
                                wins.Player1++;
                                winsIncremental.Player1++;

                                quintin1.Reward(-1);

                                break;
                            }
                        }
                    }
                    if (winner == false)
                    {
                        if (b.GetAvailableMoveForPlayer(player2).Count == 0)
                        {
                            winner = true;
                            wins.Player1++;
                            winsIncremental.Player1++;

                            quintin1.Reward(-1);

                            Console.WriteLine("Player 1 killed player 2");
                        }
                        else
                        {
                            //                      MAKE DET MOVE MOND!
                            Console.WriteLine("Make Move Player :D");
                            PawnMove playermove = new PawnMove();


                            List <PawnMove> liste = b.GetAvailableMoveForPlayer(player2);
A:
                            int count = 0;
                            foreach (var item in liste)
                            {
                                Console.WriteLine(count + ": " + item.ToString());
                                count++;
                            }
                            int choose = int.Parse(Console.ReadLine());
                            try
                            {
                                b.MakeMove(liste[choose], player2.Pawns[0]);
                            }
                            catch (Exception)
                            {
                                goto A;
                            }


                            //b.MakeMove(quintin1.TakeTurn(b, player2), player2.Pawns[0]);
                            //b.DrawBoard();
                            //Console.ReadKey();

                            foreach (Pawn item in player2.Pawns)
                            {
                                if (b.BoardState[item.X, item.Y, 0] == 3)
                                {
                                    winner = true;
                                    Console.WriteLine("Player 2 climbed the tower!");
                                    wins.Player2++;
                                    winsIncremental.Player2++;


                                    break;
                                }
                            }
                        }
                    }
                }
                b.DrawBoard();
                Console.ReadLine();
            }
        }