From 9276ed9aa0565a4b74db34c8a905677263fa2d46 Mon Sep 17 00:00:00 2001 From: Chris Proctor Date: Thu, 19 Mar 2026 12:15:22 -0400 Subject: [PATCH] Fixing game to working state --- .gitignore | 1 + fruit_catcher/__init__.py | 0 catcher.py => fruit_catcher/catcher.py | 13 ----- fruit.py => fruit_catcher/fruit.py | 33 +++++++---- fruit_catcher/game.py | 17 ++++++ manager.py => fruit_catcher/manager.py | 6 +- game.py | 17 ------ poetry.lock | 81 -------------------------- pyproject.toml | 35 ++++++----- uv.lock | 68 +++++++++++++++++++++ 10 files changed, 131 insertions(+), 140 deletions(-) create mode 100644 fruit_catcher/__init__.py rename catcher.py => fruit_catcher/catcher.py (77%) rename fruit.py => fruit_catcher/fruit.py (54%) create mode 100644 fruit_catcher/game.py rename manager.py => fruit_catcher/manager.py (79%) delete mode 100644 game.py delete mode 100644 poetry.lock create mode 100644 uv.lock diff --git a/.gitignore b/.gitignore index e43b0f9..f648967 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +fruit_catcher/__pycache__ diff --git a/fruit_catcher/__init__.py b/fruit_catcher/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/catcher.py b/fruit_catcher/catcher.py similarity index 77% rename from catcher.py rename to fruit_catcher/catcher.py index 141985f..88f79d4 100644 --- a/catcher.py +++ b/fruit_catcher/catcher.py @@ -6,11 +6,6 @@ class CatcherPiece: def __init__(self, position): self.position = position - def play_turn(self, game): - fruit = game.get_agent_by_name("fruit") - if self.position == fruit.position: - game.state['Score'] += 1 - class Catcher: width = 6 display = False @@ -36,14 +31,6 @@ class Catcher: if x + self.width < width: self.position = (x+1, y) self.update_piece_positions() - self.checkforfruitcollision(game) - - def checkforfruitcollision(self, game): - for piece in self.pieces: - if piece.collision(game): - game.remove_agent(fruit) - game.state['Score'] += 1 - def create_pieces(self, game): x, y = self.position diff --git a/fruit.py b/fruit_catcher/fruit.py similarity index 54% rename from fruit.py rename to fruit_catcher/fruit.py index a7e84f0..11d0173 100644 --- a/fruit.py +++ b/fruit_catcher/fruit.py @@ -28,14 +28,17 @@ class Fruit: self.create_shape(game, offset) def play_turn(self, game): - if game.turn_number % 3 == 0: + if game.turn_number % 3 == 0: x, y = self.position - if y == 29: + if y >= 29: + for piece in self.pieces.values(): + game.remove_agent(piece) game.remove_agent(self) game.end() else: - catcher = game.get_agent_by_name("catcher") - new_position = (x, y + 1) + self.position = (x, y + 1) + self.update_piece_positions() + self.check_catcher_collision(game) def create_shape(self, game, offset): x, y = self.position @@ -45,12 +48,18 @@ class Fruit: game.add_agent(piece) def update_piece_positions(self): - if game.turn_number % 3 == 0: - self.set_color() - x, y = self.position - if y == 29: + x, y = self.position + for offset, piece in self.pieces.items(): + ox, oy = offset + piece.position = (x + ox, y + oy) + + def check_catcher_collision(self, game): + catcher = game.get_agent_by_name("catcher") + catcher_positions = {p.position for p in catcher.pieces} + for piece in self.pieces.values(): + if piece.position in catcher_positions: + game.state['Score'] += 1 + for p in self.pieces.values(): + game.remove_agent(p) game.remove_agent(self) - game.end() - else: - catcher = game.get_agent_by_name("catcher") - new_position = (x, y + 1) \ No newline at end of file + return \ No newline at end of file diff --git a/fruit_catcher/game.py b/fruit_catcher/game.py new file mode 100644 index 0000000..9361fd6 --- /dev/null +++ b/fruit_catcher/game.py @@ -0,0 +1,17 @@ +from random import randint +from retro.game import Game +from .catcher import Catcher +from .manager import FruitManager +import json + +WIDTH = 27 +HEIGHT = 30 + +def play(): + agents = [ + Catcher((11, 29)), + FruitManager(), + ] + state = {'Score': 0} + game = Game(agents, state, board_size=(WIDTH, HEIGHT), framerate=24, color="white_on_indigo", dump_state="result.json") + game.play() diff --git a/manager.py b/fruit_catcher/manager.py similarity index 79% rename from manager.py rename to fruit_catcher/manager.py index 9fdefbf..4f9702a 100644 --- a/manager.py +++ b/fruit_catcher/manager.py @@ -1,4 +1,4 @@ -from fruit import Fruit, SHAPE_DEFINITIONS +from .fruit import Fruit, SHAPE_DEFINITIONS from random import choice, randint from retro.errors import AgentNotFoundByName @@ -13,6 +13,6 @@ class FruitManager: self.create_piece(game) def create_piece(self, game): - x = randint(0, 26) + x = randint(0, 25) fruit = Fruit((x, 1), game, choice(SHAPE_DEFINITIONS)) - game.add_agent(fruit) \ No newline at end of file + game.add_agent(fruit) diff --git a/game.py b/game.py deleted file mode 100644 index 4e7af94..0000000 --- a/game.py +++ /dev/null @@ -1,17 +0,0 @@ -from random import randint -from retro.game import Game -from catcher import Catcher -from manager import FruitManager -import json - -WIDTH = 27 -HEIGHT = 30 - -agents = [ - Catcher((11, 29)), - FruitManager(), -] - -state = {'Score': 0} -game = Game(agents, state, board_size=(WIDTH, HEIGHT), framerate=24, color="white_on_indigo") -game.play() \ No newline at end of file diff --git a/poetry.lock b/poetry.lock deleted file mode 100644 index 4ef7f79..0000000 --- a/poetry.lock +++ /dev/null @@ -1,81 +0,0 @@ -# This file is automatically @generated by Poetry 2.2.0 and should not be changed by hand. - -[[package]] -name = "ansicon" -version = "1.89.0" -description = "Python wrapper for loading Jason Hood's ANSICON" -optional = false -python-versions = "*" -groups = ["main"] -markers = "platform_system == \"Windows\"" -files = [ - {file = "ansicon-1.89.0-py2.py3-none-any.whl", hash = "sha256:f1def52d17f65c2c9682cf8370c03f541f410c1752d6a14029f97318e4b9dfec"}, - {file = "ansicon-1.89.0.tar.gz", hash = "sha256:e4d039def5768a47e4afec8e89e83ec3ae5a26bf00ad851f914d1240b444d2b1"}, -] - -[[package]] -name = "blessed" -version = "1.25.0" -description = "Easy, practical library for making terminal apps, by providing an elegant, well-documented interface to Colors, Keyboard input, and screen Positioning capabilities." -optional = false -python-versions = ">=3.7" -groups = ["main"] -files = [ - {file = "blessed-1.25.0-py3-none-any.whl", hash = "sha256:e52b9f778b9e10c30b3f17f6b5f5d2208d1e9b53b270f1d94fc61a243fc4708f"}, - {file = "blessed-1.25.0.tar.gz", hash = "sha256:606aebfea69f85915c7ca6a96eb028e0031d30feccc5688e13fd5cec8277b28d"}, -] - -[package.dependencies] -jinxed = {version = ">=1.1.0", markers = "platform_system == \"Windows\""} -wcwidth = ">=0.1.4" - -[package.extras] -docs = ["Pillow", "Sphinx (>3)", "sphinx-paramlinks", "sphinx_rtd_theme", "sphinxcontrib-manpage"] - -[[package]] -name = "jinxed" -version = "1.3.0" -description = "Jinxed Terminal Library" -optional = false -python-versions = "*" -groups = ["main"] -markers = "platform_system == \"Windows\"" -files = [ - {file = "jinxed-1.3.0-py2.py3-none-any.whl", hash = "sha256:b993189f39dc2d7504d802152671535b06d380b26d78070559551cbf92df4fc5"}, - {file = "jinxed-1.3.0.tar.gz", hash = "sha256:1593124b18a41b7a3da3b078471442e51dbad3d77b4d4f2b0c26ab6f7d660dbf"}, -] - -[package.dependencies] -ansicon = {version = "*", markers = "platform_system == \"Windows\""} - -[[package]] -name = "retro-games" -version = "1.1.3" -description = "A simple framework for Terminal-based games" -optional = false -python-versions = "<4.0,>=3.10" -groups = ["main"] -files = [ - {file = "retro_games-1.1.3-py3-none-any.whl", hash = "sha256:4bdd27241b5cb3ee72e69a042d301ff58df2a2ade7e3c29400a538fa54e30148"}, - {file = "retro_games-1.1.3.tar.gz", hash = "sha256:4f91ff725e551820aa4e30c12c0264e2da41967ed34252122b7136bc2a8ed311"}, -] - -[package.dependencies] -blessed = ">=1.20.0,<2.0.0" - -[[package]] -name = "wcwidth" -version = "0.2.14" -description = "Measures the displayed width of unicode strings in a terminal" -optional = false -python-versions = ">=3.6" -groups = ["main"] -files = [ - {file = "wcwidth-0.2.14-py2.py3-none-any.whl", hash = "sha256:a7bb560c8aee30f9957e5f9895805edd20602f2d7f720186dfd906e82b4982e1"}, - {file = "wcwidth-0.2.14.tar.gz", hash = "sha256:4d478375d31bc5395a3c55c40ccdf3354688364cd61c4f6adacaa9215d0b3605"}, -] - -[metadata] -lock-version = "2.1" -python-versions = ">=3.10,<4.0" -content-hash = "ef9faaca1f4921bdb0f3ad32c00827ffc8373223b745fd6732e8e95d90972543" diff --git a/pyproject.toml b/pyproject.toml index 0cc4733..5d25e0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,28 +2,35 @@ name = "fruit-catcher" version = "0.1.0" description = "" -authors = [ - {name = "Kayden Dang, Connor ",email = "chris@chrisproctor.net"} -] -license = {text = "MIT"} -readme = "README.md" +authors = [{ name = "Kayden Dang, Connor ", email = "chris@chrisproctor.net" }] requires-python = ">=3.10,<4.0" +license = { text = "MIT" } +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", +] dependencies = [ - "retro-games (>=1.1.1,<2.0.0)" + "retro-games>=2.0.0,<3.0.0", ] [project.scripts] -play = "game:play" +play = "fruit_catcher.game:play" + +[tool.uv.build-backend] +module-name = "fruit_catcher" +module-root = "" + + +[build-system] +requires = ["uv_build>=0.10.0,<0.11.0"] +build-backend = "uv_build" [tool.retro] authors = "Kayden, Connor" description = "Use your buttons to help the catcher catch the falling fruits. Don't drop too many fruits!" instructions = "SCore as many points as possible before losing by using the two designated buttons to move left and right." result_file = "result.json" - -[build-system] -requires = ["poetry-core>=2.0.0,<3.0.0"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry] -package-mode = false diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..06b3863 --- /dev/null +++ b/uv.lock @@ -0,0 +1,68 @@ +version = 1 +requires-python = ">=3.10, <4.0" + +[[package]] +name = "ansicon" +version = "1.89.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b6/e2/1c866404ddbd280efedff4a9f15abfe943cb83cde6e895022370f3a61f85/ansicon-1.89.0.tar.gz", hash = "sha256:e4d039def5768a47e4afec8e89e83ec3ae5a26bf00ad851f914d1240b444d2b1", size = 67312 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/75/f9/f1c10e223c7b56a38109a3f2eb4e7fe9a757ea3ed3a166754fb30f65e466/ansicon-1.89.0-py2.py3-none-any.whl", hash = "sha256:f1def52d17f65c2c9682cf8370c03f541f410c1752d6a14029f97318e4b9dfec", size = 63675 }, +] + +[[package]] +name = "blessed" +version = "1.33.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "jinxed", marker = "platform_system == 'Windows'" }, + { name = "wcwidth" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/68/5c/92dc10a25a4eafb4b9bef5dad522a0b7d5d5b55d2d76f9a6721b2e49ca2c/blessed-1.33.0.tar.gz", hash = "sha256:c732a1043042d84f411423a1a7b74643e1dd3a2271bd6e5955682dd4a321b0ef", size = 13980368 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/22/04/2b4e111e0b902b1ac0b25e5e010af71c79fca093a3399bd7f8b82adcc536/blessed-1.33.0-py3-none-any.whl", hash = "sha256:1bc8ecac6d139286ea51ec1683433528ce75b0c60db77b7d881112bf9fc85b0f", size = 111519 }, +] + +[[package]] +name = "fruit-catcher" +version = "0.1.0" +source = { editable = "." } +dependencies = [ + { name = "retro-games" }, +] + +[package.metadata] +requires-dist = [{ name = "retro-games", specifier = ">=2.0.0,<3.0.0" }] + +[[package]] +name = "jinxed" +version = "1.3.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "ansicon", marker = "platform_system == 'Windows'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/20/d0/59b2b80e7a52d255f9e0ad040d2e826342d05580c4b1d7d7747cfb8db731/jinxed-1.3.0.tar.gz", hash = "sha256:1593124b18a41b7a3da3b078471442e51dbad3d77b4d4f2b0c26ab6f7d660dbf", size = 80981 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/27/e3/0e0014d6ab159d48189e92044ace13b1e1fe9aa3024ba9f4e8cf172aa7c2/jinxed-1.3.0-py2.py3-none-any.whl", hash = "sha256:b993189f39dc2d7504d802152671535b06d380b26d78070559551cbf92df4fc5", size = 33085 }, +] + +[[package]] +name = "retro-games" +version = "2.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "blessed" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/61/4d/f1f75a461f4e78d743046c906b8e9e0b609f1ed905f7c79fc8d1125acf97/retro_games-2.0.0.tar.gz", hash = "sha256:46ed67bd50139daca0577d486d23e8b8cb1c30cda45226590f9207981cf3948c", size = 14989 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/67/05/cb166180d20f47e4644bba8e0ecf65078c3b007a5106278e1db9ea7734cd/retro_games-2.0.0-py3-none-any.whl", hash = "sha256:03882090bb19e689fdbe173ac31fdf6d5ab7d10881f9b7af21b96588ce3f695a", size = 21787 }, +] + +[[package]] +name = "wcwidth" +version = "0.6.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/35/a2/8e3becb46433538a38726c948d3399905a4c7cabd0df578ede5dc51f0ec2/wcwidth-0.6.0.tar.gz", hash = "sha256:cdc4e4262d6ef9a1a57e018384cbeb1208d8abbc64176027e2c2455c81313159", size = 159684 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/68/5a/199c59e0a824a3db2b89c5d2dade7ab5f9624dbf6448dc291b46d5ec94d3/wcwidth-0.6.0-py3-none-any.whl", hash = "sha256:1a3a1e510b553315f8e146c54764f4fb6264ffad731b3d78088cdb1478ffbdad", size = 94189 }, +]