Esempio n. 1
0
    public static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");

        var positions = Enumerable.Range(1, ConnectFourBoard.CellAmount).Select(_ => (ConnectFourPiece)ConnectFourPiece.Empty).ToArray();
        var board     = new ConnectFourBoard(positions, (ConnectFourPiece)ConnectFourPiece.Black);

        var(human, computer) = SelectSide();

        var moveNumber = 0;

        while (board.GetLegalMoves().Any())
        {
            Console.Clear();
            Console.WriteLine($"step#{moveNumber}");
            Console.WriteLine(board.ToString());

            var location = board.GetTurn() == human
                ? DoHumanMove(board, human)
                : DoComputerMove(board);

            Console.WriteLine($"the move is to put {board.GetTurn()} into column {location}");

            moveNumber++;
            board = board.Move(location) as ConnectFourBoard;
        }

        PrintResult(moveNumber, board, human);
    }
Esempio n. 2
0
 private static void PrintResult(int moveNumber, ConnectFourBoard board, ConnectFourPiece human)
 {
     Console.Clear();
     Console.WriteLine($"After {moveNumber} steps");
     Console.WriteLine(board.ToString());
     if (board.IsWin())
     {
         var winnerName = board.GetTurn() == human ? "computer" : "human";
         Console.WriteLine($"{winnerName} wins!");
     }
     else
     {
         Console.WriteLine("It's a draw!");
     }
 }