#98 Enemy AI feels broken

Closed
opened 2 months ago by eugeneloza · 18 comments

I can't understand the pattern yet, but the enemy sometimes stands in a distance (about 2-3 cells) and doesn't attack.

I can't understand the pattern yet, but the enemy sometimes stands in a distance (about 2-3 cells) and doesn't attack.
eugeneloza commented 2 months ago
Poster

Seems like this CTD has something to do with it:

Traceback (most recent call last):
  File "/home/eugene/rogueboxadventures/main.py", line 14244, in <module>
    main()
  File "/home/eugene/rogueboxadventures/main.py", line 14228, in main
    test = player.user_input()
  File "/home/eugene/rogueboxadventures/main.py", line 10362, in user_input
    time.tick()
  File "/home/eugene/rogueboxadventures/main.py", line 13909, in tick
    world.maplist[player.pos[2]][player.on_map].AI_move()
  File "/home/eugene/rogueboxadventures/main.py", line 4356, in AI_move
    if self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp/2 and player.lp > player.attribute.max_lp/2 and distance[0] < 3 and self.npcs[y][x].num_special > 0 :#this is a defensive situation for the monster
NameError: global name 'distance' is not defined
Seems like this CTD has something to do with it: ``` Traceback (most recent call last): File "/home/eugene/rogueboxadventures/main.py", line 14244, in <module> main() File "/home/eugene/rogueboxadventures/main.py", line 14228, in main test = player.user_input() File "/home/eugene/rogueboxadventures/main.py", line 10362, in user_input time.tick() File "/home/eugene/rogueboxadventures/main.py", line 13909, in tick world.maplist[player.pos[2]][player.on_map].AI_move() File "/home/eugene/rogueboxadventures/main.py", line 4356, in AI_move if self.npcs[y][x].lp < self.npcs[y][x].basic_attribute.max_lp/2 and player.lp > player.attribute.max_lp/2 and distance[0] < 3 and self.npcs[y][x].num_special > 0 :#this is a defensive situation for the monster NameError: global name 'distance' is not defined ```
themightyglider commented 2 months ago
Owner

The CTD should be fixed now. (Was just a typo)

The other things you reported could be a bug but I need a bit more info. I added function that checks if monsters can see the player when I implemented invisibility. Maybe the monsters line of sight is blocked if it won't attack?

The CTD should be fixed now. (Was just a typo) The other things you reported could be a bug but I need a bit more info. I added function that checks if monsters can see the player when I implemented invisibility. Maybe the monsters line of sight is blocked if it won't attack?
eugeneloza commented 2 months ago
Poster

Nope. The enemy can see the player directly, but just stands in one place a few cells away and doesn't move (however, if has a ranged attack - uses it as usually).

I'll try to put those together...

Nope. The enemy can see the player directly, but just stands in one place a few cells away and doesn't move (however, if has a ranged attack - uses it as usually). I'll try to put those together...
eugeneloza commented 2 months ago
Poster

This pretty affects over 50% of enemies. The ones highlighted with red circle just stand there and don't move. Yet, they throw daggers, shot, as expected. They start acting a bit more actively, if player closes in to melee range, however they stop again if player disengages. Seldomly they do move when the player character changes position, seems like random - I couldn't find any pattern. Sometimes an enemy may "just stand" and after some time player moves around, the enemy starts attacking normally.

This pretty affects over 50% of enemies. The ones highlighted with red circle just stand there and don't move. Yet, they throw daggers, shot, as expected. They start acting a bit more actively, if player closes in to melee range, however they stop again if player disengages. Seldomly they do move when the player character changes position, seems like random - I couldn't find any pattern. Sometimes an enemy may "just stand" and after some time player moves around, the enemy starts attacking normally.
themightyglider commented 2 months ago
Owner

Looks like debuging this will become a pain.

Looks like debuging this will become a pain.
themightyglider commented 2 months ago
Owner

Update: I tried to make the 'line of sight' of monsters visible. I think the problem is obvious. Now I need to find a way to fix this.

Update: I tried to make the 'line of sight' of monsters visible. I think the problem is obvious. Now I need to find a way to fix this.
themightyglider commented 2 months ago
Owner

I made a little change. Now it seems to work better. But I've no time for extensive testing, so I leave this issue open for now.

I made a little change. Now it seems to work better. But I've no time for extensive testing, so I leave this issue open for now.
eugeneloza commented 2 months ago
Poster

Much, much better. Still enemies sometimes don't move as I'd expect them (when they are too many), but eventually they don't just stand in one place. By far (about 10 minutes) I've got only one enemy "permanently stuck" in position, if player doesn't move (e.g. trying to walk into walls or wait) - see screenshot.

Upd - got one more with a Nymph.

