示例#1
0
        public void WinnTextInitialization(Player player)
        {
            for (int i = 0; i < 5; i++)
            {
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Red;
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.WriteLine("Spieler " + player.Name + " Sie haben gewonnen!!! YEAHH!!!");
                Thread.Sleep(300);
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Spieler " + player.Name + " Sie haben gewonnen!!! YEAHH!!!");
                Thread.Sleep(300);
                Console.Clear();
                Console.ResetColor();
            }

            if (PlayerCollector.RePlay() == false)
            {
                Environment.Exit(0);
            }
            else
            {
                ConnectFourGame.Play();
            }
        }
示例#2
0
        public static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                // Display help
                Console.WriteLine("Program: Play connect four");
                Console.WriteLine("Usage:");
                Console.WriteLine("     Program <player one name> <player two name>");
                return(1);
            }

            // Play the game
            Console.WriteLine("Connect Four!");

            Player <ConnectFourToken> playerOne = GetPlayerForName(args[0], ConnectFourToken.X);
            Player <ConnectFourToken> playerTwo = GetPlayerForName(args[1], ConnectFourToken.O);

            const int width  = 7;
            const int height = 6;

            ConnectFourGame game = new ConnectFourGame(width, height, playerOne, playerTwo);

            Player <ConnectFourToken> winningPlayer = Play(game);

            Console.WriteLine(winningPlayer == null ? "Draw or AI fails to find solution!" : $"{winningPlayer.Name} wins!");
            Console.WriteLine(game.ToString());

            return(0);
        }
示例#3
0
        public static Player <ConnectFourToken> Play(ConnectFourGame game)
        {
            Player <ConnectFourToken> winningPlayer;

            do
            {
                Console.WriteLine($"Round #{game.RoundNumber}");

                Console.WriteLine(game.ToString());

                Move <ConnectFourToken> nextMove = game.CurrentPlayer.GetNextMove(game);

                if (nextMove == null)
                {
                    winningPlayer = null;
                    break;
                }

                Console.WriteLine(nextMove.ToString());

                game.TryMove(nextMove);
            } while (!game.IsGameOver(out winningPlayer));

            return(winningPlayer);
        }
示例#4
0
        public IMinimaxGame <ConnectFourToken> Clone()
        {
            ConnectFourGame clone = new ConnectFourGame(Width, Height, Players.Select(p => p.Clone()).ToArray());

            clone.Grid = Grid.Clone();
            clone._currentPlayerIndex = _currentPlayerIndex;
            clone.RoundNumber         = RoundNumber;

            return(clone);
        }
        public override Move <ConnectFourToken> GetNextMove(IBoardGame <ConnectFourToken> game)
        {
            ConnectFourGame clone = (ConnectFourGame)game.Clone();

            (Move <ConnectFourToken> nextMove, int _) = Minimax(
                moveAndPosition: (Move <ConnectFourToken> .Default, clone),
                depth: MinimaxDepth,
                alpha: int.MinValue,
                beta: int.MaxValue,
                currentPlayer: clone.CurrentPlayer,
                maximizingCurrentPlayer: true);

            if (!game.IsMoveAllowed(nextMove))
            {
                throw new InvalidOperationException();
            }

            return(nextMove);
        }
示例#6
0
        static void Main(string[] args)
        {
            SetWindowPosition(-7, 0, 1934, 1047);

            ConnectFourGame.Play();
        }