aboutsummaryrefslogtreecommitdiff
path: root/src/clyde.py
diff options
context:
space:
mode:
authorOmar Magdy <99906646+omagdy7@users.noreply.github.com>2023-05-08 23:25:14 +0300
committerGitHub <noreply@github.com>2023-05-08 23:25:14 +0300
commit439ae67f933ee85bd425566cabac64815db4096e (patch)
tree19077318fda033952677f84a7107ecb079db3c43 /src/clyde.py
parentd610718c10e310c75126593624ecaaaa2233b371 (diff)
parent0164fb61ccc79e677c711b158359060a7d3a2873 (diff)
downloadMacpan-439ae67f933ee85bd425566cabac64815db4096e.tar.xz
Macpan-439ae67f933ee85bd425566cabac64815db4096e.zip
Merge pull request #5 from omagdy7/Refactoring
Refactoring
Diffstat (limited to 'src/clyde.py')
-rw-r--r--src/clyde.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/clyde.py b/src/clyde.py
index 7dcf54e..2fd4aee 100644
--- a/src/clyde.py
+++ b/src/clyde.py
@@ -19,10 +19,14 @@ class Clyde(Ghost):
@override
def get_default_tile(self):
- return (27 * 30 + 15, 2 * 30 + 15)
+ return (2 * 30 + 15, 30 * 30 + 15)
@override
- def get_next_move(self, pacman, maze, screen, blinky):
+ def get_intial_tile(self):
+ return (14 * 30 + 15, 12 * 30 + 15)
+
+ @override
+ def get_next_move(self, game_state, screen):
default_tile = self.get_default_tile()
dx = [1, 0, -1, 0] # right, down, left, up
@@ -31,23 +35,28 @@ class Clyde(Ghost):
inv_dir = [2, 3, 0, 1]
ret = len(dx) * [math.inf]
- bottom_left_corner = (2.5 * 30, (len(maze) - 1 - 1 - 0.5) * 30)
+ bottom_left_corner = (
+ 2.5 * 30, (len(game_state.map.maze) - 1 - 1 - 0.5) * 30)
forbidden = inv_dir[self.last_move]
rand_pos = (0, 0)
- if pacman.powerup:
+ if game_state.pacman.powerup and self.mode != MODE.EATEN:
self.mode = MODE.FRIGHETENED
rand_pos = random.randint(0, 900), random.randint(0, 990)
- if pacman.powerup is False and self.mode == MODE.FRIGHETENED:
+ if game_state.pacman.powerup is False and self.mode == MODE.FRIGHETENED:
self.mode = MODE.CHASING
+ if settings.debug:
+ pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
+ (self.x, self.y), 1)
+
for i in range(len(dx)):
nx = self.x + dx[i] * self.speed
ny = self.y + dy[i] * self.speed
- if self.check_collision(nx, ny, 30, 30, maze):
+ if self.check_collision(nx, ny, 30, 30, game_state.map.maze):
if i != forbidden:
if self.mode == MODE.SCATTERED:
ret[i] = self.heuristic(
@@ -56,7 +65,7 @@ class Clyde(Ghost):
ret[i] = self.heuristic(
(nx, ny), rand_pos[0], rand_pos[1])
elif self.mode == MODE.CHASING:
- if self.is_eight_tiles_away(pacman):
+ if self.is_eight_tiles_away(game_state.pacman):
ret[i] = self.heuristic(
(nx, ny), bottom_left_corner[0], bottom_left_corner[1])
if settings.debug:
@@ -64,11 +73,14 @@ class Clyde(Ghost):
(self.x, self.y), 1)
else:
ret[i] = self.heuristic(
- (nx, ny), pacman.x, pacman.y)
+ (nx, ny), game_state.pacman.x, game_state.pacman.y)
if settings.debug:
- pygame.draw.line(screen, self.color, (pacman.x, pacman.y),
+ pygame.draw.line(screen, self.color, (game_state.pacman.x, game_state.pacman.y),
(self.x, self.y), 1)
-
+ elif self.mode == MODE.EATEN:
+ pos = self.get_intial_tile()
+ self.x = pos[0]
+ self.y = pos[1]
min_h = min(ret)
# Favour going up when there is a conflict