Skip to content

Commit

Permalink
Lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
Kiyotoko committed Jul 31, 2024
1 parent 230e1d9 commit cc78197
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion seekers/game/camp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@dataclasses.dataclass
class Camp:
id: str
owner: "Player"
owner: object
position: Vector
width: float
height: float
Expand Down
6 changes: 4 additions & 2 deletions seekers/game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from seekers import draw


class GameFullError(Exception): ...
class GameFullError(Exception):
...


class SeekersGame:
Expand All @@ -42,8 +43,8 @@ def __init__(self, local_ai_locations: typing.Iterable[str], config: Config,
self._logger.warning("Config option `global.wait-for-players=false` is not supported for local players.")

if grpc_address and len(self.players) < config.global_players:
from seekers.grpc.server import GrpcSeekersServer
try:
from .grpc.server import GrpcSeekersServer
self.grpc = GrpcSeekersServer(self, grpc_address)
except ImportError as e:
self._logger.warning("gRPC server could not be started. Import error.", exc_info=e)
Expand All @@ -61,6 +62,7 @@ def __init__(self, local_ai_locations: typing.Iterable[str], config: Config,
)
self.animations = []

self.clock = None
self.ticks = 0

def start(self):
Expand Down
3 changes: 1 addition & 2 deletions seekers/game/goal.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Goal(Physical):
def __init__(self, scoring_time: float, base_thrust: float, *args, **kwargs):
Physical.__init__(self, *args, **kwargs)

self.owner: "Player | None" = None
self.owner = None
self.time_owned: int = 0

self.scoring_time = scoring_time
Expand Down Expand Up @@ -40,4 +40,3 @@ def camp_tick(self, camp: "Camp") -> bool:
self.owner = camp.owner

return self.time_owned >= self.scoring_time

1 change: 0 additions & 1 deletion seekers/game/physical.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,3 @@ def collision(self, other: "Physical", world: "World"):
if ddn < min_dist:
self.position += dn * (ddn - min_dist)
other.position -= dn * (ddn - min_dist)

5 changes: 2 additions & 3 deletions seekers/game/seeker.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def disabled(self):
return self.is_disabled

def magnetic_force(self, world: World, pos: Vector) -> Vector:
def bump(r) -> float:
return math.exp(1 / (r ** 2 - 1)) if r < 1 else 0
def bump(difference) -> float:
return math.exp(1 / (difference ** 2 - 1)) if difference < 1 else 0

torus_diff = world.torus_difference(self.position, pos)
torus_diff_len = torus_diff.length()
Expand Down Expand Up @@ -131,4 +131,3 @@ def set_magnet_disabled(self):
@property
def max_speed(self):
return self.base_thrust / self.friction

4 changes: 2 additions & 2 deletions seekers/game/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def middle(self) -> Vector:
return self.geometry / 2

def torus_difference(self, left: Vector, right: Vector, /) -> Vector:
def diff1d(l, a, b):
def diff1d(length, a, b):
delta = abs(a - b)
return b - a if delta < l - delta else a - b
return b - a if delta < length - delta else a - b

return Vector(diff1d(self.width, left.x, right.x),
diff1d(self.height, left.y, right.y))
Expand Down
14 changes: 7 additions & 7 deletions seekers/tests/test_seekers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest

from seekers import Config
from seekers.seekers_types import LocalPlayerAi
from seekers.game.player import LocalPlayerAi
from seekers.game import SeekersGame
from seekers.grpc.client import GrpcSeekersServiceWrapper, GrpcSeekersClient

Expand Down Expand Up @@ -34,7 +34,7 @@ def test_speed_consistency(self):

for speed in 1, 1, 10, 10, 20, 40:
with self.subTest(msg=f"Speed: {speed}", speed=speed):
new_scores = nogrpc_game(
new_scores = no_grpc_game(
playtime=2000,
speed=speed,
players=2,
Expand Down Expand Up @@ -107,7 +107,7 @@ def grpc_game(playtime: int, speed: int, players: int, seed: int, filepaths: lis
return {player.name: player.score for player in game.players.values()}


def nogrpc_game(playtime: int, speed: int, players: int, seed: int, filepaths: list[str]) -> dict[str, int]:
def no_grpc_game(playtime: int, speed: int, players: int, seed: int, filepaths: list[str]) -> dict[str, int]:
config = Config.from_filepath("config.ini")

config.global_fps = 1000
Expand Down Expand Up @@ -143,11 +143,11 @@ def test_grpc(self):
address="localhost:7778"
)

def test_grpc_nogrpc_consistency(self):
"""Test that the outcome of a game is the same for grpc and nogrpc."""
def test_grpc_no_grpc_consistency(self):
"""Test that the outcome of a game is the same for grpc and no grpc."""
for seed in 40, 41, 42, 43, 44, 45:
with self.subTest(msg=f"Seed: {seed}", seed=seed):
nogrpc_scores = nogrpc_game(
no_grpc_scores = no_grpc_game(
playtime=2000,
speed=10,
players=2,
Expand All @@ -164,7 +164,7 @@ def test_grpc_nogrpc_consistency(self):
address="localhost:7778"
)

self.assertEqual(grpc_scores, nogrpc_scores,
self.assertEqual(grpc_scores, no_grpc_scores,
msg=f"Outcome of gRPC and non-gRPC games with seed {seed} is different.")


Expand Down

0 comments on commit cc78197

Please sign in to comment.