Gym Environment for 3D Tic Tac Toe
Project description
gym-tic-tac-toe3D
OpenAI Gym Environment for a Two-Player 3D Tic-Tac-Toe. Github Link: https://github.com/OUStudent/gym_tic_tac_toe3D
Requirements
- gym
- Numpy
- Matplotlib
Install
pip install gym-tic-tac-toe3D
How it Works
Tic Tac Toe is usually played on a 3x3 grid where the objective is for one player to line up their tokens in a straight line of three. This is an extremely easy and trivial game; however, one can extend the difficulty by stacking 3x3 layers to create a 3x3x3 cube. Now the objective is to line up three tokens in any of the directions.
Here are three example games where the action was randomly generated:
How to Use
The environment is a Two-Player Game, where Blue denotes Player 1 and Red denotes Player 2. The state
and action
contains all 27 possible positions, 9 for the first layer, 9 for the second, and 9 for the third.
The input has three possible integer values for eac position, -1 for opponent, 0 for empty, and 1 for current player. Note that no matter whom the Player is, these values holds true. The reward
is a two value list where the first index represents the reward for Player 1 and the second for Player 2. The reward
value should only be used after the game is completed. Players are rewarded for wins and receive extra points for how fast they win; while players are penalized for losing and how fast they lost. For example, after a game has completed the final reward could be [20, -10]
, which rewards Player 1 20
points while penalizing Player 2 -10
points.
Here is an example on how to create the environment:
import gym
import gym_tic_tac_toe3D
env = gym.make("tic_tac_toe3D-v0")
games = 3 # best of three
player1_reward = 0
player2_reward = 0
for i in range(0, games):
state = env.reset()
done = False
player = 1
while not done:
env.render(player=player)
plt.pause(0.5)
while True:
action = env.action_space.sample()
# Need to check if action is available in state space
if state[action] == 0:
break
state, reward, done, info = env.step(action, player=player)
# switch players
if player == 1:
player = 2
else:
player = 1
# final render after completion of game to see final move
env.render(player=player)
plt.pause(1)
player1_reward += reward[0]
player2_reward += reward[1]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file gym_tic_tac_toe3D-0.0.2.tar.gz
.
File metadata
- Download URL: gym_tic_tac_toe3D-0.0.2.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12c70f8bb9f362fa7d55ac5bd55ad9d44438670ee6702ea2df0efd638f2ba0b3 |
|
MD5 | 340bf60e6172c9db506509c67ce2ea56 |
|
BLAKE2b-256 | 0b8f4d7bc0646f8a646076d0162a521e821403aafa44936e2443adef93ffa370 |