public void SetCellValue( int x, int y, TicTacToeCellValue cellValue) { _grid[x, y] = cellValue; }
public CellValueWithLocation( TicTacToeCellValue cellValue, TicTacToeLocation location) { _location = location; CellValue = cellValue; }
public Player( TicTacToeCellValue playerCellValue) { _playerCellValue = playerCellValue; if (_playerCellValue == TicTacToeCellValue.X) { _opposingCellValue = TicTacToeCellValue.O; } else { _opposingCellValue = TicTacToeCellValue.X; } }
public void IsWonShouldBeTrueForVerticalWin( int x, TicTacToeCellValue cellValue) { var board = new TicTacToeBoard(); board.SetCellValue(x, 0, cellValue); board.SetCellValue(x, 1, cellValue); board.SetCellValue(x, 2, cellValue); var winStatus = WinDetector.GetWinStatus(board); winStatus.IsWon.Should().BeTrue(); winStatus.WinMessage.Should().Be($"Column win for {cellValue} on column {x + 1}"); }
public void IsWonShouldBeTrueForHorizonalWin( int y, TicTacToeCellValue cellValue) { var board = new TicTacToeBoard(); board.SetCellValue(0, y, cellValue); board.SetCellValue(1, y, cellValue); board.SetCellValue(2, y, cellValue); var winStatus = WinDetector.GetWinStatus(board); winStatus.IsWon.Should().BeTrue(); winStatus.WinMessage.Should().Be($"Row win for {cellValue} on row {y + 1}"); }
public void SetCellValueShouldChangeCellValues( int x, int y, TicTacToeCellValue cellValue) { var board = new TicTacToeBoard(); board.SetCellValue(x, y, cellValue); board.GetCellValue(x, y).Should().Be(cellValue); board.SetCellValue(x, y, TicTacToeCellValue.Blank); board.GetCellValue(x, y).Should().Be(TicTacToeCellValue.Blank); AssertAllCellsAreBlank(board); }
private bool CheckPattern(int[][] pattern) { TicTacToeCellValue signToCheck = _board[pattern[0][0]][pattern[0][1]].Value; if (signToCheck == TicTacToeCellValue.Default) { return(false); } foreach (var cell in pattern) { if (signToCheck != _board[cell[0]][cell[1]].Value) { return(false); } } return(true); }
public void ShouldPickNextBlankSpace2( TicTacToeCellValue cellValue) { var grid = new string[] { "OXO", "---", "---", }; var board = new TicTacToeBoard(grid); var player = new Player(cellValue); player.MakeNextMove(board); board.GetCellValue(0, 1).Should().Be(cellValue); }
private static WinStatus GetRowWinStatus( TicTacToeCellValue cellValue, TicTacToeBoard board) { for (int y = 0; y < 3; y++) { var horizontalCells = board.GetHorizontalCells(y); if (horizontalCells[0].CellValue == cellValue && horizontalCells[1].CellValue == cellValue && horizontalCells[2].CellValue == cellValue) { var message = $"Row win for {cellValue} on row {y + 1}"; return(WinStatus.CreateAsWin(message)); } } return(WinStatus.CreateAsNoWin()); }
private static WinStatus GetColumnWinStatus( TicTacToeCellValue cellValue, TicTacToeBoard board) { for (int x = 0; x < 3; x++) { var verticalCells = board.GetVerticalCells(x); if (verticalCells[0].CellValue == cellValue && verticalCells[1].CellValue == cellValue && verticalCells[2].CellValue == cellValue) { var message = $"Column win for {cellValue} on column {x + 1}"; return(WinStatus.CreateAsWin(message)); } } return(WinStatus.CreateAsNoWin()); }
public bool TryMarkCell(int row, int cell, TicTacToeCellValue sign) { if (row < 0 || cell < 0 || row >= BOARD_SIZE || cell >= BOARD_SIZE) { return(false); } if (_board[row][cell].Value != TicTacToeCellValue.Default) { return(false); } _board[row][cell].Value = sign; ++_filledCellsCount; IsThereAWinner = CheckIfSomeoneWon(); return(true); }
public void ShouldMakeMiddleRowBlock( string inputRow, string expectedRow, TicTacToeCellValue cellValue) { var grid = new string[] { "---", inputRow, "---", }; var board = new TicTacToeBoard(grid); var player = new Player(cellValue); player.MakeNextMove(board); var stringBoard = board.GetStringBoard(); stringBoard[0].Should().Be("---"); stringBoard[1].Should().Be(expectedRow); stringBoard[2].Should().Be("---"); }
public void ShouldMakeDiagonalBlock1( string inputRow, string expectedRow, TicTacToeCellValue cellValue) { var grid = new string[] { inputRow[0] + "--", "-" + inputRow[1] + "-", "--" + inputRow[2], }; var board = new TicTacToeBoard(grid); var player = new Player(cellValue); player.MakeNextMove(board); var stringBoard = board.GetStringBoard(); stringBoard[0].Should().Be(expectedRow[0] + "--"); stringBoard[1].Should().Be("-" + expectedRow[1] + "-"); stringBoard[2].Should().Be("--" + expectedRow[2]); }
public BotPlayer(string name, TicTacToeCellValue sign) { Name = name; Sign = sign; }
public void SetCellValue( ILocation location, TicTacToeCellValue cellValue) { _grid[location.X, location.Y] = cellValue; }