gymconnectx


Namegymconnectx JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/fauzisho/GymConnectX
SummaryAn OpenAI Gymnasium 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.
upload_time2024-07-09 10:19:31
maintainerNone
docs_urlNone
authorFauzi Sholichin
requires_python>=3.9
licenseMIT License Copyright (c) 2024 Fauzi Sholichin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords connect4 gymnasium pygame reinforcement learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ConnectX Game Environment

This repository contains the implementation of a Connect Game Environment using OpenAI's Gym and Pygame for rendering. The environment supports various game modes like Connect 4 and includes features like GUI display, avatar support for players, and different modes of player interaction (human, random).


![demo.png](demo.png)

## Table of Contents

- [Description](#description)
- [Installation](#installation)
- [Usage](#usage)
- [Setting Player Mode](#setting-player-modes)
- [Parameters](#connectgameenv-class)

## Description

The Connect Game Environment is a customizable and interactive environment for simulating Connect-style games. It leverages the OpenAI Gym interface for standard reinforcement learning interactions and uses Pygame for graphical rendering. The environment allows for different configurations of the board size and connect length and includes support for different player types, including human players and random agents.

## Installation

To use this environment, you need to have Python installed. You can install the necessary packages using `pip`:

```bash
pip install gymconnectx
```

## Usage

```
import gymconnectx


def run_game_env():
    env = gymconnectx.gym.make('gymconnectx/ConnectGameEnv',
                               connect=4,
                               width=7,
                               height=6,
                               reward_winner=1,
                               reward_loser=-1,
                               reward_living=0,
                               reward_draw=0.5,
                               reward_hell=-0.5,
                               max_steps=100,
                               delay=100,
                               square_size=100,
                               avatar_player_1='img_cat.png',
                               avatar_player_2='img_dog.png')
    env.reset()

    while not env.is_done and env.current_step < env.max_steps:
        try:
            move = env.set_players(player_1_mode='random', player_2_mode='random')
            observations, rewards, done, _, info = env.step(move)
            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}, "
                  f"Done: {done}, "
                  f"Info: {info}")

            print(env.get_game_status())

            if done:
                break
            else:
                env.current_step += 1

        except Exception as e:
            print(f"An error occurred: {str(e)}")
            break


if __name__ == "__main__":
    run_game_env()
```

## Setting Player Modes
You can set different player modes using the set_players method. Here are some examples:

### Example 1: Both Players Make Random Moves
```
move = env.set_players(player_1_mode='random', player_2_mode='random')
```

### Example 2: Player 1 Makes Moves Through the Terminal, Player 2 Makes Random Moves
```
move = env.set_players(player_1_mode='human_terminal', player_2_mode='random')
```

### Example 3: Player 1 Makes Moves Through the GUI, Player 2 Makes Random Moves
```
move = env.set_players(player_1_mode='human_gui', player_2_mode='random')
```

### Example 4: Player 1 Makes Moves Through the GUI, Player 2 Follows a Custom Policy
```
if env.get_current_player() == 1:
    move = env.set_players(player_1_mode='human_gui')
else:
    move = env.get_action_random()  # Add your policy here
```

### Example 5: Both Players Make Moves Through the GUI
```
move = env.set_players(player_1_mode='human_gui', player_2_mode='human_gui')
```

# ConnectGameEnv Class

The `ConnectGameEnv` class is designed to simulate a Connect 4-like game environment, allowing customization through various parameters to accommodate different rules and interfaces. Below are the parameters it accepts:

Please use this bibtex if you want to cite this repository in your publications:

    @misc{pytorchaaac,
      author = {Sholichin, Fauzi},
      title = {ConnectX Game Environment},
      year = {2024},
      publisher = {GitHub},
      journal = {GitHub repository},
      howpublished = {\url{https://github.com/fauzisho/GymConnectX}},
    }

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/fauzisho/GymConnectX",
    "name": "gymconnectx",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "connect4, gymnasium, pygame, reinforcement learning",
    "author": "Fauzi Sholichin",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/98/06/071f43573d5d1b7b5214e14f941368bc2c32249a8654a6ab6a5df72bc166/gymconnectx-2.0.0.tar.gz",
    "platform": null,
    "description": "# ConnectX Game Environment\n\nThis repository contains the implementation of a Connect Game Environment using OpenAI's Gym and Pygame for rendering. The environment supports various game modes like Connect 4 and includes features like GUI display, avatar support for players, and different modes of player interaction (human, random).\n\n\n![demo.png](demo.png)\n\n## Table of Contents\n\n- [Description](#description)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Setting Player Mode](#setting-player-modes)\n- [Parameters](#connectgameenv-class)\n\n## Description\n\nThe Connect Game Environment is a customizable and interactive environment for simulating Connect-style games. It leverages the OpenAI Gym interface for standard reinforcement learning interactions and uses Pygame for graphical rendering. The environment allows for different configurations of the board size and connect length and includes support for different player types, including human players and random agents.\n\n## Installation\n\nTo use this environment, you need to have Python installed. You can install the necessary packages using `pip`:\n\n```bash\npip install gymconnectx\n```\n\n## Usage\n\n```\nimport gymconnectx\n\n\ndef run_game_env():\n    env = gymconnectx.gym.make('gymconnectx/ConnectGameEnv',\n                               connect=4,\n                               width=7,\n                               height=6,\n                               reward_winner=1,\n                               reward_loser=-1,\n                               reward_living=0,\n                               reward_draw=0.5,\n                               reward_hell=-0.5,\n                               max_steps=100,\n                               delay=100,\n                               square_size=100,\n                               avatar_player_1='img_cat.png',\n                               avatar_player_2='img_dog.png')\n    env.reset()\n\n    while not env.is_done and env.current_step < env.max_steps:\n        try:\n            move = env.set_players(player_1_mode='random', player_2_mode='random')\n            observations, rewards, done, _, info = env.step(move)\n            env.render(mode='terminal_display')\n            env.render(mode='gui_update_display')\n\n            print(f'Observation: {observations}')\n            print(f\"Step: {env.current_step}, \"\n                  f\"Move: {move}, \"\n                  f\"Rewards: {rewards}, \"\n                  f\"Done: {done}, \"\n                  f\"Info: {info}\")\n\n            print(env.get_game_status())\n\n            if done:\n                break\n            else:\n                env.current_step += 1\n\n        except Exception as e:\n            print(f\"An error occurred: {str(e)}\")\n            break\n\n\nif __name__ == \"__main__\":\n    run_game_env()\n```\n\n## Setting Player Modes\nYou can set different player modes using the set_players method. Here are some examples:\n\n### Example 1: Both Players Make Random Moves\n```\nmove = env.set_players(player_1_mode='random', player_2_mode='random')\n```\n\n### Example 2: Player 1 Makes Moves Through the Terminal, Player 2 Makes Random Moves\n```\nmove = env.set_players(player_1_mode='human_terminal', player_2_mode='random')\n```\n\n### Example 3: Player 1 Makes Moves Through the GUI, Player 2 Makes Random Moves\n```\nmove = env.set_players(player_1_mode='human_gui', player_2_mode='random')\n```\n\n### Example 4: Player 1 Makes Moves Through the GUI, Player 2 Follows a Custom Policy\n```\nif env.get_current_player() == 1:\n    move = env.set_players(player_1_mode='human_gui')\nelse:\n    move = env.get_action_random()  # Add your policy here\n```\n\n### Example 5: Both Players Make Moves Through the GUI\n```\nmove = env.set_players(player_1_mode='human_gui', player_2_mode='human_gui')\n```\n\n# ConnectGameEnv Class\n\nThe `ConnectGameEnv` class is designed to simulate a Connect 4-like game environment, allowing customization through various parameters to accommodate different rules and interfaces. Below are the parameters it accepts:\n\nPlease use this bibtex if you want to cite this repository in your publications:\n\n    @misc{pytorchaaac,\n      author = {Sholichin, Fauzi},\n      title = {ConnectX Game Environment},\n      year = {2024},\n      publisher = {GitHub},\n      journal = {GitHub repository},\n      howpublished = {\\url{https://github.com/fauzisho/GymConnectX}},\n    }\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Fauzi Sholichin  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "An OpenAI Gymnasium 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.",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/fauzisho/GymConnectX"
    },
    "split_keywords": [
        "connect4",
        " gymnasium",
        " pygame",
        " reinforcement learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1a221ee58b790a7bb3aff4ae7a6ba3b71bc62f208c2ca9bc72aee82629d1beda",
                "md5": "d558fc946d904dc53921196296218766",
                "sha256": "c3648dbc7c1a6df1156ba4085ace29aef129dadc61a0fcbfe9c04561a031b3ef"
            },
            "downloads": -1,
            "filename": "gymconnectx-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d558fc946d904dc53921196296218766",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 12398,
            "upload_time": "2024-07-09T10:19:30",
            "upload_time_iso_8601": "2024-07-09T10:19:30.511838Z",
            "url": "https://files.pythonhosted.org/packages/1a/22/1ee58b790a7bb3aff4ae7a6ba3b71bc62f208c2ca9bc72aee82629d1beda/gymconnectx-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9806071f43573d5d1b7b5214e14f941368bc2c32249a8654a6ab6a5df72bc166",
                "md5": "2d52201dd42f39a2ff08d434e6865b6e",
                "sha256": "082dba2a1dcb2f78f8d4dba8fea6d8da8e552b7c97f46dc9e3af343eda688a15"
            },
            "downloads": -1,
            "filename": "gymconnectx-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2d52201dd42f39a2ff08d434e6865b6e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 13693,
            "upload_time": "2024-07-09T10:19:31",
            "upload_time_iso_8601": "2024-07-09T10:19:31.839151Z",
            "url": "https://files.pythonhosted.org/packages/98/06/071f43573d5d1b7b5214e14f941368bc2c32249a8654a6ab6a5df72bc166/gymconnectx-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-09 10:19:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fauzisho",
    "github_project": "GymConnectX",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "gymconnectx"
}
        
Elapsed time: 0.26513s