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 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ] diff --git a/src/agents/BaseAgent.py b/src/agents/BaseAgent.py index 1958484..04eec79 100644 --- a/src/agents/BaseAgent.py +++ b/src/agents/BaseAgent.py @@ -8,6 +8,8 @@ class BaseAgent: LEFT = vector(-5, 0) RIGHT = vector(5, 0) + course = None + def __init__(self, position, valid_function) -> None: self.position = position self.valid = valid_function @@ -19,17 +21,5 @@ def _move(self, delta): return True return False - def down(self): - self._move(self.DOWN) - - def up(self): - self._move(self.UP) - - def left(self): - self._move(self.LEFT) - - def right(self): - self._move(self.RIGHT) - def step(self, game_state): pass diff --git a/src/agents/Ghost.py b/src/agents/Ghost.py index 72c70c0..f7049f7 100644 --- a/src/agents/Ghost.py +++ b/src/agents/Ghost.py @@ -2,7 +2,6 @@ import random class Ghost(BaseAgent.BaseAgent): - course = None color = "red" def step(self, game_state): diff --git a/src/agents/HumanPacman.py b/src/agents/HumanPacman.py index a42fd5a..8101ec4 100644 --- a/src/agents/HumanPacman.py +++ b/src/agents/HumanPacman.py @@ -3,9 +3,37 @@ class HumanPacman(BaseAgent.BaseAgent): color = "yellow" - + next_in_queue = None + timer = 0 + + def down(self): + self.next_in_queue = self.DOWN + self.timer = 10 + + def up(self): + self.next_in_queue = self.UP + self.timer = 10 + + def left(self): + self.next_in_queue = self.LEFT + self.timer = 10 + + def right(self): + self.next_in_queue = self.RIGHT + self.timer = 10 + def step(self, game_state): + # check whether any new direction in queue + if self.timer > 0: + self.timer -= 1 + if self.next_in_queue and self.valid(self.position + self.next_in_queue): + self.course = self.next_in_queue + timer = 0 + self.next_in_queue = None + onkey(lambda: self.right(), "Right") onkey(lambda: self.left(), "Left") onkey(lambda: self.up(), "Up") - onkey(lambda: self.down(), "Down") \ No newline at end of file + onkey(lambda: self.down(), "Down") + if self.course: + self._move(self.course) \ No newline at end of file diff --git a/src/agents/customghost.py b/src/agents/customghost.py new file mode 100644 index 0000000..4837dc3 --- /dev/null +++ b/src/agents/customghost.py @@ -0,0 +1,18 @@ +from . import Ghost + + +class Blinky(Ghost.Ghost): + color = "red" + # def __init__ (self,) + + +class Pinky (Ghost.Ghost) : + color = "pink" + +class Inky (Ghost. Ghost): + color = "teal" + + +class Clyde (Ghost.Ghost): + color = "orange" + diff --git a/src/pacman.py b/src/pacman.py index e63d719..5ab056e 100644 --- a/src/pacman.py +++ b/src/pacman.py @@ -5,6 +5,7 @@ from agents.Ghost import Ghost from WorldRendering import * from Mazes import * +from agents.customghost import Blinky, Pinky, Inky, Clyde WRITER = Turtle(visible=False) @@ -82,10 +83,10 @@ def get_agent_game_state(agent): pacman = HumanPacman(vector(-40, -80), valid) ghosts = [ - Ghost(vector(-180, 160), valid), - Ghost(vector(-180, -160), valid), - Ghost(vector(100, 160), valid), - Ghost(vector(100, -160), valid), + Blinky(vector(-120, -100), valid), + Pinky(vector(-120, 100), valid), + Inky(vector(100, 100), valid), + Clyde(vector(100, -100), valid), ] setup(420, 420, 370, 0) # window