Python Forum
My first python game : Tic-Tac-Toe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first python game : Tic-Tac-Toe
#4
Quote:That's very good. Don't you want players? Class files. Or objects in the module.py. They'll have to keep track of times won or how many people are playing in the game.

Yeah, actually I am dodging OOP concepts in my code but I will throw myself into it soon.

Quote:Understanding the game helps reduce the amount of code. Tic-tac-toe is a one player game where the players take turns being the current player. For example, your win_check() functions is very long because your program does not take advantage of the fact that the only the last play can win. After X makes a play there is no need to check of O won. Only X could win. Checking if O won is a waste of time. O can only win when O made the last play.

You start with having the user enter 1-9 to specify what cell to place their marker, but after that you treat the "grid" like it has 3 rows and 3 columns. Making rows and columns makes the game more complicated. I would make the "grid" a list of length 9. The only time I would treat it like a 3x3 matrix is when drawing the board.

Data is better than code. Your win_check is overly complicated because you use code to check all possible winning combinations. I would put most of the winning combination information in a data structure and have a short function that uses the winning combinations to check if the player won.

My second game project is Connect4 with bigger grid than Tic-Tac-Toe, that's why I didn't use winning combo list, I was preparing myself to Connect4. But it's interesting how your code is short. I think now the best is to use both, winning combo list for Tic-Tac-Toe and my win function for Connect4. Thanks to your code, I discovered the all function. I am thinking now how I will make a second version of my Tic-Tac-Toe.
Reply


Messages In This Thread
RE: My first python game : Tic-Tac-Toe - by ForsakenDusk - May-20-2024, 11:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  From python game in terminal to a website game using bottle Njanez 0 3,950 Aug-13-2021, 01:11 PM
Last Post: Njanez

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020