public void NoughtsWinHorizontallyOnCompleteBoard() { var cells = CommonMethods.CreateMockBoardCells( "OOO" + "XOX" + "XXO" ); var status = _boardWinningRules.CheckForWinner(cells.Object); Assert.AreEqual(BoardStatus.NoughtsWins, status); }
/// <summary> /// Allow the placing of a piece on the board, subject to certain conditions. It then uses /// both IBoardWinningRules and IBoardCells to work out the current state of the board /// </summary> /// <param name="piece">Type of piece to place on board - Nought or Cross</param> /// <returns>State of the board after applyin the piece - either having a winner (and which one), full or still playable</returns> public BoardStatus AssignPieceToBoard(PieceType piece) { if (_boardCells.NoSpacesLeft()) { throw new Exception("You can't assign a piece to a full board"); } int randomIndex; while (true) { randomIndex = _random.Next(_boardSize); if (_boardCells.GetCell(randomIndex) == PieceType.Neither) { break; } } _boardCells.SetCell(randomIndex, piece); var winner = _boardWinningRules.CheckForWinner(_boardCells); if (winner.HasValue) { return(winner.Value); } if (_boardCells.NoSpacesLeft()) { return(BoardStatus.Full); } return(BoardStatus.StillPlayable); }