Stuck at TicTacToe | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Stuck at TicTacToe

I keep getting a class <module> error and an undefined error, any suggestions? import time from playerbase import HumanPlayer, RandomCompPlayer # This sets up the whole gameboard in a 3x3 box. Each empty square reps a digit from 0-8 class Tictactoe: def __init__(self): self.board = [' ' for _ in range(9)] # Uses a single list to rep 3x3 board self.current_winner = None # keeps track of winner def print_board(self): # gets the rows for row in [self.board[i * 3:(i + 1) * 3] for i in range(3)]: print('| ' + '| '.join(row) + ' |') @staticmethod def print_board_nums(): number_board = [[str(i) for i in range(j * 3, (j + 1) * 3)] for j in range(3)] for row in number_board: print('| ' + '| '.join(row) + ' |') def available_moves(self): return [i for i, spot in enumerate(self.board) if spot == ' '] def empty_squares(self): return ' ' in self.board def num_empty_squares(self): return self.board.count(' ') def make_move(self, square, letter): if self.board[square] == ' ': self.board[square] == letter if self.winner(square, letter): self.current_winner = letter return True else: return False def winner(self, square, letter): row_ind = square // 3 row = self.board[row_ind: (row_ind + 1) * 3] if all([spot == letter for spot in row]): return True else: # check column col_ind = square % 3 column = [self.board[col_ind + i * 3] for i in range(3)] if all([spot == letter for spot in column]): return True # check diagonals if square % 2 == 0: # checks for the even numbers on the board that reps the empty squares diagonal1 = [self.board[i] for i in [0, 4, 8]] # left to right diagonal if all([spot == letter for spot in d

26th Sep 2022, 1:49 AM
Kevin Calderon
Kevin Calderon - avatar
3 Answers
+ 4
Kevin Calderon , it's better to put your code in playground, save it and link it here.
26th Sep 2022, 10:17 AM
Lothar
Lothar - avatar
+ 2
Hi Kevin, Your code is longer than which the UI allows, so they just took what they could, I guess. Maybe drop the rest in a response @Kevin Calderon ?
26th Sep 2022, 6:04 AM
l4t3nc1
l4t3nc1 - avatar
+ 2
And link in the question description, removing all the wall of code
27th Sep 2022, 3:37 AM
Emerson Prado
Emerson Prado - avatar