Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
fauzisho committed May 19, 2024
1 parent cbd2daf commit a308998
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,5 @@ The `ConnectGameEnv` class is designed to simulate a Connect 4-like game environ
- **max_steps** (int): The maximum number of steps the game can take before it ends. Default is `100`.
- **delay** (int): Time delay (in milliseconds) between moves, primarily used for GUI purposes. Default is `100`.
- **square_size** (int): Size of the squares in the GUI. Default is `100`.
- **avatar_player_1** (string): Base64 format avatar image for player 1. This is used in the GUI.
- **avatar_player_2** (string): Base64 format avatar image for player 2. This is used in the GUI.
- **avatar_player_1** (string): Base64/path format avatar image for player 1. This is used in the GUI.
- **avatar_player_2** (string): Base64/path format avatar image for player 2. This is used in the GUI.
1 change: 1 addition & 0 deletions run_env.py → demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def run_game_env():
env.render(mode='terminal_display')
env.render(mode='gui_update_display')

print(f'Observation: {observations}')
print(f"Step: {env.current_step}, "
f"Move: {move}, "
f"Rewards: {rewards}, "
Expand Down
13 changes: 4 additions & 9 deletions gymconnectx/envs/gymconnectxenv.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import re
import urllib
import urllib.request
from typing import List
import io
import gym
from gym.spaces import Box, Discrete, Tuple
import base64
import imgBase64
import pygame
import sys
import numpy as np
Expand Down Expand Up @@ -65,16 +66,10 @@ def load_image_from_path(self, path):
"""Loads an image from a local file path and resizes it."""
return self.process_image(pygame.image.load(path))

def load_image_from_url(self, url):
"""Loads an image from a URL and resizes it."""
with urllib.request.urlopen(url) as response:
image_data = response.read()
return self.process_image(pygame.image.load(io.BytesIO(image_data)))

def load_avatar(self, avatar_string):
"""Determines the type of the avatar input and loads the image accordingly."""
if self.is_url(avatar_string):
return self.load_image_from_url(avatar_string)
if avatar_string is None:
return None
elif self.is_base64(avatar_string):
return self.load_image_from_base64(avatar_string)
elif avatar_string is not None:
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "gymconnectx"
version = "1.0.3"
version = "1.0.4"
description = "An OpenAI Gym Environment Connect X Game with GUI. ConnectX is a game for two players that is based on the well-known Connect 4. The goal is to place X coins in a row, column, or diagonal on a board with dimensions M by N."
readme = "README.md"
authors = [{ name = "Fauzi Sholichin" }]
Expand All @@ -14,7 +14,7 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
]
keywords = ["tictactoe", "gym", "pygame"]
keywords = ["connect4", "gym", "pygame", "reinforcement learning"]
dependencies = ["gym", "pygame"]
requires-python = ">=3.9"

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='gymconnectx',
version='1.0.3',
version='1.0.4',
description='ConnectX is a game for two players that is based on the well-known Connect 4. The goal is to place X coins in a row, column, or diagonal on a board with dimensions M by N.',
url='https://github.com/fauzisho/GymConnectX',
author='Fauzi Sholichin',
Expand Down

0 comments on commit a308998

Please sign in to comment.