public void CanPlayDoublePieceFromCoord() { var board = builder.FromTypeGrid("0101 1101 1100 1110"); foreach (var coord in Coord.SquareRange(c00, 2)) { var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s2); simulator.Simulate(); Assert.Pass(); } }
public void NewPieceHasExpectedType() { var board = builder.FromTypeGrid("10 21"); foreach (var coord in board.AllCoords) { var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1); simulator.Simulate(); var actions = simulator.GetMove().consequences; var newPieceAction = actions.First(IsNewPieceAction) as NewPieceAction; Assert.AreEqual(t0, newPieceAction.newPiece.type); } }
public void NotValidMoveDetected() { var board = builder.FromTypeGrid("10 20"); foreach (var coord in new Coord[] { c10, c11 }) { var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1); simulator.Simulate(); Assert.IsFalse(simulator.IsMovePossible()); Assert.Throws(typeof(InvalidGameOperationException), new TestDelegate(() => { simulator.GetMove(); })); } }
public void BoardIsUntouched() { var board = builder.FromTypeGrid("1020 1201 2201 0021"); var backup = board.Clone(); Assert.IsTrue(board.Matches(backup)); foreach (var coord in board.AllCoords) { var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1); simulator.Simulate(); Assert.IsTrue(board.Matches(backup)); } }
public void OnlyOneNewPieceAdded() { // all coords have moves var board = builder.FromTypeGrid("12 01"); foreach (var coord in board.AllCoords) { var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1); simulator.Simulate(); var actions = simulator.GetMove().consequences; var newPieceAction = actions.Where(IsNewPieceAction); Assert.AreEqual(1, newPieceAction.Count()); } }
void ProcessClickedCoord(Coord coord) { coord = GetBaseCoord(coord); var simulator = MoveSimulator.FromCoord(board, coord, Game.NextPieceIfPlaying(coord)); simulator.Simulate(); if (simulator.IsMovePossible()) { Execute(simulator.GetMove()); } else { DisplayObstacles(simulator.Obstacles()); } }
public void CompactsIfNeeded() { var board = builder.FromTypeGrid("01 00"); var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3)); var simulator = MoveSimulator.FromCoord(board, c11, game.NextPieceIfPlaying(new PotentialMove(c11, board.Orientation))); simulator.Simulate(); Assert.IsTrue(simulator.IsMovePossible()); var actions = simulator.GetMove().consequences; Assert.AreEqual(1, actions.Count(IsCompactAction)); var compactAction = actions.First(IsCompactAction) as CompactAction; Assert.AreEqual(c00, compactAction.coord); Assert.IsTrue(piece_t0_s2.Matches(compactAction.bigPiece)); }
public void StartsAndEndsInCorrectOrientation() { var board = builder.FromTypeGrid("10 21"); for (int i = 0; i < 4; i++) { board.RotateLeft(); foreach (var coord in board.AllCoords) { var simulator = MoveSimulator.FromCoord(board, coord, piece_t0_s1); simulator.Simulate(); var actions = simulator.GetMove().consequences; var expected = OrientateAction.Get(board.Orientation); Assert.AreEqual(expected, actions.First(), "first action orientates in board's current orientation"); Assert.AreEqual(expected, actions.Last(), "last action orientates in board's current orientation"); } } }
public void FallActionsStartFromBottom() { var board = builder.FromTypeGrid("0100 0200 1212 2021"); var game = new Game(board, GameRules.ClassicRules, PieceType.GetRange(0, 3)); var simulator = MoveSimulator.FromCoord(board, c10, game.NextPieceIfPlaying(new PotentialMove(c10, board.Orientation))); simulator.Simulate(); Assert.IsTrue(simulator.IsMovePossible()); var move = simulator.GetMove(); var actions = move.consequences; var fallActions = actions.Where(IsFallAction); Assert.IsNotEmpty(fallActions); var arrActions = fallActions.ToArray(); Assert.AreEqual(c11, (arrActions[0] as FallAction).coord); Assert.AreEqual(c12, (arrActions[1] as FallAction).coord); Assert.AreEqual(c13, (arrActions[2] as FallAction).coord); }