Example #1
0
        private MahjongGameState StateUpdater(MahjongGameState state, MahjongMove m)
        {
            MahjongGameState s = state.Clone() as MahjongGameState;

            s.ApplyMove(m);

            return(s);
        }
Example #2
0
        public static void Main(string[] args)
        {
            // Setup output information
            string fout      = "Game " + DEPTH + "-" + SAMPLES + ".txt";
            string header    = "Minimax Search Depth: " + DEPTH + "\nMonte Carlo Sample Size: " + SAMPLES + "\n\nFinal Scores\n------------\n";
            string results   = "";
            string game_text = "";

            // Create the game
            MahjongGameState state = new MahjongGameState();

            // Add the AI
            state.PlayerLeft(0, new NaiveAI(0));
            state.PlayerLeft(1, new GreedyAI(1));
            state.PlayerLeft(2, new MiniMaxAI(2, DEPTH));
            state.PlayerLeft(3, new MonteCarloAI(3, SAMPLES));

            int i = 4;

            // Run the game to completion
            while (!state.GameFinished)
            {
                MahjongAIPlayer ai   = state.GetPlayer(state.SubActivePlayer) as MahjongAIPlayer;
                MahjongMove     move = ai.AI.GetNextMove(state);

                Log(PlayerToName(state.SubActivePlayer) + " " + move + ".\n", ref game_text);

                if (--i == 0)
                {
                    Log("\n", ref game_text);
                    i = 4;
                }

                if (!state.ApplyMove(move))
                {
                    Log("An invalid move has been provided.\n", ref game_text);
                }

                if (state.HandFinished && !state.GameFinished)
                {
                    Print(state, ref game_text);
                    state.StartHand();
                }
            }

            // Output the final scores
            PrintLight(state, ref results);
            Print(state, ref game_text, true);

            File.WriteAllText(fout, header + results + "\nGame Log\n--------\n" + game_text);
            return;
        }
Example #3
0
 private MahjongGameState StateUpdater(MahjongGameState state, MahjongMove m)
 {
     state.ApplyMove(m);
     return(state);
 }