Ejemplo 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);
        }
Ejemplo n.º 2
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);
        }