Пример #1
27
 public UnoBot(UnoGame game, UnoBehavior behavior, int index)
 {
     this.Hand = new List<UnoCard>(7);
     this.game = game;
     this.rand = new Random();
     this.Index = index;
     this.behavior = behavior;
 }
Пример #2
0
 public UnoBot(UnoGame game, UnoBehavior behavior, int index)
 {
     this.Hand     = new List <UnoCard>(7);
     this.game     = game;
     this.rand     = new Random();
     this.Index    = index;
     this.behavior = behavior;
 }
Пример #3
0
        private static void RunUnoBots(int numOfGames, UnoBehavior[] behaviors)
        {
            int numOfPlayers = behaviors.Length;

            int[]     wins             = new int[numOfPlayers];
            int       totalMoves       = 0;
            long      totalOfAllRunsMS = 0;
            Stopwatch allGamesSw       = new Stopwatch();
            Stopwatch eachGameSw       = new Stopwatch();

            allGamesSw.Start();
            for (int i = 0; i < numOfGames; i++)
            {
                UnoGame game = new UnoGame(behaviors);

                eachGameSw.Restart();
                int winner = game.Play();
                eachGameSw.Stop();

                wins[winner]++;

                totalOfAllRunsMS += eachGameSw.ElapsedMilliseconds;
                totalMoves       += game.NumOfTurns;
            }
            allGamesSw.Stop();

            System.Console.WriteLine("Total games: " + numOfGames + "\n");

            Array.Sort(wins);
            for (int i = 0; i < wins.Length; i++)
            {
                double winRate = (double)wins[i] / (double)numOfGames;
                System.Console.WriteLine("Player (" + Utility.GetBehaviorString(behaviors[i]) + ") " + i + " wins: " + wins[i] + " | " + (winRate * 100) + "%");
            }

            System.Console.WriteLine();

            double avgMovesPerRound = (double)totalMoves / (double)numOfGames;
            double avgTimePerRound  = (double)totalOfAllRunsMS / (double)numOfGames;

            System.Console.WriteLine("Avg moves per round: " + avgMovesPerRound);
            System.Console.WriteLine("Total time: " + allGamesSw.ElapsedMilliseconds + " ms");
            System.Console.WriteLine("Avg time per round: " + avgTimePerRound + " ms\n");
        }
Пример #4
0
 public UnoBot(UnoGame game, int index)
     : this(game, UnoBehavior.Passive, index)
 {
 }
Пример #5
0
        static void Main(string[] args)
        {
            string input = string.Empty;
            UnoGame ugame = null;

            while (string.IsNullOrEmpty(input) || input.First() != 'q')
            {
                System.Console.Write("Provide an option: ");

                input = Console.ReadLine().ToLower();

                System.Console.WriteLine("");

                switch (input.First())
                {
                    case 'c':
                        if (game == null || robot == null)
                        {
                            game = new SolitaireGame();
                            robot = new SolitaireBot(game);
                        }

                        robot.Step();
                        break;
                    case 'g':
                        game = new SolitaireGame();
                        robot = new SolitaireBot(game);

                        System.Console.WriteLine("Starting setup: ");
                        game.DisplayState();

                        System.Console.WriteLine("Robot going to work...\n\n");

                        RunSolitaireRobot(1);

                        System.Console.WriteLine("Ending setup: ");
                        game.DisplayState();
                        break;
                    case 's':
                        int totalRounds = GetIntInput("Number of rounds: ", 100);
                        System.Console.WriteLine();
                        RunSolitaireRobot(totalRounds);
                        break;
                    case 'u':
                        {
                            int numOfPlayers = GetIntInput("Number of players: ", 4);
                            UnoBehavior[] behaviors = GetPlayerBehaviors(numOfPlayers);
                            int numOfGames = GetIntInput("Number of games: ", 100);

                            System.Console.WriteLine();

                            RunUnoBots(numOfGames, behaviors);
                            break;
                        }
                    case 'o':
                        if (ugame == null)
                        {
                            int numOfPlayers = GetIntInput("Number of players: ", 4);
                            UnoBehavior[] behaviors = GetPlayerBehaviors(numOfPlayers);
                            ugame = new UnoGame(behaviors);
                            ugame.SetupPlay();

                            System.Console.WriteLine("Game Setup: ");
                            ugame.DisplayState();
                            System.Console.WriteLine("Game Starting... \n");
                        }

                        ugame.Step();
                        ugame.DisplayState();
                        break;
                }
            }
        }
