Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

This is my Python Tic Tac Toe code I am supposed to add check for winner I can't figure out how! ROWS = 3 COLS = 3 board = [[*]* COLS for...

This is my Python Tic Tac Toe code

I am supposed to add check for winner

I can't figure out how! please help!

ROWS = 3

COLS = 3

board = [["*"]* COLS for i in range(ROWS)]

def TicTacBoard(board):

  for row in range(0,ROWS):

    for col in range(0,COLS):

      if col <= 1:

        print (" "+board[row][col]+" |",end="")

      else:

        print(" "+board[row][col]) 

    if row <= 1:

      print("-----------")

def makeMove(player):

  validMove = False

  while not(validMove):

    row = int(input("Enter row of your move between 1 and 3:"))

    col = int(input("Enter col of your move between 1 and 3:"))

    if (1 <= row <=3) and (1 <= col <= 3):

      row = row -1

      col = col -1

      if board[row][col] == "*":

        board[row][col] = player

        validMove = True

      else:

        print("That square is taken. Please try again")

    else:

      print("Both row and column must be between 1 and 3. Please try again")

#main

moves = 0

play = "X"

while moves < 9:

  TicTacBoard(board)

  print("player",play,"your move")

  makeMove(play)

  moves = moves + 1

  if play == "X":

    play = "O"

  else:

    play = "X"

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question