Much, much better. Still enemies sometimes don't move as I'd expect them (when they are too many), but eventually they don't just stand in one place. By far (about 10 minutes) I've got only one enemy "permanently stuck" in position, if player doesn't move (e.g. trying to walk into walls or wait) - see screenshot. Upd - got one more with a Nymph.
eugeneloza commented 2 months ago
Poster

Another example: vase monsters would stay in their places for about 3-4 turns, and after that 1 or 2 of those move. However, eventually all of them do close in to the player (but very-very slowly, skipping a few turns before moving).

Another example: vase monsters would stay in their places for about 3-4 turns, and after that 1 or 2 of those move. However, eventually all of them do close in to the player (but very-very slowly, skipping a few turns before moving).
themightyglider commented 2 months ago
Owner

Maybe we could fix this with an idyl counter for monsters. After 3 turns of idyl the monsters could do a random move if possible. This would change their perspective.

Maybe we could fix this with an idyl counter for monsters. After 3 turns of idyl the monsters could do a random move if possible. This would change their perspective.
themightyglider commented 2 months ago
Owner

Monsters move now randomly (like npcs with green dots) when they can't see the player. I hope this will help a bit. They maybe not allways do a logical move but at least they should not stuck.

Monsters move now randomly (like npcs with green dots) when they can't see the player. I hope this will help a bit. They maybe not allways do a logical move but at least they should not stuck.
themightyglider commented 2 months ago
Owner

Had you any more problems since my last change?

Had you any more problems since my last change?
eugeneloza commented 2 months ago
Poster

Nope, I didn't have a chance to play this week. Maybe somewhere closer to weekends.

Nope, I didn't have a chance to play this week. Maybe somewhere closer to weekends.
eugeneloza commented 2 months ago
Poster

Yes, it feels a bit better, but still:

  1. Enemies move extremely slowly (up to 5 times slower than expected) by skipping turns.

  2. If the player gets out of visual range enemies soon loose track of character and start walking around randomly (while being directly seen by the player).

  3. Some (?) spawners also dropped spawning frequency? I'm talking about daemonic chest first of all. Seems like the spawners don't spawn minions when they "don't see" the player character.

Yes, it feels a bit better, but still: 1. Enemies move extremely slowly (up to 5 times slower than expected) by skipping turns. 2. If the player gets out of visual range enemies soon loose track of character and start walking around randomly (while being directly seen by the player). 3. Some (?) spawners also dropped spawning frequency? I'm talking about daemonic chest first of all. Seems like the spawners don't spawn minions when they "don't see" the player character.
themightyglider commented 2 months ago
Owner

It seems the old 'stupid' AI worked better for RBA. Maybe I should remove the LoS check. Here is an idea for a simplified system: Monsters should have a view range. By default this range should be as big as players maximum view range. If the distance between player and monster is bigger then the monsters view range los_check() returns False. Same happens if the monster is blinded or the player char is invisible (Memo to myself: Need to an item like 'Potion of invisibility' to allow players to obtain this buff without cheats). In all other situations los_check() will return True. This way monsters should act ike before in the most situations. As a little bonus the variable view range will allow features like monsters that only act hostile if you come to close.

It seems the old 'stupid' AI worked better for RBA. Maybe I should remove the LoS check. Here is an idea for a simplified system: Monsters should have a view range. By default this range should be as big as players maximum view range. If the distance between player and monster is bigger then the monsters view range los_check() returns False. Same happens if the monster is blinded or the player char is invisible (Memo to myself: Need to an item like 'Potion of invisibility' to allow players to obtain this buff without cheats). In all other situations los_check() will return True. This way monsters should act ike before in the most situations. As a little bonus the variable view range will allow features like monsters that only act hostile if you come to close.
eugeneloza commented 2 months ago
Poster

Another variant, monsters become active once the player sees them (a but might be if player is blinded and can't see them) and never check LOS again unless blinded or player turns invisible.

Another variant, monsters become active once the player sees them (a but might be if player is blinded and can't see them) and never check LOS again unless blinded or player turns invisible.
themightyglider commented 2 months ago
Owner

I've changed the system one more time. Now monsters have an inner_view_range and an outer_view_range variable. If the distance between player and monster is smaller then inner_view_range the monster turns active. If player is outside outer_view_range the mob turns inactive again. Inactive means the monster just randomly moves around. Active monsters will try to attack the player.

Let's see how this system will work.

I've changed the system one more time. Now monsters have an inner_view_range and an outer_view_range variable. If the distance between player and monster is smaller then inner_view_range the monster turns active. If player is outside outer_view_range the mob turns inactive again. Inactive means the monster just randomly moves around. Active monsters will try to attack the player. Let's see how this system will work.
eugeneloza commented 2 months ago
Poster

Tested it today. It's much better, seems equal to what has been before.

Tested it today. It's much better, seems equal to what has been before.
Sign in to join this conversation.
No Milestone
No assignee
2 Participants
Loading...
Cancel
Save
There is no content yet.