public void Test() { IBoard board = new Board(4, 12); byte[] cells = new byte[board.Width * board.Height]; for (int i = 0; i < board.Height; i += 3) { cells[2 + i * board.Width] = 1; } board.SetCells(cells); DisplayBoard(board); Console.ReadLine(); board.LeftGravity(); DisplayBoard(board); int buriedHoles = BoardHelper.GetBuriedHolesForColumn(board, 1); int holeDepth = BoardHelper.GetHoleDepthForColumn(board, 1); int allWells = BoardHelper.GetAllWellsForColumn(board, 1); int blockades = BoardHelper.GetBlockadesForColumn(board, 1); Console.WriteLine(); Console.WriteLine("{0} {1} {2} {3}", buriedHoles, holeDepth, allWells, blockades); }
static void Main(string[] args) { try { if (TurtleAppOptions.IsHelp(args)) { MainHelpScreen.Screen.WriteScreen(); } else { var options = ConverterHelper.ConvertToTurtleAppOptions(args); var boar = FileHelper.ImportSetting(options.PathSetting); var actions = FileHelper.ImportActions(options.PathActions); var result = BoardHelper.NextListActionResult(actions, boar); ListResultScreen.Screen.WriteScreen(result); } } catch (ListMessageException ex) when(ex.Errors?.Count > 1) { ListMessageErrorScreen.Screen.WriteScreen(ex.Errors); } catch (MessageException ex) { MessageErrorScreen.Screen.WriteScreen(ex.Message); } catch { UnexpectedErrorScreen.Screen.WriteScreen(); } Console.ReadLine(); }
public void PawnBackwardsFail() { //Setup var board = new Board { Top = Side.White, Bottom = Side.Black }; var grid = BoardHelper.GetEmptyBoard(); var row1 = BoardHelper.GetEmptyRow(); var pawn = new Peice { Type = PeiceType.Pawn, Side = Side.White, X = 0, Y = 0, HasMoved = true }; row1[1] = pawn; grid[0] = row1; board.SetGrid(grid); Assert.False(Pawn.CanMove(board, pawn, 0, -1).Success); }
/* * Returns ArrayList of Move of all available moves * */ static HashSet <Move> getAvailableMoves(Board board) { HashSet <Move> set = new HashSet <Move>(); for (int i = 0; i < board.positions.Length; i++) { for (int j = 0; j < board.positions[i].Length; j++) { if ((board.xPieces > 0 && board.turn == Board.PlayerTurn.X_TURN) || (board.oPieces > 0 && board.turn == Board.PlayerTurn.O_TURN)) { //Check if enough pieces if (board.positions[i][j] == 0) //Then check if space is free { set.Add(new Move(i, j, MoveType.PLACE)); } } else if (board.positions[i][j] == getPieceNumber(board.turn)) { ArrayList positions = BoardHelper.getInstance().getMovePositions(board, i, j); //can remove if (positions.Count == 0) { set.Add(new Move(i, j, MoveType.REMOVE)); } else //add all move positions to set { foreach (Vector2 vector in positions) { set.Add(new Move(new Vector2(i, j), vector)); } } } } } return(set); }
public void CastleMoveFail() { //Setup var board = new Board { Top = Side.White, Bottom = Side.Black }; var grid = BoardHelper.GetEmptyBoard(); var row1 = BoardHelper.GetEmptyRow(); var rook = new Peice { Type = PeiceType.Castle, X = 0, Y = 0 }; row1[0] = rook; grid[0] = row1; board.SetGrid(grid); Assert.False(Castle.CanMove(board, rook, 0, 0)); Assert.False(Castle.CanMove(board, rook, -1, 0)); Assert.False(Castle.CanMove(board, rook, 8, 0)); Assert.False(Castle.CanMove(board, rook, 7, 1)); Assert.False(Castle.CanMove(board, rook, 0, -1)); Assert.False(Castle.CanMove(board, rook, 0, 8)); }
public void TestInitialize() { var dice = new[] { new Die(), new Die() }; var board = BoardHelper.GetBoard(); _player = new Player("Car", dice, board); }
public void GetLargestNumberManySolved() { var hexas = new List <Hexa> { new Hexa(1) { PossibleNumbers = new List <int> { 1, 2, 3 } }, new Hexa(2) { PossibleNumbers = new List <int> { 4 } }, new Hexa(2) { PossibleNumbers = new List <int> { 5 } } }; Assert.AreEqual(5, BoardHelper.GetLargestNumber(hexas)); }
public async Task TesInvalidWord() { var game = new Game { Player01 = new GamePlayer { UserName = "******" }, Player02 = new GamePlayer { UserName = "******" }, Board = BoardHelper.GenerateBoard(15, "Standard"), Language = Helper.Language }; // Previous moves TOTEM, HATE game.PlayMoves = new List <PlayMove> { Helper.PlayTotem(), Helper.PlayHate() }; // Played RIT not a word in dictionary var letters = Helper.PlayRit(); var res = await game.ValidateMove(letters.ToArray(), lexiconService); Assert.AreEqual("Invalid words", res.Result); }
IEnumerator IERotateCounterClockwise() { if (chosenParent.childCount == 0 || isRotating) { yield break; } yield return(StartCoroutine(RotateChosenParent(120))); List <Vector2> indexList = new List <Vector2>(); for (int i = 0; i < 3; i++) { indexList.Add(chosenObjects[i].Index); } var tempObj = chosenObjects; for (int i = 0; i < 3; i++) { BoardCells[(int)indexList[(i + 1) % 3].x][(int)indexList[(i + 1) % 3].y].HexObject = tempObj[i]; chosenObjects[i].Index = indexList[(i + 1) % 3]; } for (int i = 0; i < 3; i++) { CollectMatched(BoardHelper.GetAllMatchedCells(BoardCells, chosenObjects[i].Index)); } CheckAndSetCollectableObjects(); }
public void PawnPass() { //Setup var board = new Board() { Top = Side.White, Bottom = Side.Black }; var grid = BoardHelper.GetEmptyBoard(); var row1 = BoardHelper.GetEmptyRow(); var pawn = new Peice { Type = PeiceType.Pawn, Side = Side.White, X = 0, Y = 0 }; row1[0] = pawn; grid[0] = row1; board.SetGrid(grid); Assert.True(Pawn.CanMove(board, pawn, 0, 1).Success); Assert.True(Pawn.CanMove(board, pawn, 0, 2).Success); }
public void GetNumberOfCombinationsNewBoard() { var board = new Board(); var expected = 61 * 9; Assert.AreEqual(expected, BoardHelper.NumberOfCombinations(board)); }
public Move undo() { if (previousBoardsIndex == 0) { throw new UnityException("Cannot undo more"); } Board newerBoard = (Board)previousBoards[previousBoardsIndex]; previousBoards.RemoveAt(previousBoardsIndex); previousBoardsIndex--; Board oldBoard = (Board)previousBoards[previousBoardsIndex]; Move m = BoardHelper.getInstance().compareBoards(newerBoard, oldBoard); //move(m, false); board = oldBoard; Debug.Log("Board after undo: \n" + board); undoCounter = 0f; if (!piecePlaceSound.isPlaying) { piecePlaceSound.Play(); } return(m); }
public void DeleteUnitAt(Vector2Int pos) { if (units.ContainsKey(pos)) { deletedUnits.Add(units[pos]); BoardHelper.DeleteUnitAt(pos, ref units); } }
public void TestInitialize() { var dice = new[] { new Die(), new Die() }; var board = BoardHelper.GetBoard(); _player = new Player("Car", dice, board); Assert.AreEqual(0, _player.Cash); }
public void GetNumberOfCombinationsOneSolved() { var board = new Board(); board.Rows[0][0].Solved(4); var expected = 60 * 9; Assert.AreEqual(expected, BoardHelper.NumberOfCombinations(board)); }
/** Gets the proper BFS distance*/ public int GetDistanceBetweenTiles(byte startTileId, byte endTileId) { for (byte i = 0; i < Consts.GRID_SIZE; i++) { for (byte j = 0; j < Consts.GRID_SIZE; j++) { visited[i, j] = false; } } int[] distanceOfOrigin = new int[Consts.MAX_TILES]; for (int i = 0; i < distanceOfOrigin.Length; i++) { distanceOfOrigin[i] = Int32.MaxValue; } GridPosition startV = BoardHelper.GetColRowFromTileId(startTileId); queue.Enqueue(startTileId); distanceOfOrigin[startTileId] = 0; visited[startV.Col, startV.Row] = true; while (queue.Count > 0) { byte currentTile = queue.Dequeue(); if (currentTile == endTileId) { queue.Clear(); break; } int topX = BoardHelper.GetColRowFromTileId(currentTile).Col; int topY = BoardHelper.GetColRowFromTileId(currentTile).Row; for (byte i = 0; i < 4; i++) { if (topX + dx[i] >= 0 && topX + dx[i] < Consts.GRID_SIZE && topY + dy[i] >= 0 && topY + dy[i] < Consts.GRID_SIZE) { GridPosition adjecentTile = new GridPosition(topX + dx[i], topY + dy[i]); if (!visited[adjecentTile.Col, adjecentTile.Row] && !GetTileFromList(BoardHelper.GetTileIdFromColRow(adjecentTile)).isOccupied) { distanceOfOrigin[BoardHelper.GetTileIdFromColRow(adjecentTile)] = distanceOfOrigin[currentTile] + 1; queue.Enqueue(BoardHelper.GetTileIdFromColRow(adjecentTile)); visited[adjecentTile.Col, adjecentTile.Row] = true; } } } } return(distanceOfOrigin[endTileId]); }
private void InitilizeGameStatus() { _gameStatus = GameStatus.Instance; _gameStatus.Players = PlayerHelper.InitializePlayers(); _gameStatus.CurrentPlayer = _gameStatus.Players.FirstOrDefault(); _gameStatus.Finished = false; _gameStatus.Grid = new Grid(BoardHelper.InitializeGrid(Constants.GRID_HEIGHT, Constants.GRID_WIDTH, DOT)); _gameBoard = new SquareBoard(); }
public void PlaceUnit(Vector2Int p, UnitType unitType) { if (units.ContainsKey(p)) { DeleteUnitAt(p); } Unit unit = BoardHelper.CreateUnit(transform, null, p, unitType); units.Add(unit.Position, unit); }
public void GetNumberOfCombinationsOneSolvedAndSomeProgress() { var board = new Board(); board.Rows[0][0].Solved(4); board.Rows[0][1].PossibleNumbers = new List <int> { 1, 2, 3, 5, 6, 7, 8, 9 }; var expected = 59 * 9 + 8; Assert.AreEqual(expected, BoardHelper.NumberOfCombinations(board)); }
public void RemovePossibleNumbersRowManySolved() { var numbers1 = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; var numbers1Expected = new List <int> { 1, 4, 5, 6, 7, 8, 9 }; var numbers2 = new List <int> { 1, 2, 3 }; var numbers2Expected = new List <int> { 1 }; var numbers3 = new List <int> { 2 }; var numbers4 = new List <int> { 3 }; var row = new List <Hexa> { new Hexa(1) { PossibleNumbers = numbers1 }, new Hexa(2) { PossibleNumbers = numbers2 }, new Hexa(3) { PossibleNumbers = numbers3 }, new Hexa(4) { PossibleNumbers = numbers4 } }; var actual = BoardHelper.RemovePossibleNumbersRow(row); Assert.AreEqual(4, row.Count); Assert.AreEqual(7, row[0].PossibleNumbers.Count); Assert.AreEqual(1, row[1].PossibleNumbers.Count); Assert.AreEqual(1, row[2].PossibleNumbers.Count); Assert.AreEqual(1, row[3].PossibleNumbers.Count); Assert.IsTrue(numbers1Expected.All(n => row[0].PossibleNumbers.Contains(n))); Assert.IsTrue(numbers2Expected.All(n => row[1].PossibleNumbers.Contains(n))); Assert.IsTrue(row[2].PossibleNumbers.Contains(2)); Assert.IsTrue(row[3].PossibleNumbers.Contains(3)); }
public void TestExample1() { var board = BoardHelper.Example1(new Board()); var solvedBoard = BoardHelper.solveBoard(board, null, 0); var asd = solvedBoard.Rows.SelectMany(r => r.Where(t => t.PossibleNumbers.Count() == 1) .Select(h => h.PossibleNumbers[0])).ToList(); var actual = String.Join("", solvedBoard.Rows.SelectMany(r => r.Where(t => t.PossibleNumbers.Count() == 1) .Select(h => h.PossibleNumbers[0])).ToList()); Assert.AreEqual("5463773526446975838234175667892314554681237753268489547646758", actual); }
public void GetSmallestNumberNoSolved() { var hexas = new List <Hexa> { new Hexa(1) { PossibleNumbers = new List <int> { 1, 2, 3 } } }; Assert.AreEqual(0, BoardHelper.GetSmallestNumber(hexas)); }
public void PlaceTile(Vector2Int p, TileType tileType) { if (tiles.ContainsKey(p)) { DeleteTileAt(p); } Tile tile = BoardHelper.CreateTile( transform, null, p, tileType ); // Put tile in the dictionary tiles.Add(tile.Position, tile); }
public Vector3[] GetVector3Path(byte startTileId, byte endTileId) { for (byte i = 0; i < Consts.GRID_SIZE; i++) { for (byte j = 0; j < Consts.GRID_SIZE; j++) { visited[i, j] = false; } } GridPosition startV = BoardHelper.GetColRowFromTileId(startTileId); queue.Enqueue(startTileId); parent[startTileId] = NO_PARENT; pathSize = 0; visited[startV.Col, startV.Row] = true; while (queue.Count > 0) { byte currentTile = queue.Dequeue(); if (currentTile == endTileId) { queue.Clear(); break; } int topX = BoardHelper.GetColRowFromTileId(currentTile).Col; int topY = BoardHelper.GetColRowFromTileId(currentTile).Row; for (byte i = 0; i < 4; i++) { if (topX + dx[i] >= 0 && topX + dx[i] < Consts.GRID_SIZE && topY + dy[i] >= 0 && topY + dy[i] < Consts.GRID_SIZE) { GridPosition adjecentTile = new GridPosition(topX + dx[i], topY + dy[i]); if (!visited[adjecentTile.Col, adjecentTile.Row] && !GetTileFromList(BoardHelper.GetTileIdFromColRow(adjecentTile)).isOccupied) { queue.Enqueue(BoardHelper.GetTileIdFromColRow(adjecentTile)); visited[adjecentTile.Col, adjecentTile.Row] = true; parent[BoardHelper.GetTileIdFromColRow(adjecentTile)] = currentTile; } } } } return(GetPathList(endTileId).ConvertAll(new Converter <byte, Vector3>(GetVectorFromTileId)).ToArray()); }
public void PlaceUnit(Vector2Int p, UnitType unitType) { if (units.ContainsKey(p)) { BoardHelper.DeleteUnitAt(p, ref units); } Unit unit = BoardHelper.CreateUnit( Container.transform, this, p, unitType); units.Add(unit.Position, unit); }
public void TestInitialize() { var group = new PropertyGroup(); _parkPlace = new BuildableSquare("Park Place", 0, group, 350, 200, 200, 400, 600, 1000, 1500, 1800); _boardwalk = new BuildableSquare("Boardwalk", 0, group, 400, 200, 300, 600, 800, 1200, 1600, 2000); IDie[] dice = { new Die(), new Die() }; var board = BoardHelper.GetBoard(); _roller = new Player("Roller", dice, board); _roller.AddCash(2000); _owner = new Player("Owner", dice, board); _owner.AddCash(2000); }
public void PawnEnPassantPass() { //Setup var board = new Board { Top = Side.White, Bottom = Side.Black }; var grid = BoardHelper.GetEmptyBoard(); var row1 = BoardHelper.GetEmptyRow(); var row2 = BoardHelper.GetEmptyRow(); var pawn = new Peice { Type = PeiceType.Pawn, Side = Side.White, X = 0, Y = 4 }; var enPassantPrev = new Peice { Type = PeiceType.Pawn, Side = Side.Black, X = 1, Y = 2, HasMoved = true }; var enPassant = new Peice { Type = PeiceType.Pawn, Side = Side.Black, X = 1, Y = 4, HasMoved = true }; row1[4] = pawn; row2[4] = enPassant; grid[0] = row1; grid[1] = row2; board.SetGrid(grid); board.RecordMove(enPassantPrev, enPassant); Assert.True(Pawn.CanMove(board, pawn, 1, 1).Success); }
private static void TestFourTanksTryingToMoveIntoAWall() { TestHelper.DisplayTestTitle("Test 4 tanks each trying to move into a wall"); bool[,] isAWall = new bool[20, 20]; Rectangle walls = new Rectangle(8, 8, 12, 12); BoardHelper.AddWallsToBoard(ref isAWall, walls); Unit[] tanks = new Unit[Constants.TANK_COUNT]; Unit topUnit = new Unit { X = 10, Y = 5, Direction = Direction.DOWN, Action = Core.Action.DOWN }; Unit rightUnit = new Unit { X = 15, Y = 10, Direction = Direction.LEFT, Action = Core.Action.LEFT }; Unit bottomUnit = new Unit { X = 10, Y = 15, Direction = Direction.UP, Action = Core.Action.UP }; Unit leftUnit = new Unit { X = 5, Y = 10, Direction = Direction.RIGHT, Action = Core.Action.RIGHT }; tanks[0] = topUnit; tanks[1] = rightUnit; tanks[2] = bottomUnit; tanks[3] = leftUnit; MoveStatus[] expectedStatuses = { MoveStatus.Cancelled, MoveStatus.Cancelled, MoveStatus.Cancelled, MoveStatus.Cancelled }; TestHelper.DisplayBoardResolveAndCheckExpectations("FourTanksMovingIntoAWall", ref isAWall, expectedStatuses, tanks, imageFolderPath: ImageFolderPath); }
public void CastleMoveCastlePass() { //Setup var board = new Board() { Top = Side.White, Bottom = Side.Black }; var grid = BoardHelper.GetEmptyBoard(); var firstRow = BoardHelper.GetEmptyRow(); var kingRow = BoardHelper.GetEmptyRow(); var lastRow = BoardHelper.GetEmptyRow(); var leftRook = new Peice { Type = PeiceType.Castle, X = 0, Y = 0 }; var rightRook = new Peice { Type = PeiceType.Castle, X = 7, Y = 0 }; var king = new Peice { Type = PeiceType.King, X = 5, Y = 0 }; firstRow[0] = leftRook; kingRow[0] = king; lastRow[0] = rightRook; grid[0] = firstRow; grid[5] = kingRow; grid[7] = lastRow; board.SetGrid(grid); Assert.True(Castle.CanMove(board, leftRook, 3, 0)); Assert.True(Castle.CanMove(board, rightRook, -2, 0)); }
IEnumerator IECheckAndCollectAllMatched() { // yield break; for (int i = 0; i < BoardCells.Length; i++) { for (int j = 0; j < BoardCells[i].Length; j++) { CollectMatched(BoardHelper.GetAllMatchedCells(BoardCells, new Vector2(i, j))); if (CheckAndSetCollectableObjects()) { yield return(StartCoroutine(IERelocateHexCell())); yield return(IECheckAndCollectAllMatched()); } } } }