aliens

Author Topic: Weird AI pathfinding  (Read 8236 times)

Offline Snickerdoodle

  • Sergeant
  • **
  • Posts: 26
    • View Profile
Weird AI pathfinding
« on: May 16, 2014, 02:31:55 pm »
The AI sometimes makes some weird path decisions when going up or down a level.

Example: I have a soldier that hides behind a door (screen021), ready to go up the stairs to the next floor (screen022). She first goes around the door (screen023), then closes the door (screen024), and then proceeds up the stairs (screen025).

(continues)

Offline Snickerdoodle

  • Sergeant
  • **
  • Posts: 26
    • View Profile
Re: Weird AI pathfinding
« Reply #1 on: May 16, 2014, 02:33:00 pm »
(continued)

But if I ask her to just go to the top of the stairs but not on to the next floor (screen026), she closes the door directly (screen027) and goes straight up the stairs without any detours.

(continues)

Offline Snickerdoodle

  • Sergeant
  • **
  • Posts: 26
    • View Profile
Re: Weird AI pathfinding
« Reply #2 on: May 16, 2014, 02:34:12 pm »
(continued)

It's the same when soldiers leave the Skyranger. They're unable to walk straight down the ramp (screen029 to screen033).

Offline Shoes

  • Commander
  • *****
  • Posts: 502
    • View Profile
Re: Weird AI pathfinding
« Reply #3 on: May 16, 2014, 02:52:00 pm »
There's an option to turn on a path preview; it would probably be easier than taking multiple screenshots.

I know the skyranger quirk is like... a legacy feature. Or it's hard to fix.

Offline Snickerdoodle

  • Sergeant
  • **
  • Posts: 26
    • View Profile
Re: Weird AI pathfinding
« Reply #4 on: May 16, 2014, 03:02:41 pm »
There's an option to turn on a path preview; it would probably be easier than taking multiple screenshots.

Whoops! Quite possibly, yes.  ;D

I have a hate/hate relationship with the path preview, so I tend to forget it's there.

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Weird AI pathfinding
« Reply #5 on: May 16, 2014, 03:16:14 pm »
the ramps are a simple fix, ruleset below. the reason we use this "weird" pathing on the ramp is because our pathfinder chooses the most TU efficient route, in vanilla it chose the most direct.
the doors are gonna get nerfed tomorrow when i've actually had enough sleep to function as a human being.


Code: [Select]
MCDPatches:
  - type: PLANE
    data:
      - MCDIndex: 62
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
      - MCDIndex: 63
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
      - MCDIndex: 64
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
  - type: AVENGER
    data:
      - MCDIndex: 53
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
      - MCDIndex: 54
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
      - MCDIndex: 55
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
  - type: LIGHTNIN
    data:
      - MCDIndex: 38
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
      - MCDIndex: 39
        TUWalk: 0
        TUFly: 0
        TUSlide: 0
« Last Edit: May 16, 2014, 03:18:09 pm by Warboy1982 »

Offline Ishmaeel

  • Captain
  • ***
  • Posts: 55
    • View Profile
Re: Weird AI pathfinding
« Reply #6 on: May 16, 2014, 03:57:05 pm »
...our pathfinder chooses the most TU efficient route...

Actually, the problem could be that the pathfinder (and the actual walking) seems to ignore the costs associated with turning.

The auto-walk down the ramp screenshot by Snickerdoodle has a cost of 20 TUs. If you really must face straight backwards, you need to add one more point for turning 45 degrees and it comes to 21 TUs.

If you follow the same auto-path without turning manually but by taking the steps one at a time (four stops), the result is the same. 20+1 TUs.

If you follow the same path, but turn manually at every stop by right clicking, the total cost comes up to 24 (four steps and four turns).

Now here's the interesting part: If you manually come down the ramp one step at a time, straight down, the total cost is the same: 24TUs.

So, if walking did not ignore the 1 point cost of those 3 turns, the roundabout path and the straight path would have exactly the same TU costs.



Edit: Apparently this is by design. Vanilla legacy?
https://github.com/SupSuper/OpenXcom/blob/master/src/Battlescape/UnitWalkBState.cpp#L330

Still, I'm not sure how I feel about this. On one hand, it makes sense that creeping forward cautiously as opposed to charging headlong takes a longer time. On the other hand, it feels strange that we are allowed free actions for leaving the running to the pathfinder.

Ultimately, I'm annoyed that my soldiers seem to be doing strange chicken dances around obstacles and end up facing wrong directions, but I could always imagine them vaulting down the ramp and rolling sideways to dodge the incoming barrage of red hot plasma :).

I hope we are not starting a TU holy war here.
« Last Edit: May 16, 2014, 04:30:30 pm by Ishmaeel »

Offline CoolKid

  • Captain
  • ***
  • Posts: 89
    • View Profile
Re: Weird AI pathfinding
« Reply #7 on: May 16, 2014, 04:49:01 pm »
If you follow the same path, but turn manually at every stop by right clicking, the total cost comes up to 24 (four steps and four turns).

You wasting your TU because of turning manually. :P

Still, I'm not sure how I feel about this. On one hand, it makes sense that creeping forward cautiously as opposed to charging headlong takes a longer time. On the other hand, it feels strange that we are allowed free actions for leaving the running to the pathfinder.

Why feel strange? In real life you must be very efficient (make choices and acts quickly) or you will die!

Offline Ishmaeel

  • Captain
  • ***
  • Posts: 55
    • View Profile
Re: Weird AI pathfinding
« Reply #8 on: May 16, 2014, 05:01:43 pm »
Why feel strange?

Well, I agree completely on the efficiency point. The strange feeling comes from my tendency to think about XCom as a strictly turn-based game. You see, you are apparently taking the exact same sequence of actions and end up on the same spot at the end, but one way to get there has a different cost.

I guess I should not be forgetting that the system is actually mostly-turn-based-but-semi-emulating-real-time-sometimes ;D

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Weird AI pathfinding
« Reply #9 on: May 16, 2014, 08:17:35 pm »
the reason it goes around the door when going to level 2 is because it uses A*, the reason it goes straight through the door when going to the same floor is because it uses bresenham where possible, hence the variance in results.
« Last Edit: May 16, 2014, 08:19:08 pm by Warboy1982 »

Offline Snickerdoodle

  • Sergeant
  • **
  • Posts: 26
    • View Profile
Re: Weird AI pathfinding
« Reply #10 on: May 16, 2014, 08:21:32 pm »
But why does it both go around the door, and close it while doing so, in the same movement?

Offline Warboy1982

  • Administrator
  • Commander
  • *****
  • Posts: 2333
  • Developer
    • View Profile
Re: Weird AI pathfinding
« Reply #11 on: May 16, 2014, 08:45:22 pm »
because i didn't nerf them yet.