Bug 596 - Red Ghost crashes into wall
Summary: Red Ghost crashes into wall
Status: RESOLVED FIXED
Alias: None
Product: Group14-Pacman
Classification: Unclassified
Component: Game (show other bugs)
Version: 0.0.2
Hardware: PC Windows
: High enhancement
Assignee: Alex
URL:
Depends on:
Blocks:
 
Reported: 2021-11-21 01:09 HKT by Aleksa
Modified: 2021-12-06 22:56 HKT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aleksa 2021-11-21 01:09:54 HKT
I run Main.java with commands "LEFT" 12 times. I expected the Red Ghost to come and eat PacMan, but instead it crashed into the wall and I got this exception from Eclipse:

Exception in thread "main" java.lang.NullPointerException
        at Game.Moveable.move(Moveable.java:17)
        at Game.Ghost.moveToTarget(Ghost.java:121)
        at Game.ScatterTopRightCorner.behave(ScatterTopRightCorner.java:11)
        at Game.Game.moveGhosts(Game.java:173)
        at Game.Game.handleMovements(Game.java:115)
        at Game.Game.gameTick(Game.java:60)
        at Game.Main.main(Main.java:26)
Comment 1 Aleksa 2021-11-21 01:18:30 HKT
Solution: 


1) Ghost should not use Manhattan distance as a heuristic. We introduce Euclidian distance
2)Ghost cannot change the position when it is surrounded by walls on its 3 sides
A conditional in moveToTarget() in Ghost.java should be used to check whether the next direction of the ghost is null or not
4) Moreover, the coordinates of the maze corners have been substituted. I fixed that

Now, the red ghost does not crash into walls anymore