Shahrayar123 / Python-Projects

Basic Python projects, good first issue
272 stars 276 forks source link

README. for Tic-Tac-Toe Game #129

Closed amoghakancharla closed 6 months ago

amoghakancharla commented 9 months ago

The code provides a Python implementation of a simple text-based Tic Tac Toe game. The game is played between a human player ('X') and a computer opponent ('O'). Here's a breakdown of how the code works: The board is represented as a list with 10 elements (index 0 is not used). It's initialized with empty spaces (' ') to represent the Tic Tac Toe grid.

There are several functions defined, let us understand each of them in detail:

insertLetter(letter, pos) : Inserts the given letter ('X' or 'O') at the specified position pos on the board.

spaceIsFree(pos) : Checks if the space at position pos on the board is free (contains an empty space).

printBoard(board) : Prints the current state of the board in a visually appealing format.

isBoardFull(board) : Checks if the board is full (no empty spaces left).

isWinner(board, l) : Checks if a player with letter l has won the game by examining all possible win conditions.

userMove( ) : Allows the human player to make a move by inputting a position (1-9) where they want to place their 'X'.

compMove( ) : Implements the computer opponent's logic for making a move. It tries to win, block the player from winning, take corners, take the center if available, and finally take edges.

selectRandom(list_) : Helper function to randomly select an item from a list.

main( ) : The main game loop where the game is played. It alternates between the player and computer moves until there's a winner or a tie.

The game is played in a loop that asks the user if they want to play again after each game. If the user enters 'Y' (case-insensitive), a new game starts; otherwise, the loop exits, and the program ends.

Overall, the code provides a simple implementation of Tic Tac Toe that allows a user to play against a computer opponent. It uses a basic set of rules for the computer's moves and checks for a win or a tie in each game.

Happy Gaming!

CrypticRevenger commented 9 months ago

Please assign me, I want to do it.

Ayush29Ayush commented 9 months ago

Please assign me, this will be my first open source contribution.

bhavanagithub123 commented 6 months ago

Hey, is this issue still available?

amoghakancharla commented 6 months ago

@bhavanagundetigithub I see it's still open. But I did provide the code explanation above. Feel free to add your version :)

amoghakancharla commented 6 months ago

Let me know if you want to add yours, else I can close this one soon.