Example #1
0
        public override string ToString()
        {
            // What state do we want to show?
            // - Current cards in each hand
            // - Current player turn
            // - Cards played in current trick
            // - Trick counts by player
            StringBuilder sb = new StringBuilder();

            for (int player = 0; player < 4; player++)
            {
                if (CurrentPlayerTurn == player)
                {
                    sb.Append($"[{player}] ");
                }
                else
                {
                    sb.Append($" {player}  ");
                }
                sb.AppendLine(TichuCard.PrintCardsSortedBySuit(Players[player].Cards));
            }

            sb.AppendLine(string.Join(" ", _currentTrick.Select(play => play.ToString())));
            sb.AppendLine(string.Join(" ", Evaluate()));
            return(sb.ToString());
        }
Example #2
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);
            }
        }