Channel BannerChannel Banner
RavIOC0wkpIRavIOC0wkpI

How To Create A Tic-Tac-Toe Game In Python

1,264
Socialcounts.Org
Enter Fullscreen (f)
182
likes
37
comments
daily view 0
monthly view 0

Share

Live Analytics

Comments 0

How To Create A Tic-Tac-Toe Game In Python Analytics Table

Income Estimates for How To Create A Tic-Tac-Toe Game In Python

Based on this YouTube video's total view count of 1.26K views and industry-standard rates, the estimated total earning is $1 - $3 through ad revenue. Historical data is not yet available to calculate daily, weekly, or monthly averages.

About How To Create A Tic-Tac-Toe Game In Python

Explore How To Create A Tic-Tac-Toe Game In Python with 1,264 views, 182 likes, and 37 comments. Experience the impact of this video content that has captured audience attention.

code : import random class TicTacToe: def __init__(self): self.board = [] def create_board(self): for i in range(3): row = [] for j in range(3): row.append('-') self.board.append(row) def get_random_first_player(self): return random.randint(0, 1) def fix_spot(self, row, col, player): self.board[row][col] = player def is_player_win(self, player): win = None n = len(self.board) # checking rows for i in range(n): win = True for j in range(n): if self.board[i][j] != player: win = False break if win: return win # checking columns for i in range(n): win = True for j in range(n): if self.board[j][i] != player: win = False break if win: return win # checking diagonals win = True for i in range(n): if self.board[i][i] != player: win = False break if win: return win win = True for i in range(n): if self.board[i][n - 1 - i] != player: win = False break if win: return win return False for row in self.board: for item in row: if item == '-': return False return True def is_board_filled(self): for row in self.board: for item in row: if item == '-': return False return True def swap_player_turn(self, player): return 'X' if player == 'O' else 'O' def show_board(self): for row in self.board: for item in row: print(item, end=" ") print() def start(self): self.create_board() player = 'X' if self.get_random_first_player() == 1 else 'O' while True: print(f"Player {player} turn") self.show_board() # taking user input row, col = list( map(int, input("Enter row and column numbers to fix spot: ").split())) print() # fixing the spot self.fix_spot(row - 1, col - 1, player) # checking whether current player is won or not if self.is_player_win(player): print(f"Player {player} wins the game!") break # checking whether the game is draw or not if self.is_board_filled(): print("Match Draw!") break # swapping the turn player = self.swap_player_turn(player) # showing the final view of board print() self.show_board() # starting the game tic_tac_toe = TicTacToe() tic_tac_toe.start() #subscribe #shorts

About YouTube Real-Time View Count

With SocialCounts.org’s view counter, track your YouTube video’s live view count and YouTube likes count in real time with fast, reliable updates.

Watch every YouTube video live view count rise with our real-time YouTube views tracker—built for accuracy and minimal delay.

Follow YouTube real time views as they happen, using our dedicated view counter for YouTube videos.

Get up-to-date live view count on YouTube and see real-time growth with SocialCounts.org’s smart tracking tools.

Embed Widget

Parameters:

  • fullscreen=true - Fullscreen counter
  • graph=true - Live graph chart
  • counter=0/1/2 - Select counter (0=likes, 1=views, 2=comments)
URL

Click to copy the embed URL to your clipboard