aboutsummaryrefslogtreecommitdiff
path: root/src/clyde.py
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-05-08 14:47:07 +0300
committeromagdy7 <omar.professional8777@gmail.com>2023-05-08 14:47:07 +0300
commit72aeff07de251f66c579405f0aecb0b9c4d4cfac (patch)
treef8cd713cb9bd7df73297e110eaf8baad2236b48b /src/clyde.py
parentc7c473177086399a8fb97936b4c3c2b67a43fce0 (diff)
downloadMacpan-72aeff07de251f66c579405f0aecb0b9c4d4cfac.tar.xz
Macpan-72aeff07de251f66c579405f0aecb0b9c4d4cfac.zip
Added scattered mode for the ghosts
Diffstat (limited to 'src/clyde.py')
-rw-r--r--src/clyde.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/clyde.py b/src/clyde.py
index 95de2cb..d17a583 100644
--- a/src/clyde.py
+++ b/src/clyde.py
@@ -1,6 +1,7 @@
from ghost import Ghost
import pygame
from settings import settings
+from mode import MODE
from typing_extensions import override
import math
@@ -16,7 +17,13 @@ class Clyde(Ghost):
return math.sqrt(dx * dx + dy * dy) <= tile_width * 8
@override
+ def get_default_tile(self):
+ return (27 * 30 + 15, 2 * 30 + 15)
+
+ @override
def get_next_move(self, pacman, maze, screen, blinky):
+ default_tile = self.get_default_tile()
+
dx = [1, 0, -1, 0] # right, down, left, up
dy = [0, 1, 0, -1]
@@ -32,23 +39,30 @@ class Clyde(Ghost):
ny = self.y + dy[i] * self.speed
if self.check_collision(nx, ny, 30, 30, maze):
if i != forbidden:
- if self.is_eight_tiles_away(pacman):
+ if self.mode == MODE.SCATTERED:
ret[i] = self.heuristic(
- (nx, ny), bottom_left_corner[0], bottom_left_corner[1])
- if settings.debug:
- pygame.draw.line(screen, self.color, (bottom_left_corner),
- (self.x, self.y), 1)
+ (nx, ny), default_tile[0], default_tile[1])
else:
- ret[i] = self.heuristic(
- (nx, ny), pacman.x, pacman.y)
- if settings.debug:
- pygame.draw.line(screen, self.color, (pacman.x, pacman.y),
- (self.x, self.y), 1)
+ if self.is_eight_tiles_away(pacman):
+ ret[i] = self.heuristic(
+ (nx, ny), bottom_left_corner[0], bottom_left_corner[1])
+ if settings.debug:
+ pygame.draw.line(screen, self.color, (bottom_left_corner),
+ (self.x, self.y), 1)
+ else:
+ ret[i] = self.heuristic(
+ (nx, ny), pacman.x, pacman.y)
+ if settings.debug:
+ pygame.draw.line(screen, self.color, (pacman.x, pacman.y),
+ (self.x, self.y), 1)
min_h = min(ret)
# Favour going up when there is a conflict
if min_h == ret[3] and min_h != math.inf:
return 3
+ # Favour going down than sideways when there is a conflict
+ if min_h == ret[1] and min_h != math.inf:
+ return 1
min_idx = ret.index(min_h)
return min_idx