An implementation of the Tic Tac Toe game rules
Project description
Tic Tac Toe Engine
Implementation of the rules of the game "Tic tac toe".
This project can be use as:
- An engine for a game (Both CLI and paired with a game library like Pygame).
- A tool for AI training.
This project implements all the logic needed to play the tic tac toe game.
Example usage (a CLI implementation):
from tic_tac_toe_engine import Engine
from typing import Union
def print_board(board: list[Union[str, None]]) -> None:
""" Print the board """
print("") # Some space
for i in range(0, 9, 3):
row = " | ".join(board[j] if board[j] is not None else str(j) for j in range(i, i + 3))
print(row)
if i < 6: # Add a line between rows, but not after the last row
print("-" * 9)
engine = Engine()
while True:
print_board(engine.board)
print(f"\n{engine.current_player} moves.")
move = int(input("Enter your move (0 - 8): "))
engine.play_move(move)
if engine.is_over():
print_board(engine.board) # Print again to reflect the ending
if engine.is_tie():
print("It's a tie")
else:
print(f"{engine.winner} wins!")
break
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tic-tac-toe-engine-0.1.0.tar.gz.
File metadata
- Download URL: tic-tac-toe-engine-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc7619212ec8125d447611d0ad5cbec13ae111e04155cd6f1011a7c3f060cd4f
|
|
| MD5 |
6532f7a799a4f5a418ef375849ef7854
|
|
| BLAKE2b-256 |
e80025c7915a5c3e9cee4b4969d3e14ee04b773b30d73f997b7e572faee00cc0
|
File details
Details for the file tic_tac_toe_engine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tic_tac_toe_engine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d9069442e9d779aad855287510aadb8a28e639a2807a60d540c1f6c5f2a626a
|
|
| MD5 |
1613622e529eeb755c7c15a253e82174
|
|
| BLAKE2b-256 |
57ca9684b39d47d99f764adeb202a99ab50cdc0f9175955cf8a8c9d0d1efaf06
|