protected override void InitState() { base.InitState(); { State state = new PathFindingIdleState(); state.Init(this); _stateMap[eStateType.IDLE] = state; } { State state = new PathFindingTestMoveState(); state.Init(this); _stateMap[eStateType.MOVE] = state; } { //State state = new PathFindingImmediateState(); State state = new PathFindingState(); state.Init(this); _stateMap[eStateType.PATHFINDING] = state; } { State state = new DiscoverState(); state.Init(this); _stateMap[eStateType.DISCOVER] = state; } _state = _stateMap[eStateType.IDLE]; }
private void GetState() { if (Physics2D.Raycast(transform.position, transform.right, 1f, WallLayer)) { State = PathFindingState.Stuck; ObstacleDirection = transform.right; } else if (PathFindingState.Stuck == State && Physics2D.Raycast(transform.position, ObstacleDirection, 1f, WallLayer)) { State = PathFindingState.Hunting; } }
private void ButtonSolveClick(object sender, RoutedEventArgs e) { if (_currentPolyLine.Points.Count >= 2) { _currentPolyLine.Points.Add(_currentPolyLine.Points[0]); } var initialState = new PathFindingState(new Search.Types.Point(100, 100)); var goalState = new PathFindingState(new Search.Types.Point(800, 600)); var environment = new PathFindingEnvironment(); foreach (var polyLine in _polyLines) { var points = polyLine.Points.Select(p => p).Distinct().ToList(); for (int i = 0; i < points.Count; i++) { for (int j = i + 1; j < points.Count; j++) { if (i == j) { continue; } var pointLine = new PointLine( new Point(points[i].X, points[i].Y), new Point(points[j].X, points[j].Y)); environment.PointLines.Add(pointLine); } } } var actionFunction = new PathFindingActionFunction(environment, goalState); var resultFunction = new PathFindingResultFunction(); var goalTest = new PathFindingGoalTest(goalState); var stepCost = new PathFindingStepCost(); var searchAlgorithm = new GraphSearch <PathFindingState, PathFindingAction>(); var problem = new Problem <PathFindingState, PathFindingAction>(initialState, actionFunction, resultFunction, goalTest, stepCost); var solution = searchAlgorithm.Search(problem); for (int i = 1; i < solution.Count; i++) { AddLine( solution[i - 1].State.Point.X, solution[i - 1].State.Point.Y, solution[i].State.Point.X, solution[i].State.Point.Y); } }
private static void SolvePathFindingProblem() { var initialState = new PathFindingState(new Point(1, 1)); var goalState = new PathFindingState(new Point(5, 5)); var environment = new PathFindingEnvironment(); environment.PointLines.Add(new PointLine(new Point(1, 3), new Point(3, 1))); environment.PointLines.Add(new PointLine(new Point(3, 1), new Point(5, 3))); environment.PointLines.Add(new PointLine(new Point(5, 3), new Point(3, 5))); environment.PointLines.Add(new PointLine(new Point(3, 5), new Point(1, 3))); environment.PointLines.Add(new PointLine(new Point(3, 1), new Point(3, 5))); environment.PointLines.Add(new PointLine(new Point(1, 3), new Point(5, 3))); var actionFunction = new PathFindingActionFunction(environment, goalState); var resultFunction = new PathFindingResultFunction(); var goalTest = new PathFindingGoalTest(goalState); var stepCost = new PathFindingStepCost(); var searchAlgorithm = new GraphSearch <PathFindingState, PathFindingAction>(); SolveProblem(actionFunction, resultFunction, goalTest, stepCost, initialState, searchAlgorithm); }
//private Vector2 obstacle private void Start() { State = PathFindingState.Hunting; }