That's a Ultimate Tic-Tac-Toe game implementation in Python with some rule changes.
- Contributors
- Requirements
- Game Rules changes
- Boards and Game Classes
- Players Classes
- If you want to use our classes
- Play the game
Participants | nUSP |
---|---|
João Guilherme Alves Santos | 11819560 |
Heitor Barroso Cavalcante | 12566101 |
Nathan Luiz Bezerra Martins | 11805061 |
Some player classes are using NumPy's arrays, you need to install it.
Moreover, if you want to run our tests you have to install Pytest. If you want to have more details about the test, install pytest-cov.
The difference between the original Ultimate Tic Tac Toe's game and this one is that every turn the player can choose any local board to play. In this game, you can't play in a local board that already has a winner.
This repository has three boards classes and a Game class:
Generic board class, used as a base class of the other two.
- Methods:
def check_winner(self)
The check_winner method checks if the board has a winner or has no more valid moves.
This class represents the local board.
- Methods:
def play(self,row,col,player)
The play method makes plays in the board. The arguments row is the row that you want to make your play (1 <= row <= 3), col is the column you want to play (1<= col <= 3) and player is your team's mark ("X" or "O").
This class represents the global board. The Mega board has a attribute called grid_mega that is a 3x3 list of local boards where the plays will happen.
- Methods:
def play(self,wich,row,col,player)
Almost the same as Mini's play, but this one has a argument called wich that represents the local board that you want to play ( 1 <= wich <= 9).
def show()
The show method prints the global board with all the local boards inside.
Example:
When a local board has a X shape, the X player has won that local board. Same to local board with O shape.
This class represents an Ultimate Tic-Tac-Toe game.
- Initialize: To initialize a Game class you have to pass two players as arguments. For example:
game = Game(player1, player2)
- Methods:
def reset(self)
The reset method cleans the entire game and keeps the players that were playing.
def playing(self)
The playing method runs the entire game and stops when someone won the game or all cell's are filled.
def show_winner(self)
The show_winner method prints the winner of the game or when the game tied.
This repository has three player types:
-
Clumsy
Makes random plays. -
Noob
Always play in the first empty position in a valid board. -
Human
Reads plays in the standard input.
To initialize a player class you have to pass "X" or "O" as argument to choose your team mark. For example:
player1 = Noob("X")
Firstly, being in the same directory of the files in this repository, you will have to type "python3" in your console.
Then, you'll have entered in python's interative mode.
Now, the user has to import "boards" and "players", trailing the following steps:
>>> from boards import *
>>> from players import *
Then, you should define the players, for example, in a Human x Clumsy mode:
>>> player1 = Human("X")
>>> player2 = Clumsy("O")
Now, the only thing left is to play!
>>> game = Game(player1, player2)
>>> game.playing
All you'll have to do is, create a .py file and type the following lines (in this example, the Noob x Human mode is shown):
from boards import *
from players import *
player1 = Noob("X")
player2 = Human("O")
game = Game(player1, player2)
game.playing()
The game is in Uttt.py. You just need run the file and the game starts.
At first, it will ask the type of the players that will play. You have to type 1 for Human, 2 for Noob, or another number for Clumsy.
After that, the game will start.
Enjoy!