Welcome to 7Wonder-RL-Lib’s documentation!

Readme File

7Wonder-RL-Lib

Library providing environment for testing Reinforcement learning in 7 Wonders Game.

GitHub GitHub issues

codecov CodeQL Build + CodeCov + Pylint/Black PyPI

Overview

There are multiple environments for the AI game testing. However, environments implemented now are mostly covered only the traditional board games (Go, Chess, etc.) or 52-card based card games (Poker, Rummy, etc.) where games do not really have interactions with other players.

Most of the Euro-games board games are good game environments to test the algorithm on as there are many aspects to explore, such as tradings, dealing with imperfect informations, stochastic elements, etc.

7 Wonders board games introduced multiple elements mentioned above which are good for testing out new algorithm. This library will cover basic game systems and allow users to customize the environments with custom state space and rewarding systems.

Installation

To install the gym environment, run

make develop
make build
make install

Usage

Example codes of how to declare the gym environment is displayed below

import SevenWonEnv
from SevenWonEnv.envs.mainGameEnv import Personality

env = gym.make("SevenWonderEnv", player=4) #Declare Environment with 4 Players

To use the Personality that is given (RandomAI, RuleBasedAI, DQNAI, Human), use setPersonality(personalityList)

personalityList = []
    personalityList.append(Personality.DQNAI)
    for i in range(1, 4):
        personalityList.append(Personality.RandomAI)
    env.setPersonality(personalityList)

To run the game each step,

stateList = env.step(None)

The variable stateList consist of n 4-tuple, depends on number of players. Each tuple are (new_state, reward, done, info).

To add the custom model, change the SevenWondersEnv/SevenWonEnv/envs/mainGameEnv/Personality.py file. Each personality will have 2 main functions, which are init and make_choice.

For example, RandomAI takes all possible choices and randomly choose one choice.

class RandomAI(Personality):
    def __init__(self):
        super().__init__()

    def make_choice(self, player, age, options):
        return random.choice(range(len(options)))

Documentation

class SevenWonEnv.envs.SevenWonderEnv.SevenWonderEnv(player)
close()

After the user has finished using the environment, close contains the code necessary to “clean up” the environment.

This is critical for closing rendering windows, database or HTTP connections.

legalAction(playerNum)

Given the player number, return all legal actions as a list of action code

Args:

playerNum: The position of player (1-n)

Returns:

List[actionCode]

render(mode='human')

Compute the render frames as specified by render_mode during the initialization of the environment.

The environment’s metadata render modes (env.metadata[“render_modes”]) should contain the possible ways to implement the render modes. In addition, list versions for most render modes is achieved through gymnasium.make which automatically applies a wrapper to collect rendered frames.

Note:

As the render_mode is known during __init__, the objects used to render the environment state should be initialised in __init__.

By convention, if the render_mode is:

  • None (default): no render is computed.

  • “human”: The environment is continuously rendered in the current display or terminal, usually for human consumption. This rendering should occur during step() and render() doesn’t need to be called. Returns None.

  • “rgb_array”: Return a single frame representing the current state of the environment. A frame is a np.ndarray with shape (x, y, 3) representing RGB values for an x-by-y pixel image.

  • “ansi”: Return a strings (str) or StringIO.StringIO containing a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).

  • “rgb_array_list” and “ansi_list”: List based version of render modes are possible (except Human) through the wrapper, gymnasium.wrappers.RenderCollection that is automatically applied during gymnasium.make(..., render_mode="rgb_array_list"). The frames collected are popped after render() is called or reset().

Note:

Make sure that your class’s metadata "render_modes" key includes the list of supported modes.

Changed in version 0.25.0: The render function was changed to no longer accept parameters, rather these parameters should be specified in the environment initialised, i.e., gymnasium.make("CartPole-v1", render_mode="human")

reset(seed=None, options=None)

Reset the environment after each episode

Args:

seed: Seed ID for randomization options: Default to None

Returns:

List[State]

setPersonality(personalityList)

Set the personality for each player.

Args:

personalityList: List[Personality]

step(action)

Proceed one turn of the game.

Args:

action: 0 by default.

Returns:

List[tuple] containing (new_state, reward, done, info)

Indices and tables