Welcome to the ultimate Tic Tac Toe showdown! Are you ready to test your wits and strategic prowess? It's time to embark on an epic journey into the world of Xs and Os. You'll face off against a crafty bot, competing to be the first to complete a row, column, or diagonal with your 'X' marks. But beware, the bot won't make victory easy! So, gear up and get ready for an intense battle of wits. Do you have what it takes to outsmart the bot and emerge as the Tic Tac Toe champion? Let's find out!
Given that this program is tailored for terminal use, the emphasis was placed on functionality rather than intricate visual design. The game board and player tokens are represented using basic keyboard letters and symbols, with the added ANSI escape code to provide a visually appealing and engaging experience.
The objective of Tic Tac Toe is to be the first player to get three of your marks in a row, column, or diagonal on the 3x3 game board.
- Open the Tic Tac Toe game on your device.
- In most Tic Tac Toe games, one player is "X," and the other is "O."
- The "X" player usually goes first.
- You'll see a 3x3 grid on the screen, initially empty. Each cell is labeled with a number from 1 to 9, as shown below:
- The "X" player goes first.
- Players take turns to make their moves.
- When it's your turn, you will be prompted to select a cell by entering the corresponding number (e.g., 1, 5, 9).
- The cell you choose will be marked with your symbol ("X" or "O").
- The game continues until one player gets three of their symbols in a row, column, or diagonal. That player wins the game.
- The winning combinations are:
- Three in a row: Across the top, middle, or bottom row.
- Three in a column: Down the left, middle, or right column.
- Three diagonally: From the top-left to the bottom-right or from the top-right to the bottom-left.
- If one player wins, the game will announce the winner.
- If all cells are filled, and no player wins, the game will end in a draw (a tie).
- After a game ends, you can choose to play another round.
- If you want to play again, the game will reset the board, and you can continue playing.
- If you don't want to play again, you can exit the game.
- Have fun playing Tic Tac Toe with your opponent!
- You can try different strategies to outsmart your opponent, but remember that Tic Tac Toe is a game of skill and strategy.
Now you're ready to enjoy a game of Tic Tac Toe! Take turns, plan your moves, and aim to be the first to get three in a row. Good luck and have fun!
Custom layout Say hello to our wicked terminal setup and rad background image. It's like we're giving your game an exclusive VIP lounge
Interactive Guide New to the game? No worries! We've got an interactive guide that'll teach you how to play like a pro, right on your custom background.
Randomly Smart Bot Challenge a bot that makes clever, random moves. It's not just any bot; it's a stylish and smart one.
Winning Highlight When you emerge victorious, we'll make sure your epic moves shine brightly against the custom background.
Tie or Draw If no one conquers the grid, we'll call it a draw. Tic-Tac-Toe drama at its finest, set against a stylish backdrop.
Play Again Feel like another round? You can restart the epic showdown with a single keystroke, all on your sleek custom terminal.
Coming up son
Multiplayer Mode Challenge your friends and see who's the ultimate champion.
AI Bot Opponent Test your skills against our cunning AI bot.
The selected data model for our Tic Tac Toe game, a two-dimensional list representing the 3x3 game board, is the most suitable choice. This model perfectly mirrors the game's structure and simplifies game logic. It aligns seamlessly with the game's rules, enabling intuitive player interactions and streamlined win checks.
This data model's simplicity and efficiency offer excellent flexibility for potential future features like larger grids, additional players, or alternative win conditions, making it the ideal choice to keep the game adaptable and entertaining while staying true to the classic Tic Tac Toe experience.
I've given this project a solid manual run-through, just to make sure everything's smooth and snappy. I also ran it through a PEP* inter, and it's all clear on that frontโno problems to see here.
I threw some curveballs too, like tossing in strings when it expected numbers and venturing into out-of-bounds territory. The game handled it like a champ.
To top it off, I gave it a spin on my trusty local terminal and even unleashed it in the wilds of the Code Institute Heroku terminal. It's all good, no hiccups.
We managed to prevent unintended terminal output printed red after handling invalid input by applying the continue
get_user_next_move definition. This statement allows us to skip the current loop iteration when invalid input is detected, ensuring that only valid inputs are processed and displayed in the terminal, thus improving the user experience.
def get_user_next_move(board):
'''
Get user to input next move by typing a number from 1 to 9.
It's not going to let you move to a spot that's already been claimed.
'''
while True:
try:
next_move = int(input("What's your move, superstar? Pick a number from 1 to 9: "))
if validate_move(next_move, board):
move, mark = (next_move, 'X')
board = update_board(board, move, mark)
return board
except ValueError:
print(ANSI_RED + f'Oops, that\'s not a valid move. Try again, champ!' + ANSI_RESET)
continue
Our bug-busting adventure is ever going!
This project was brought to life using Code Institute's mock terminal for Heroku ๐
- Here's the playbook:
- First, fork or clone this epic repo.
- Head over to Heroku and create a brand-new app.
- Set the buildpacks like a pro โ Python and Node.js, in that order.
- Now, link your Heroku app to the repo where the action's happening.
- Finally, just tap that 'Deploy' button like a champ! ๐ฅ
Watch your game come to life on Heroku
_Web trinity +
- Python
- HTML
- CSS
- JS
_Toolkit
- VS Code, coding
- draw.io , flowchart
- Git, version controlling
- GitHub, sharing, deploying, and other cool stuff
Indeed, I've been the lone architect behind the planning, design, and code, but I couldn't have pulled it off without some helping hands. And honestly, I wouldn't want it any other way. The collaborative spirit of programming is truly one of the things I cherish the most about this journey.
- unsplash
- 'Cause it makes everything look oh-so-pretty!
- Chat GPT
- This AI buddy was the brain behind it all. It's been our chit-chat partner throughout.
def get_winner_moves(board):
'''
Snag the game-winning moves!
'''
winning_moves = []
for combination in winning_combinations:
if all(board[row][col] == 'X' for row, col in combination):
winning_moves.extend(combination)
elif all(board[row][col] == 'O' for row, col in combination):
winning_moves.extend(combination)
return winning_moves
- Code Institute's Love Sandwiches
- Clever Programmer
- David Calikes, Code Institute Cohort Facilitator.
- Positive and Uplifting. David's Always available and boosts my confidence time we chat.
- Oluwafemi Medale, Code Institute Mentor.
- Bugs terminator. He always make times, when there's no time at all.
- Chat GPT, Here comes Mister know it all again.
- Documenting King. Not always correct, but frequently inspiring.