Skip to main content

A library simplifying the process of embedding a TicTacToe game in your python project.

Project description

Lemon-TicTacToe

A tic tac toe python library aiming to make it easy to implement TicTacToe into whatever project you like.
My first attempt at making a python library.

Features

  • Creating TicTacToe games of various board sizes
  • Interacting with the game without a forced event loop

Requirements

  • Python 3.9 or higher

Getting started

pip install lemon-tictactoe

Usage

Setting up the game

You can easily create a game by instantiating the TicTacToeGame class.
The default options will result in a traditional TicTacToe game.

from lemon_tictactoe import TicTacToeGame

game = TicTacToeGame()

But you are also able to pass various configuration options to get a more custom experience:

from lemon_tictactoe import TicTacToeGame

game = TicTacToeGame(board_size=10, player_count=5, starting_player=2)

Grid coordinates

The coordinates (0, 0) are at the top left of the board.
Here is a visual representation of the board coordinates (x, y) with board_size=3:
TicTacToe Board Coordinates

Playing moves

You can use the TicTacToeGame.move method, specifying a player and x,y coordinates to play a move.
This will make Player 1 play their move on x=1 and y=2:

win = game.move(1, 1, 2)

The move method will return True if it lead to a win of the specified player.

Handling invalid move input

Sometimes players might do moves which are not allowed, you can catch errors to handle these cases:

from lemon_tictactoe import TicTacToeGame, CellOccupiedError, WrongPlayerError

game = TicTacToeGame()

try:
    game.move(1, 1, 2)
except ValueError:
    print("Move out of bounds or otherwise invalid input.")
except CellOccupiedError:
    print("The specified cell is already occupied.")
except WrongPlayerError:
    print("Wrong player tried to play a turn.")

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

lemon_tictactoe-0.2.3.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

lemon_tictactoe-0.2.3-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file lemon_tictactoe-0.2.3.tar.gz.

File metadata

  • Download URL: lemon_tictactoe-0.2.3.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for lemon_tictactoe-0.2.3.tar.gz
Algorithm Hash digest
SHA256 0df36374e5a5530675146e9d0d288767f5de17c096875bf461cfdc33bb50083a
MD5 a1c83f36ee466526056d94763f1c4045
BLAKE2b-256 511d9083b78a067121bb9832020c33ef7016c84a9d9343efe0e8fa6300d5a0ef

See more details on using hashes here.

File details

Details for the file lemon_tictactoe-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for lemon_tictactoe-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 32771f0d299be3e4e7d906c356277a5787ead4a5f4ea3805175df11a5dfaa6cb
MD5 8fed69dcd3244898e5563ea0091d70be
BLAKE2b-256 6a935fdfb2b48da84a554a39e1267e07e09d70cd8a59706a18a060017b00c754

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page