Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new classes for ghosts #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/Mazes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,21 @@ def __init__(self):
# fmt: off
level_1 = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 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, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0,
]
Expand Down
14 changes: 2 additions & 12 deletions src/agents/BaseAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion src/agents/Ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import random

class Ghost(BaseAgent.BaseAgent):
course = None
color = "red"

def step(self, game_state):
Expand Down
32 changes: 30 additions & 2 deletions src/agents/HumanPacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
onkey(lambda: self.down(), "Down")
if self.course:
self._move(self.course)
18 changes: 18 additions & 0 deletions src/agents/customghost.py
Original file line number Diff line number Diff line change
@@ -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"

9 changes: 5 additions & 4 deletions src/pacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down