aboutsummaryrefslogtreecommitdiff
path: root/src/pinky.py
diff options
context:
space:
mode:
authorMoisis <moisis.george@yahoo.com>2023-05-09 10:53:08 +0300
committerGitHub <noreply@github.com>2023-05-09 10:53:08 +0300
commit1c409760e93ce1641a7d1bcd5cd09a34ff86fe6b (patch)
treea1e9497fe359613f29164c589a499f727ef71d5c /src/pinky.py
parent1c33c06df4d40e708d526cd00d3b8392d931b7c2 (diff)
parent439ae67f933ee85bd425566cabac64815db4096e (diff)
downloadMacpan-1c409760e93ce1641a7d1bcd5cd09a34ff86fe6b.tar.xz
Macpan-1c409760e93ce1641a7d1bcd5cd09a34ff86fe6b.zip
Merge branch 'master' into TryatGUI
Diffstat (limited to 'src/pinky.py')
-rw-r--r--src/pinky.py68
1 files changed, 53 insertions, 15 deletions
diff --git a/src/pinky.py b/src/pinky.py
index 42b5d91..bb50c5b 100644
--- a/src/pinky.py
+++ b/src/pinky.py
@@ -1,13 +1,16 @@
import pygame
+import random
from typing_extensions import override
from direction import DIRECTION
+from mode import MODE
+from settings import settings
import math
from ghost import Ghost
+
class Pinky(Ghost):
def __init__(self, sprite_sheet, x, y):
- super().__init__(sprite_sheet,"pink", x, y)
-
+ super().__init__(sprite_sheet, "pink", x, y)
def get_four_tiles_ahead_of_pacman(self, pacman):
if pacman.direction == DIRECTION.UP:
@@ -36,7 +39,17 @@ class Pinky(Ghost):
return (pacman.x, pacman.y)
@override
- def get_next_move(self, target, maze, screen):
+ def get_default_tile(self):
+ return (27 * 30 + 15, 30 * 30 + 15)
+
+ @override
+ def get_intial_tile(self):
+ return (11 * 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]
dy = [0, 1, 0, -1]
@@ -53,21 +66,46 @@ class Pinky(Ghost):
if self.last_move == 3:
forbidden = 1
- new_target = self.get_four_tiles_ahead_of_pacman(target)
- pygame.draw.circle(screen, self.color, (new_target[0], new_target[1]), 15)
-
- for i in range(len(dx)):
- if i != forbidden:
- nx = self.x + dx[i] * self.speed
- ny = self.y + dy[i] * self.speed
- if self.check_collision(nx, ny, 30, 30, maze):
- ret[i] = self.heuristic((nx, ny), new_target[0], new_target[1])
-
- min_idx = ret.index(min(ret))
- return min_idx
+ rand_pos = (0, 0)
+ new_target = self.get_four_tiles_ahead_of_pacman(game_state.pacman)
+ 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 game_state.pacman.powerup is False and self.mode == MODE.FRIGHETENED:
+ self.mode = MODE.CHASING
+ for i in range(len(dx)):
+ if i != forbidden:
+ nx = self.x + dx[i] * self.speed
+ ny = self.y + dy[i] * self.speed
+ if self.check_collision(nx, ny, 30, 30, game_state.map.maze):
+ if self.mode == MODE.SCATTERED:
+ ret[i] = self.heuristic(
+ (nx, ny), default_tile[0], default_tile[1])
+ elif self.mode == MODE.FRIGHETENED:
+ ret[i] = self.heuristic(
+ (nx, ny), rand_pos[0], rand_pos[1])
+ elif self.mode == MODE.CHASING:
+ ret[i] = self.heuristic(
+ (nx, ny), new_target[0], new_target[1])
+ elif self.mode == MODE.EATEN:
+ pos = self.get_intial_tile()
+ self.x = pos[0]
+ self.y = pos[1]
+ if settings.debug:
+ pygame.draw.line(screen, self.color, (new_target),
+ (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