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
Close
Hashes for tic_tac_toe_engine-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d9069442e9d779aad855287510aadb8a28e639a2807a60d540c1f6c5f2a626a |
|
MD5 | 1613622e529eeb755c7c15a253e82174 |
|
BLAKE2b-256 | 57ca9684b39d47d99f764adeb202a99ab50cdc0f9175955cf8a8c9d0d1efaf06 |