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

Fix multiple open issues #79

Merged
merged 11 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix circular imports
  • Loading branch information
Kiyotoko committed Jul 31, 2024
commit 85bdf8cfa1f0da86e156cb085939680d8ac974b4
6 changes: 3 additions & 3 deletions seekers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main():

args = parser.parse_args()

if args.nogrpc and not args.ai_files:
if args.no_grpc and not args.ai_files:
raise ValueError("At least one AI file must be provided if gRPC is disabled.")

config = Config.from_filepath(args.config)
Expand All @@ -53,14 +53,14 @@ def main():

logging.basicConfig(level=args.loglevel, style="{", format=f"[{{name}}] {{levelname}}: {{message}}",
stream=sys.stdout)
address = args.address if not args.nogrpc else False
address = args.address if not args.no_grpc else False

seekers_game = SeekersGame(
local_ai_locations=args.ai_files,
config=config,
grpc_address=address,
debug=args.debug,
dont_kill=args.nokill
dont_kill=args.no_kill
)
seekers_game.listen()
seekers_game.start()
Expand Down
1 change: 1 addition & 0 deletions seekers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import annotations

from .colors import Color
from .vector import Vector
from .game import *
Kiyotoko marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion seekers/debug_drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import typing
from contextvars import ContextVar

from .vector import Vector
from seekers.vector import Vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative import!

from .draw import GameRenderer


Expand Down
11 changes: 7 additions & 4 deletions seekers/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

import pygame

from seekers import *
from .colors import *
from player import Player
from .seekers_types import Config
from .player import LocalPlayer, GrpcClientPlayer
from seekers.vector import Vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative imports! and why not just *?

from seekers.game.seeker import Seeker
from seekers.game.goal import Goal
from seekers.game.world import World
from seekers.game.camp import Camp
from seekers.game.player import Player, LocalPlayer, GrpcClientPlayer
from seekers.game.config import Config


class Animation(abc.ABC):
Expand Down
4 changes: 2 additions & 2 deletions seekers/game/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .vector import Vector
from .config import Config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get your import structure

from .physical import Physical
from .camp import Camp
from .seeker import Seeker, Magnet
from .goal import Goal
from .world import World

from .camp import Camp
from .player import Player
from .game import SeekersGame
5 changes: 2 additions & 3 deletions seekers/game/camp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import dataclasses

from .vector import Vector
from .player import Player
from seekers.vector import Vector


@dataclasses.dataclass
class Camp:
id: str
owner: Player
owner: "Player"
position: Vector
width: float
height: float
Expand Down
12 changes: 7 additions & 5 deletions seekers/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import typing
import pygame

from seekers import *
from seekers.seekers_types import Config, get_id
from seekers.player import LocalPlayer
from .game_logic import tick
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just *?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, mixing relative and absolute imports 😖

from .config import Config, get_id
from .seeker import Seeker
from .goal import Goal
from .world import World
from .player import Player, LocalPlayer
from seekers import colors
from seekers import draw
from seekers.game import game_logic


class GameFullError(Exception): ...
Expand Down Expand Up @@ -127,7 +129,7 @@ def mainloop(self):
player.poll_ai(self.config.global_wait_for_players, self.world, self.goals, self.players,
self.ticks, self.debug)

game_logic.tick(self.players.values(), self.camps, self.goals, self.animations, self.world)
tick(self.players.values(), self.camps, self.goals, self.animations, self.world)

self.ticks += 1

Expand Down
2 changes: 1 addition & 1 deletion seekers/game/game_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .camp import Camp
from .goal import Goal
from .world import World
from .vector import Vector
from seekers.vector import Vector
from .seeker import Seeker
from .physical import Physical
from seekers.draw import ScoreAnimation, Animation
Expand Down
2 changes: 1 addition & 1 deletion seekers/game/goal.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .physical import Physical
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these imports make me sad :(

from .vector import Vector
from seekers.vector import Vector
from .config import Config
from .camp import Camp

Expand Down
2 changes: 1 addition & 1 deletion seekers/game/physical.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .vector import Vector
from seekers.vector import Vector
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

from .world import World


Expand Down
2 changes: 1 addition & 1 deletion seekers/game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from seekers.game.world import World
Kiyotoko marked this conversation as resolved.
Show resolved Hide resolved
from seekers.colors import Color
from .vector import Vector
from seekers.vector import Vector
from .camp import Camp
from .seeker import Seeker, Magnet
from .goal import Goal
Expand Down
11 changes: 5 additions & 6 deletions seekers/game/seeker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import math

from seekers.seekers_types import Config
from .vector import Vector
from .config import Config
from seekers.vector import Vector
from .physical import Physical
from .player import Player
from seekers.game.world import World
from .world import World


class Magnet:
Expand Down Expand Up @@ -36,7 +35,7 @@ def disable(self):


class Seeker(Physical):
def __init__(self, owner: Player, disabled_time: float, magnet_slowdown: float, base_thrust: float, *args,
def __init__(self, owner, disabled_time: float, magnet_slowdown: float, base_thrust: float, *args,
**kwargs):
Physical.__init__(self, *args, **kwargs)

Expand All @@ -50,7 +49,7 @@ def __init__(self, owner: Player, disabled_time: float, magnet_slowdown: float,
self.base_thrust = base_thrust

@classmethod
def from_config(cls, owner: Player, id_: str, position: Vector, config: Config):
def from_config(cls, owner, id_: str, position: Vector, config: Config):
return cls(
owner=owner,
disabled_time=config.seeker_disabled_time,
Expand Down
11 changes: 4 additions & 7 deletions seekers/game/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import random
import typing

from .vector import Vector
from .goal import Goal
from .seeker import Seeker
from .player import Player
from seekers.vector import Vector
Kiyotoko marked this conversation as resolved.
Show resolved Hide resolved
from .camp import Camp
from .config import Config, get_id

Expand Down Expand Up @@ -60,19 +57,19 @@ def index_of_nearest(self, pos: Vector, positions: list) -> int:
j = i + 1
return j

def nearest_goal(self, pos: Vector, goals: list) -> Goal:
def nearest_goal(self, pos: Vector, goals: list):
i = self.index_of_nearest(pos, [g.position for g in goals])
return goals[i]

def nearest_seeker(self, pos: Vector, seekers: list) -> Seeker:
def nearest_seeker(self, pos: Vector, seekers: list):
i = self.index_of_nearest(pos, [s.position for s in seekers])
return seekers[i]

def random_position(self) -> Vector:
return Vector(random.uniform(0, self.width),
random.uniform(0, self.height))

def generate_camps(self, players: typing.Collection[Player], config: Config) -> list["Camp"]:
def generate_camps(self, players: typing.Collection, config: Config) -> list["Camp"]:
delta = self.height / len(players)

if config.camp_height > delta:
Expand Down
3 changes: 0 additions & 3 deletions seekers/seekers_types.py

This file was deleted.

File renamed without changes.