Пример #6
0
        private static void RunUnoBots(int numOfGames, UnoBehavior[] behaviors)
        {
            int numOfPlayers = behaviors.Length;
            int[] wins = new int[numOfPlayers];
            int totalMoves = 0;
            long totalOfAllRunsMS = 0;
            Stopwatch allGamesSw = new Stopwatch();
            Stopwatch eachGameSw = new Stopwatch();

            allGamesSw.Start();
            for (int i = 0; i < numOfGames; i++)
            {
                UnoGame game = new UnoGame(behaviors);

                eachGameSw.Restart();
                int winner = game.Play();
                eachGameSw.Stop();

                wins[winner]++;

                totalOfAllRunsMS += eachGameSw.ElapsedMilliseconds;
                totalMoves += game.NumOfTurns;
            }
            allGamesSw.Stop();

            System.Console.WriteLine("Total games: " + numOfGames + "\n");

            Array.Sort(wins);
            for (int i = 0; i < wins.Length; i++)
            {
                double winRate = (double)wins[i] / (double)numOfGames;
                System.Console.WriteLine("Player (" + Utility.GetBehaviorString(behaviors[i]) + ") " + i + " wins: " + wins[i] + " | " + (winRate * 100) + "%");
            }

            System.Console.WriteLine();

            double avgMovesPerRound = (double)totalMoves / (double)numOfGames;
            double avgTimePerRound = (double)totalOfAllRunsMS / (double)numOfGames;

            System.Console.WriteLine("Avg moves per round: " + avgMovesPerRound);
            System.Console.WriteLine("Total time: " + allGamesSw.ElapsedMilliseconds + " ms");
            System.Console.WriteLine("Avg time per round: " + avgTimePerRound + " ms\n");
        }
Пример #7
0
 public UnoBot(UnoGame game, int index) : this(game, UnoBehavior.Passive, index)
 {
 }
Пример #8
0
        static void Main(string[] args)
        {
            string  input = string.Empty;
            UnoGame ugame = null;

            while (string.IsNullOrEmpty(input) || input.First() != 'q')
            {
                System.Console.Write("Provide an option: ");

                input = Console.ReadLine().ToLower();

                System.Console.WriteLine("");

                switch (input.First())
                {
                case 'c':
                    if (game == null || robot == null)
                    {
                        game  = new SolitaireGame();
                        robot = new SolitaireBot(game);
                    }

                    robot.Step();
                    break;

                case 'g':
                    game  = new SolitaireGame();
                    robot = new SolitaireBot(game);

                    System.Console.WriteLine("Starting setup: ");
                    game.DisplayState();

                    System.Console.WriteLine("Robot going to work...\n\n");

                    RunSolitaireRobot(1);

                    System.Console.WriteLine("Ending setup: ");
                    game.DisplayState();
                    break;

                case 's':
                    int totalRounds = GetIntInput("Number of rounds: ", 100);
                    System.Console.WriteLine();
                    RunSolitaireRobot(totalRounds);
                    break;

                case 'u':
                {
                    int           numOfPlayers = GetIntInput("Number of players: ", 4);
                    UnoBehavior[] behaviors    = GetPlayerBehaviors(numOfPlayers);
                    int           numOfGames   = GetIntInput("Number of games: ", 100);

                    System.Console.WriteLine();

                    RunUnoBots(numOfGames, behaviors);
                    break;
                }

                case 'o':
                    if (ugame == null)
                    {
                        int           numOfPlayers = GetIntInput("Number of players: ", 4);
                        UnoBehavior[] behaviors    = GetPlayerBehaviors(numOfPlayers);
                        ugame = new UnoGame(behaviors);
                        ugame.SetupPlay();

                        System.Console.WriteLine("Game Setup: ");
                        ugame.DisplayState();
                        System.Console.WriteLine("Game Starting... \n");
                    }

                    ugame.Step();
                    ugame.DisplayState();
                    break;
                }
            }
        }