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 classic environments screen sizes, add type hints, fix pre-commit #998

Merged
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
2 changes: 1 addition & 1 deletion pettingzoo/atari/basketball_pong/basketball_pong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Basketball Pong

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/boxing/boxing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Boxing

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/combat_plane/combat_plane.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Combat: Plane

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/combat_tank/combat_tank.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Combat: Tank

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/double_dunk/double_dunk.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Double Dunk

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Emtombed: Competitive

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Emtombed: Cooperative

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/flag_capture/flag_capture.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Flag Capture

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/foozpong/foozpong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Foozpong

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/ice_hockey/ice_hockey.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Ice Hockey

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/joust/joust.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Joust

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/mario_bros/mario_bros.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Mario Bros

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/maze_craze/maze_craze.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Maze Craze

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/othello/othello.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Othello

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/pong/pong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Pong

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/quadrapong/quadrapong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Quadrapong

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/space_invaders/space_invaders.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Space Invaders

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/space_war/space_war.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Space War

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/surround/surround.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Surround

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/tennis/tennis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Tennis

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/video_checkers/video_checkers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Video Checkers

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/volleyball_pong/volleyball_pong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Volleyball Pong

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/warlords/warlords.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Warlords

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/atari/wizard_of_wor/wizard_of_wor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Wizard of Wor

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/butterfly/cooperative_pong/cooperative_pong.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Cooperative Pong

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Knights Archers Zombies ('KAZ')

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/butterfly/pistonball/pistonball.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Pistonball

Expand Down
13 changes: 8 additions & 5 deletions pettingzoo/classic/chess/chess.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Chess

Expand Down Expand Up @@ -83,6 +83,8 @@
* v0: Initial versions release (1.0.0)

"""
from __future__ import annotations

from os import path

import chess
Expand All @@ -97,8 +99,8 @@
from pettingzoo.utils.agent_selector import agent_selector


def env(render_mode=None):
env = raw_env(render_mode=render_mode)
def env(**kwargs):
env = raw_env(**kwargs)
env = wrappers.TerminateIllegalWrapper(env, illegal_reward=-1)
env = wrappers.AssertOutOfBoundsWrapper(env)
env = wrappers.OrderEnforcingWrapper(env)
Expand All @@ -113,7 +115,7 @@ class raw_env(AECEnv):
"render_fps": 2,
}

def __init__(self, render_mode=None):
def __init__(self, render_mode: str | None = None, screen_height: int | None = 800):
super().__init__()

self.board = chess.Board()
Expand Down Expand Up @@ -149,6 +151,7 @@ def __init__(self, render_mode=None):

assert render_mode is None or render_mode in self.metadata["render_modes"]
self.render_mode = render_mode
self.screen_height = self.screen_width = screen_height

if self.render_mode in {"human", "rgb_array"}:
try:
Expand All @@ -158,7 +161,7 @@ def __init__(self, render_mode=None):
f"pygame is needed for {self.render_mode} rendering, run with `pip install pettingzoo[classic]`"
)

self.BOARD_SIZE = (400, 400)
self.BOARD_SIZE = (self.screen_width, self.screen_height)
self.window_surface = None
self.clock = pygame.time.Clock()
self.cell_size = (self.BOARD_SIZE[0] / 8, self.BOARD_SIZE[1] / 8)
Expand Down
14 changes: 8 additions & 6 deletions pettingzoo/classic/connect_four/connect_four.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Connect Four

Expand Down Expand Up @@ -57,6 +57,7 @@
* v0: Initial versions release (1.0.0)

"""
from __future__ import annotations

import os

Expand All @@ -82,8 +83,8 @@ def get_image(path):
return sfc


def env(render_mode=None):
env = raw_env(render_mode=render_mode)
def env(**kwargs):
env = raw_env(**kwargs)
env = wrappers.TerminateIllegalWrapper(env, illegal_reward=-1)
env = wrappers.AssertOutOfBoundsWrapper(env)
env = wrappers.OrderEnforcingWrapper(env)
Expand All @@ -98,7 +99,7 @@ class raw_env(AECEnv):
"render_fps": 2,
}

