public void _02_Pathfinder_Solves_The_Puzzle() { SlidingPuzzleMap map = new SlidingPuzzleMap( "11111111;" + "11000101;" + "11000101;" + "10000101;" + "10000001;" + "10001111;" + "11000001;" + "10000001;" + "11W11111;" + "11111111"); SlidingPuzzleState startingState = new SlidingPuzzleState(new Vector2Int(1, 6)); var processor = new SlidingPuzzleProcessor(map); var pathfinder = new Pathfinder.PuzzlePathfinder <Vector2Int, SlidingPuzzleState>().RecalculateGrah(processor, startingState, new Vector2Int[] { _up, _down, _left, _right }); var stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start(); var path = pathfinder.GetClosestWinPath(startingState); stopwatch.Stop(); Debug.Log($"Pathfinding had taken: {stopwatch.ElapsedMilliseconds} ms [{stopwatch.ElapsedTicks} ticks]"); Assert.That(path.Succesfull, Is.EqualTo(true), $"Path is not marked as succesful"); Assert.That(path.Path, Is.EqualTo(new Vector2Int[] { _right, _up, _left, _down }), $"Path is incorrect"); }
private void Start() { SlidingPuzzleMap map = new SlidingPuzzleMap( "11111111111111111111;" + "11111111110000011111;" + "11000000000111011111;" + "10000010000111010001;" + "10010010000000010001;" + "10111010110000000001;" + "10010000110101000001;" + "1100000000000101W101;" + "10000001100111011101;" + "10000001100000010001;" + "11110000000001100001;" + "11111000100001100001;" + "11111000100000000001;" + "11111000000000000001;" + "11110000000111111111;" + "11111100001111111111;" + "11111111111111111111" ); currentState = new SlidingPuzzleState(new Vector2Int(7, 9)); CreateMap(map); _display.ShowState(currentState); movementQueue = new Queue <Vector2Int>(); _pathfinder = new PuzzlePathfinder <Vector2Int, SlidingPuzzleState>() .RecalculateGrah(_processor, currentState, new Vector2Int[] { Vector2Int.up, Vector2Int.down, Vector2Int.left, Vector2Int.right }); }
public void ShowState(SlidingPuzzleState state) { if (_player_instance == null) { _player_instance = Instantiate(_playerPrefab, transform); } _player_instance.transform.position = _grid.GetCellCenterWorld((Vector3Int)state.PlayerCoords); }
private void HandleInput(Vector2Int dir) { if (!_display.Moving) { var result = _processor.ProcessWithTransitions(currentState, dir); currentState = result.State; if (_processor.StateIsWinning(currentState)) { Debug.Log("You won"); } _display.ShowTransition(result.Transitions, null); } }