I just finished Tic tac toe game as my first python project. This is a very simple classic game, for beginners in programming tic-tac-toe game is the best choice. I am using Jupyter notebook, you can use any python ide like Pycharm, Spyder etc.
Scenario of tic-tac-toe game:
Your task is to write a simple program which pretends to play Tic-tac-toe game with the user. To make it easier for you. We have decided to simplify the game. Here are our assumptions.
- the computer should play a game using 'X'
- the user should play a game using 'O'
- the first move belongs to the computer, it always 'X' in the middle of the board.
- all squares are numbered row by row, start with '1'.
- the user move is to enter the number of the square they choose, the number must be valid, that is it must be an integer, it must be greater than 0 and less than 10, and it cannot point to a field which is already occupied.
- the program checks the game is over, there are four possibilities- the game should continue, the game should tie, computer's win and you win.
- don't implement any form of artificial intelligence's, a random field is chosen by a computer this is enough for the game.
Requirements to build tic-tac-toe game:
- Better knowledge about if-elif-else, for-while loop, tuple, list, function.
- Draw a random function you can use randrange()
from random import randrange
for i in range(10): print(randrange(8))
1. Display Board function of tic-tac-toe game:
The function accepts one parameter containing the board's current status and prints it out to the console.
2.Enter a move:
The function accepts the board current status, asks the user about their move, checks the input and updates the board according to the user's decision.
3. Make a list of the free field:
The function browses the board, builds a list of all the free squares and the list consists of tuples, while each tuple is a pair of row-column numbers.
4.Victory for :
The function analyzes the board status to check if the player using 'O's or 'X's has won the game.
5.Draw move:
The function draws the computer's move and updates the board.
I am developer and i make a website check it.
ReplyDeleteHi. Can you share the code please? (able to be copied)
ReplyDeleteHello, at the victor, the last if it's actually: board[2-rc][rc] != sign so it can take the other cross correctly.
ReplyDelete