def __init__(self, render_mode=None):
def __init__(self, render_mode: str | None = None, screen_scaling: int = 9):
super().__init__()
# 6 rows x 7 columns
# blank space = 0
Expand All @@ -107,6 +108,7 @@ def __init__(self, render_mode=None):
# flat representation in row major order
self.screen = None
self.render_mode = render_mode
self.screen_scaling = screen_scaling

self.board = [0] * (6 * 7)

Expand Down Expand Up @@ -225,8 +227,8 @@ def render(self):
)
return

screen_width = 1287
screen_height = 1118
screen_width = 99 * self.screen_scaling
screen_height = 86 / 99 * screen_width
if self.render_mode == "human":
if self.screen is None:
pygame.init()
Expand Down
22 changes: 13 additions & 9 deletions pettingzoo/classic/go/go.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
r"""
# Go

Expand Down Expand Up @@ -106,9 +106,9 @@
* v0: Initial versions release (1.0.0)

"""
from __future__ import annotations

import os
from typing import Optional

import gymnasium
import numpy as np
Expand Down Expand Up @@ -148,7 +148,11 @@ class raw_env(AECEnv):
}

def __init__(
self, board_size: int = 19, komi: float = 7.5, render_mode: Optional[str] = None
self,
board_size: int = 19,
komi: float = 7.5,
render_mode: str | None = None,
screen_height: int | None = 800,
):
# board_size: a int, representing the board size (board has a board_size x board_size shape)
# komi: a float, representing points given to the second player.
Expand Down Expand Up @@ -191,6 +195,7 @@ def __init__(
self.board_history = np.zeros((self._N, self._N, 16), dtype=bool)

self.render_mode = render_mode
self.screen_width = self.screen_height = screen_height

def observation_space(self, agent):
return self.observation_spaces[agent]
Expand Down Expand Up @@ -333,22 +338,21 @@ def render(self):
)
return

screen_width = 1026
screen_height = 1026

if self.screen is None:
if self.render_mode == "human":
pygame.init()
self.screen = pygame.display.set_mode((screen_width, screen_height))
self.screen = pygame.display.set_mode(
(self.screen_width, self.screen_height)
)
else:
self.screen = pygame.Surface((screen_width, screen_height))
self.screen = pygame.Surface((self.screen_width, self.screen_height))
if self.render_mode == "human":
pygame.event.get()

size = go_base.N

# Load and scale all of the necessary images
tile_size = (screen_width) / size
tile_size = self.screen_width / size

black_stone = get_image(os.path.join("img", "GoBlackPiece.png"))
black_stone = pygame.transform.scale(
Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/classic/hanabi/hanabi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Hanabi

Expand Down
7 changes: 4 additions & 3 deletions pettingzoo/classic/rlcard_envs/gin_rummy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Gin Rummy

Expand Down Expand Up @@ -108,6 +108,7 @@
* v0: Initial versions release (1.0.0)

"""
from __future__ import annotations

import gymnasium
import numpy as np
Expand Down Expand Up @@ -148,8 +149,8 @@ def __init__(
self,
knock_reward: float = 0.5,
gin_reward: float = 1.0,
opponents_hand_visible=False,
render_mode=None,
opponents_hand_visible: bool | None = False,
render_mode: str | None = None,
):
EzPickle.__init__(
self,
Expand Down
9 changes: 7 additions & 2 deletions pettingzoo/classic/rlcard_envs/leduc_holdem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# noqa
# noqa: D212, D415
"""
# Leduc Hold'em

Expand Down Expand Up @@ -80,6 +80,7 @@
* v0: Initial versions release (1.0.0)

"""
from __future__ import annotations

import gymnasium
from rlcard.utils.utils import print_card
Expand Down Expand Up @@ -110,7 +111,11 @@ class raw_env(RLCardBase):
"render_fps": 1,
}

def __init__(self, num_players=2, render_mode=None):
def __init__(
self,
num_players: int = 2,
render_mode: str | None = None,
):
super().__init__("leduc-holdem", num_players, (36,))
self.render_mode = render_mode

Expand Down
2 changes: 1 addition & 1 deletion pettingzoo/classic/rlcard_envs/rlcard_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class RLCardBase(AECEnv):
def __init__(self, name, num_players, obs_shape):
def __init__(self, name: str, num_players: int, obs_shape: tuple):
super().__init__()
self.name = name
self.num_players = num_players
Expand Down
Loading