Skip to content

fix: FlexiblePathfinding migration follow-ups#92

Merged
skaldarnar merged 77 commits intodevelopfrom
fix/behavior-follow-ups
Mar 13, 2022
Merged

fix: FlexiblePathfinding migration follow-ups#92
skaldarnar merged 77 commits intodevelopfrom
fix/behavior-follow-ups

Conversation

@skaldarnar
Copy link
Contributor

@skaldarnar skaldarnar commented Jan 22, 2022

  • style: format .behavior files
  • chore: add TODO ideas and questions in several places
  • chore: add some debug logging
  • feature/fix: small adjustments to Behaviors logic

Follow-up PR to #89.

Related PRs (extracted from this): #94, #96, #97, #99.

Contributes to MovingBlocks/Terasology#4981.

Depends on Terasology/FlexiblePathfinding#26 and Terasology/FlexiblePathfinding#27.

Formatted `critter`, `doRandomMove`, `hostileCritter`, and `stray` behavior files with indent of 2 spaces.
The structure of having a guarded behavior lookup (`flee`) and a fallback behavior lookup (`stray`) to me looks like we're good with running nodes until we find the first one that is successful.
Applies simple refactorings such as renaming or inversion of return values to make the code defining the action more readable.

In addition, added a comment to discuss whether this should be a (complex) action or rather a behavior.
In addition, adds a couple of debug logs to investigate the control flow when running the action.

These debug lines revealed that exceptions during the execution of an action are treated as failed actions. The behavior tree runner logs a warning, but it is easy to miss...
@skaldarnar skaldarnar requested a review from jdrueckert January 22, 2022 16:14
@jdrueckert
Copy link
Member

I just noticed that the now pathfinding-based doRandomMove works pretty okay (including moving uphill).
However, it (1) does time out rather frequently when actually moving along the path or (2) the randomly chosen target block just "doesn't make sense".

For (1) we need to investigate why it times out after having found what appears to be a valid path (and judging from the debug path visualization actually is a reasonable path).
For (2) I think what we need here would be some more movement-type-based restrictions on what a "reasonable random target block" is, which should be reflected in the plugin's isReachable method.
i.e. for an entity that is walking or leaping, any target position that does not have a solid block underneath doesn't make sense (even if gravity does not apply to mobs if they don't move - btw I still feel like it does when they jump, but I don't know why).
on the other hand for an entity that is flying or swimming, that's totally fine.
for swimming however any block that is not liquid is not a reasonable target.

- add log messages when entering a behavior: critter (root), doRandomMove, naiveMoveTo, stray
Now prints out messages in the format:

```
17:43:24.551 [main] DEBUG o.t.m.behaviors.actions.LogAction - Actor 2502: ---- critter ----
```
The pathfinding plugins assume that entities are not affected by gravity. To match this assumption, we chose a movement mode that neglects gravity, but works similar to the regular walking mode: FLYING.
Without this check, we can end up with target blocks that are not walkable, screwing up the pathfinding logic. This small addition will fail the behavior action when the target is not walkable, in the hope that we'll just give it another try.

Several ideas on how to further improve this behavior action are added as TODO comments.
This is a special movement plugin that will enable gravity on entities while they are using the falling movement mode.
@jdrueckert
Copy link
Member

- only accept candidate if it increases the distance to the start block
@skaldarnar
Copy link
Contributor Author

Locally, there is a single failing test case for me now:

13:23:23.542 [Test worker] INFO  o.t.module.behaviors.MovementTests - movement plugin combination: [walking, leaping, falling]

Test character is not at target position.
  start   : ( 0.000E+0  4.100E+1  0.000E+0)
  target  : ( 5.000E+0  4.100E+1  0.000E+0)
  current : ( 0.000E+0  4.100E+1  0.000E+0)

  X    X|XX XX|XXXXX
 ==> expected: <( 5.000E+0  4.100E+1  0.000E+0)> but was: <( 0.000E+0  4.100E+1  0.000E+0)>
Expected :( 5.000E+0  4.100E+1  0.000E+0)
Actual   :( 0.000E+0  4.100E+1  0.000E+0)

All the other (positive) test cases pass nicely, usually in under 3 seconds per test case, summing up to a bit less than 2 minutes of execution time. The result is the same on CI, about 50% slower than running test locally with an execution time of 2min 40s.

jdrueckert added a commit to Terasology/FlexiblePathfinding that referenced this pull request Feb 13, 2022
Extract many tests cases from Terasology/Behaviors#92 to tests on the pathfinding itself.

Most importantly, this allows us to run these tests as unit tests instead of long-running integration tests using MTE.
@jdrueckert jdrueckert marked this pull request as ready for review March 6, 2022 15:24
set_target_nearby_block : { moveProbability: 65 }
},
move_to
{ log: { message: "in doRandomMove Behavior"} },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to keep this and similar log messages in behavior trees and also in code in for the time being and clean them up later or should we remove them before merging this so we don't forget about them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add some doc comment to LogAction and remove those debug statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 34b61b8

Copy link
Contributor Author

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this PR now does the following:

  • style: format .behavior files
  • chore: add TODO ideas and questions in several places
  • chore: add some debug logging
  • feature/fix: small adjustments to Behaviors logic

None of the remaining debug log statements does any heavy computation, so it's fine to keep them in (for now) as they are not logged with the default configuration but might prove useful for debugging purposes.

LGTM

Vector3ic[] allowedBlocks = Iterators.toArray(
Iterators.transform(Iterators.filter(neighbors.iterator(),
(candidate) -> plugin.isReachable(currentBlock, candidate)),
(candidate) -> candidate.distanceSquared(startBlock) > currentDistance
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is probably not very good as it easily runs into local dead ends, but it at least prevents us from jumping back and forth while searching... We have a TODO below to improve on this.

@skaldarnar skaldarnar added Type: Bug Issues reporting and PRs fixing problems Topic: AI Requests, Issues and Changes related to pathfinding, behaviors, etc. Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Chore Request for or implementation of maintenance changes labels Mar 13, 2022
@skaldarnar skaldarnar merged commit e14e58d into develop Mar 13, 2022
@skaldarnar skaldarnar deleted the fix/behavior-follow-ups branch March 13, 2022 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Topic: AI Requests, Issues and Changes related to pathfinding, behaviors, etc. Topic: Stabilization Requests, Issues and Changes related to improving stablity and reducing flakyness Type: Bug Issues reporting and PRs fixing problems Type: Chore Request for or implementation of maintenance changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants