diff --git a/.DS_Store b/.DS_Store index 3fdffc1..7b037e4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/__pycache__/helpers.cpython-312.pyc b/__pycache__/helpers.cpython-312.pyc new file mode 100644 index 0000000..c45e79c Binary files /dev/null and b/__pycache__/helpers.cpython-312.pyc differ diff --git a/__pycache__/man.cpython-312.pyc b/__pycache__/man.cpython-312.pyc new file mode 100644 index 0000000..de44eed Binary files /dev/null and b/__pycache__/man.cpython-312.pyc differ diff --git a/__pycache__/snack.cpython-312.pyc b/__pycache__/snack.cpython-312.pyc new file mode 100644 index 0000000..e8da0ca Binary files /dev/null and b/__pycache__/snack.cpython-312.pyc differ diff --git a/game files/__pycache__/board.cpython-312.pyc b/game files/__pycache__/board.cpython-312.pyc new file mode 100644 index 0000000..cb2c680 Binary files /dev/null and b/game files/__pycache__/board.cpython-312.pyc differ diff --git a/game files/__pycache__/man.cpython-312.pyc b/game files/__pycache__/man.cpython-312.pyc new file mode 100644 index 0000000..a8e9dd6 Binary files /dev/null and b/game files/__pycache__/man.cpython-312.pyc differ diff --git a/game files/__pycache__/mine.cpython-312.pyc b/game files/__pycache__/mine.cpython-312.pyc new file mode 100644 index 0000000..e82fd4e Binary files /dev/null and b/game files/__pycache__/mine.cpython-312.pyc differ diff --git a/game files/__pycache__/snack.cpython-312.pyc b/game files/__pycache__/snack.cpython-312.pyc new file mode 100644 index 0000000..159f62c Binary files /dev/null and b/game files/__pycache__/snack.cpython-312.pyc differ diff --git a/game files/board.py b/game files/board.py new file mode 100644 index 0000000..cd36491 --- /dev/null +++ b/game files/board.py @@ -0,0 +1,27 @@ +from man import Man +from snack import Snack +from mine import Mine +from random import shuffle + + +class Board: + + def __init__(self,width, height,snack_density): + self.width = width + self.height = height + self.snack_density = snack_density + + def get_agents(self): + positions = self.get_all_positions() + shuffle(positions) + num_snacks = round((self.snack_density * len(positions))) + snacks = [Snack(p) for p in positions[1:num_snacks+1]] + agents=[Man(positions[0])] + snacks + return agents + + def get_all_positions(self): + positions=[] + for i in range(self.width): + for j in range(self.height): + positions.append((i,j)) + return positions \ No newline at end of file diff --git a/game files/helpers.py b/game files/helpers.py new file mode 100644 index 0000000..3e175a1 --- /dev/null +++ b/game files/helpers.py @@ -0,0 +1,30 @@ +#List of helper functions to move the man + +def add(vec0, vec1): + """Adds two vectors. + Got tired of doing this by hand. + """ + x0, y0 = vec0 + x1, y1 = vec1 + return (x0 + x1, y0 + y1) + +def get_occupant(game, position): + """Returns the agent at position, if there is one. + This function slightly simplifies the process of getting the + agent at a position: the game returns a list of agents at a position, + because some games allow more than one agent at a position. + """ + positions_with_agents = game.get_agents_by_position() + if position in positions_with_agents: + agents_at_position = positions_with_agents[position] + return agents_at_position[0] + +def distance(vec0, vec1): + """Returns the distance between two vectors, using the + "manhattan distance," or the distance if you can only + move in the x-direction or the y-direction, but not + diagonally. Just like walking blocks in Manhattan :) + """ + x0, y0 = vec0 + x1, y1 = vec1 + return abs(x1 - x0) + abs(y1 - y0) \ No newline at end of file diff --git a/game files/man.py b/game files/man.py new file mode 100644 index 0000000..b421b11 --- /dev/null +++ b/game files/man.py @@ -0,0 +1,79 @@ +from retro.agent import ArrowKeyAgent +#from retro.game import Game +#from helpers import add, get_occupant + + +direction_vectors = { + "KEY_RIGHT": (1, 0), + "KEY_UP": (0, -1), + "KEY_LEFT": (-1, 0), + "KEY_DOWN": (0, 1), +} + +class Man: + character = "&" #try google asci full table?, + color = "blue" + #name = "man" + + def __init__(self,position): + self.position = position + + def handle_keystroke(self, keystroke, game): + if keystroke.name in direction_vectors: + vector = direction_vectors[keystroke.name] + self.try_to_move(vector, game) + + def try_to_move(self, vector, game): + x,y = self.position + vx,vy = vector + future_position = (x +vx, y+vy) + on_board = game.on_board(future_position) + agents_by_position = game.get_agents_by_position() + agents = agents_by_position[future_position] + if len(agents)>0: + obstacle = agents[0] + else: + obstacle= None + + if on_board: + if obstacle: + pass + if obstacle.snack: + score +=1 + else: + score -=1 + + else: + self.position = future_position + + def die(self,game): + game.state["message"] = "Game Over" + self.color = "black" + game.end() + + +''' + def __init__(self, position): + self.position = position + + def handle_keystroke(self, keystroke, game): + if keystroke.name in direction_vectors: + vector = direction_vectors[keystroke.name] + self.try_to_move(vector, game) + + def try_to_move(self, vector, game): + """Tries to move the player in the direction of vector. + If the space is empty and it's on the board, then the move succeeds. + If the space is occupied, then if the occupant can be pushed, it gets + pushed and the move succeeds. Otherwise, the move fails. + """ + future_position = add(self.position, vector) + on_board = game.on_board(future_position) + obstacle = get_occupant(game, future_position) + if obstacle: + if obstacle.deadly: + self.die(game) + elif obstacle.handle_push(vector, game): + self.position = future_position + elif on_board: + self.position = future_position''' \ No newline at end of file diff --git a/game files/mine.py b/game files/mine.py new file mode 100644 index 0000000..c564caf --- /dev/null +++ b/game files/mine.py @@ -0,0 +1,8 @@ +class Mine: + character = "*" + color = "green" + snack=False + + + def __init__(self,position): + self.position = position diff --git a/game files/nav_game.py b/game files/nav_game.py new file mode 100644 index 0000000..1e5b7f5 --- /dev/null +++ b/game files/nav_game.py @@ -0,0 +1,16 @@ +from retro.game import Game +from board import Board + +width = 25 +height = 25 +board = Board(width,height,.01) +score = 0 +state= {} +#score = 0 +#man = Man(board_size) +game = Game( + board.get_agents(), + state, + board_size = (width, height) +) +game.play() \ No newline at end of file diff --git a/game files/snack.py b/game files/snack.py new file mode 100644 index 0000000..6b75dd2 --- /dev/null +++ b/game files/snack.py @@ -0,0 +1,8 @@ +class Snack: + character = "o" + color = "red" + snack=True + + + def __init__(self,position): + self.position = position