Esempio n. 1
0
        static void PlayGame(System.IO.StreamWriter writer)
        {
            Game g = new Game()
            {
                Rows = 6,
                Columns = 7,
                PiecesToWin = 4,
                TimeLimitSeconds = 30
            };

            g.Initialize();

            Player p1 = new MinimaxPlayer(Players.Black, Players.Red, "MINIMAX (1)");
            p1.SetGameInfo(g.Rows, g.Columns, g.PiecesToWin, 0, g.TimeLimitSeconds);

            Player p2 = new Player(Players.Red, Players.Black, "SIMPLE (2)");
            p2.SetGameInfo(g.Rows, g.Columns, g.PiecesToWin, 1, g.TimeLimitSeconds);

            GameValueCalculator calc = new GameValueCalculator(g);

            GameResult result = GameResult.InProgress;
            while (result == GameResult.InProgress)
            {
                int move = p1.GetNextMove();
                g.AcceptMove(p1.ID, move);
                result = calc.EvaluateGameState();
                p2.NoteOpponentsMove(move);

                if (result == GameResult.WinBlack || result == GameResult.WinRed) break;

                move = p2.GetNextMove();
                g.AcceptMove(p2.ID, move);
                result = calc.EvaluateGameState();
                p1.NoteOpponentsMove(move);
            }

            Console.WriteLine(string.Format(" --- {0} --- ", result));
            g.DisplayBoard();

            writer.WriteLine(string.Format(" --- {0} --- ", result));
            g.DisplayBoard(writer);
        }
Esempio n. 2
0
 int UTILITY(Game game)
 {
     GameValueCalculator calc = new GameValueCalculator(game);
     return calc.CalculateValues(_max).NormalizedValue;
 }
Esempio n. 3
0
        bool TERMINAL_TEST(Game game, int depth)
        {
            if (_stopwatch.Elapsed.Seconds > (game.TimeLimitSeconds - 2)) return true;

            if (depth >= MAX_DEPTH) return true;

            GameValueCalculator calc = new GameValueCalculator(game);
            if (calc.IsGameComplete()) return true;

            return false;
        }