Example #1
0
        public static void Run(int numGames)
        {
            Random random = new Random();

            int[] cumulativeTrickCounts            = new int[4]; // [playerId]
            IPlayGenerator <Play>[] playGenerators = new IPlayGenerator <Play> [4];
            //playGenerators[0] = new MultiThreadedMcts<Play>(100000, 50, random, 8);
            playGenerators[0]  = new Mcts <Play>(10000, 50, random);
            playGenerators[1]  = new RandomPlayGenerator <Play>();
            playGenerators[2]  = new HighestCardPlayGenerator();
            playGenerators[3]  = new HighestCardPlayGenerator();
            Logger.Log.Enabled = true;
            for (int gameNumber = 0; gameNumber < numGames; gameNumber++)
            {
                var gameState = TichuGameRunHarness.SetupFourPlayerGame(random);

                if (true)
                {
                    Logger.Log.WriteLine("Starting cards:");
                    for (int i = 0; i < 4; i++)
                    {
                        Logger.Log.WriteLine($"Player {i} {TichuCard.PrintCardsSortedBySuit(gameState.Players[i].Cards)}");
                    }
                }
                while (true)
                {
                    gameState.SetPointOfViewPlayer(gameState.CurrentPlayerTurn);
                    Play play = playGenerators[gameState.CurrentPlayerTurn].FindPlay(gameState);
                    Logger.Log.WriteLine($"Player {play.Player} played {play.Cards[0].ToString()}");
                    gameState.CommitPlay(play);
                    if (gameState.GameOver())
                    {
                        break;
                    }

                    if (gameState.PlayedCards.Count % 4 == 0)
                    {
                        Logger.Log.WriteLine("----");
                    }
                }

                var scores = gameState.Evaluate();
                for (int i = 0; i < 4; i++)
                {
                    cumulativeTrickCounts[i] += (int)scores[i];
                }

                Console.WriteLine($"Tricks: {scores[0]} {scores[1]} {scores[2]} {scores[3]} ");
            }

            string header = string.Format("{0, 6}{1, 10}{2, 10}", "Player", "Tricks", "Average");

            Console.WriteLine(header);

            for (int i = 0; i < 4; i++)
            {
                string output = string.Format("{0, 6}{1, 10}{2, 10:N1}", i, cumulativeTrickCounts[i], (double)cumulativeTrickCounts[i] / numGames);
                Console.WriteLine(output);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            string game = "";

            if (args.Length > 0)
            {
                game = args[0];
            }

            if (game.Equals("6nimmt"))
            {
                SixNimmtHarness.Run(1);
            }
            else if (game.Equals("6nimmthelp", StringComparison.OrdinalIgnoreCase))
            {
                SixNimmtSuggestMoveHarness.Run();
            }
            else if (game.Equals("tichu"))
            {
                TichuGameRunHarness.Run(1);
            }

            // TicTacToeHarness.Run(100);
            // GameRunHarness.Run(100);

            //int i = 7462;
            // for (int i = 1; i < 2000000; i++)
            // {
            //     using (StreamReader reader = File.OpenText($@"c:\repro\tichuhands\{i}.txt"))
            //     {
            //         var game = GameParser.ParseGame(reader);
            //         //Console.WriteLine($"{i}.txt {game.Hands.Count} games");
            //     }
            // }
            // int numGames = 1;
        }