Exemplo n.º 1
0
        public void CheckLocationIsTaken(int x, int y)
        {
            var board = new Board();

            board.AddMove(Tuple.Create(2, 2));
            board.AddMove(Tuple.Create(1, 1));
            Boolean isItTaken = board.IsLocationTaken(Tuple.Create(x, y));

            Assert.True(isItTaken);
        }
Exemplo n.º 2
0
        public void CheckWinCondidtionDiagonal() //only works if board size is 3
        {
            var board = new Board();

            board.AddMove(Tuple.Create(2, 2));
            board.AddMove(Tuple.Create(1, 1));
            board.AddMove(Tuple.Create(3, 3));
            var result = Board.DidUserWin();

            Assert.True((result));
        }
Exemplo n.º 3
0
        public void FindingCorrectFreeSpace()
        {
            var board = new Board();

            board.AddMove(Tuple.Create(2, 2));
            board.AddMove(Tuple.Create(1, 1));
            var compTurn  = new ComputerMoves();
            var freeSpace = ComputerMoves.FindAvailableSpace(board);

            Assert.Equal(Tuple.Create(1, 2), freeSpace);
        }
Exemplo n.º 4
0
        public void IsThisPlaceTaken(int x, int y)
        {
            var board   = new Board();
            var allowed = board.IsLocationTaken(Tuple.Create(x, y));

            board.AddMove(Tuple.Create(x, y), true);
            Assert.Equal(2, board.Locations[x - 1, y - 1]);
            var notAllowed = board.IsLocationTaken(Tuple.Create(x, y));

            Assert.False(allowed);
            Assert.True(notAllowed);
        }
Exemplo n.º 5
0
        public void CheckBoardIsCorrectAfterMove(int x, int y, int loc00, int loc01, int loc02, int loc10, int loc11,
                                                 int loc12, int loc20, int loc21, int loc22)
        {
            var board = new Board();

            board.AddMove(Tuple.Create(x, y), false);
            var result = board.Locations;

            Assert.Equal(result[0, 0], loc00);
            Assert.Equal(result[0, 1], loc01);
            Assert.Equal(result[0, 2], loc02);
            Assert.Equal(result[1, 0], loc10);
            Assert.Equal(result[1, 1], loc11);
            Assert.Equal(result[1, 2], loc12);
            Assert.Equal(result[2, 0], loc20);
            Assert.Equal(result[2, 1], loc21);
            Assert.Equal(result[2, 2], loc22);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            var board = new Board();

            while (board.Status().Equals(BoardStatus.InProgress))
            {
                try
                {
                    Console.Write("Enter next move (x y): ");
                    var xy = Array.ConvertAll(Console.ReadLine().Split(' ').ToArray(), s => int.Parse(s.Trim()));

                    board.AddMove(xy[0], xy[1]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                DisplayBoard(board);
            }

            Console.WriteLine($"{board.Winner.DisplayName} wins!");

            Console.ReadLine();
        }