private void TestMovement(Movement movement, int expected) { MovementDeltaCalculator movementDeltaCalculator = new MovementDeltaCalculator(); AccessibleBoard board = new AccessibleBoard { AccessibleSize = SIZE }; int delta = movementDeltaCalculator.GetMovementDelta(board, movement); Assert.Equal(expected, delta); }
private void Validate(int blankIndex, List <Movement> expectedLegalMovements) { AccessibleBoard board = new AccessibleBoard { AccessibleSize = 3, AccessibleBlankIndex = blankIndex }; LegalMovesCalculator legalMovesCalculator = new LegalMovesCalculator(); List <Movement> legalMovements = legalMovesCalculator.GetLegalMoves(board); bool areEquivalent = (expectedLegalMovements.Count == legalMovements.Count) && !expectedLegalMovements.Except(legalMovements).Any(); Assert.True(areEquivalent); }
private void SuccessMove(AccessibleBoard board, Movement movement, int expectedBlankIndex, bool expectedIsSolved) { TileMover tileMover = GetTileMover(out TileMoverContext tileMoverContext); tileMoverContext.LegalMovesCalculator.Setup(lmc => lmc.GetLegalMoves(It.IsAny <Board>())).Returns(new List <Movement>() { movement }); bool moved = tileMover.TryMove(board, movement, out string error); Assert.True(moved); Assert.Equal(expectedBlankIndex, board.AccessibleBlankIndex); Assert.Equal(expectedIsSolved, board.AccessibleIsSolved); }
public void PlayOnceForSolvedBoard() { GameDriver gameDriver = GetGameDriver(out GameDriverContext gameDriverContext); AccessibleBoard board = new AccessibleBoard { AccessibleIsSolved = true }; GameFlow flow = gameDriver.Play(board); gameDriverContext.BoardRenderer.Verify(br => br.Render(It.IsAny <Board>()), Times.Once); gameDriverContext.IO.Verify(io => io.Clear(), Times.Once); gameDriverContext.IO.Verify(io => io.WriteLine(Match.Create <string>(b => b == RENDERED_BOARD), It.IsAny <int>()), Times.Once); gameDriverContext.IO.Verify(io => io.Read(It.IsAny <string>()), Times.Once); Assert.Equal(GameFlow.NEW_GAME, flow); }
public void SuccessMoveRight() { AccessibleBoard board = new AccessibleBoard { AccessibleTiles = ToTiles(new List <int?> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, null }), AccessibleBlankIndex = 15, AccessibleSize = 4, AccessibleTotalMisplacedTiles = 0, AccessibleIsSolved = true }; SuccessMove(board, Movement.RIGHT, 14, false); }
public void SuccessMoveLeft() { AccessibleBoard board = new AccessibleBoard { AccessibleTiles = ToTiles(new List <int?> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, null, 14 }), AccessibleBlankIndex = 14, AccessibleSize = 4, AccessibleTotalMisplacedTiles = 1, AccessibleIsSolved = false }; SuccessMove(board, Movement.LEFT, 15, true); }
private bool TryGetValueAt(int row, int column, out int?value, out string error) { AccessibleBoard board = new AccessibleBoard { AccessibleTiles = new List <Tile>() { new Tile(0), new Tile(1), new Tile(2), new Tile(null) }, AccessibleBlankIndex = 3, AccessibleSize = 2, AccessibleIsSolved = true, AccessibleTotalMisplacedTiles = 0 }; BoardValueFetcher boardValueFetcher = new BoardValueFetcher(); bool found = boardValueFetcher.TryGetValueAt(board, row, column, out value, out error); return(found); }
public void StopPlayingWhenFlowIsNotKeepPlaying() { GameDriver gameDriver = GetGameDriver(out GameDriverContext gameDriverContext); AccessibleBoard board = new AccessibleBoard { AccessibleIsSolved = false }; gameDriverContext.ActionReader.Setup(ar => ar.ReadAction(It.IsAny <Board>())).Returns("some action"); gameDriverContext.ActionApplier.Setup(aa => aa.ApplyAction(It.IsAny <Board>(), It.IsAny <string>())).Returns(GameFlow.END_GAME); GameFlow flow = gameDriver.Play(board); gameDriverContext.BoardRenderer.Verify(br => br.Render(It.IsAny <Board>()), Times.Once); gameDriverContext.IO.Verify(io => io.Clear(), Times.Once); gameDriverContext.IO.Verify(io => io.WriteLine(Match.Create <string>(b => b == RENDERED_BOARD), It.IsAny <int>()), Times.Once); gameDriverContext.ActionReader.Verify(ar => ar.ReadAction(It.IsAny <Board>()), Times.Once); gameDriverContext.ActionApplier.Verify(aa => aa.ApplyAction(It.IsAny <Board>(), It.IsAny <string>()), Times.Once); Assert.Equal(GameFlow.END_GAME, flow); }