The parts of the code that need fixing are in the comments. Code is in Python.
The parts of the code that need fixing are in the comments. Code is in Python.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
class TicTacToePlayer:
# Player for a game of Tic Tac Toe
def __init__(self, symbol, name):
self.symbol = symbol
self.name = name
def move(self, board):
move = int(input(self.name + " make your move 1-9:"))
move -= 1
y = move % 3
x = move // 3
board[x][y] = self.symbol
def is_symbol(self, symbol):
if symbol == self.symbol:
return True
class TicTacToe:
# Game of TicTacToe in a class!
def __init__(
self, p1_symbol="X", p2_symbol="O", p1_name="Player1", p2_name="Player2"
):
self.p1 = TicTacToePlayer(p1_symbol, p1_name)
self.p2 = TicTacToePlayer(p2_symbol, p2_name)
self.board = [[" " for x in range(3)] for x in range(3)]
def play_game(self):
turn = 0
winner_symbol = False
while not winner_symbol:
self._print_board()
if turn % 2:
self.p2.move(self.board) # replace this line with a call to self._move
else:
self.p1.move(self.board) # replace this line with a call to self._move
turn += 1
winner_symbol = self._is_over()
self._print_win_from_symbol(winner_symbol)
def _move(self, player):
# Write this method to replace TicTacToePlayer.move
pass
def _print_board(self):
space_num = 1
print("-------")
for row in self.board:
print("|", end="")
for space in row:
if space == " ":
space = space_num
print(space, end="|")
space_num += 1
print()
print("-------")
def _print_win_from_symbol(self, symbol):
self._print_board()
if symbol == "C":
print("The Cat won again!")
elif self.p1.is_symbol(symbol):
print(self.p1.name + " wins!")
else:
print(self.p2.name + " wins!")
def _is_over(self):
blank_count = 0
for x in range(3):
for y in range(3):
if (
self.board[x][0] == self.board[x][1] == self.board[x][2]
and self.board[x][0] != " "
):
return self.board[x][0]
if (
self.board[0][y] == self.board[1][y] == self.board[2][y]
and self.board[0][y] != " "
):
return self.board[0][y]
if self.board[x][y] == " ": blank_count += 1
if (
self.board[0][2] == self.board[1][1] == self.board[2][0]
and self.board[1][1] != " "
):
return self.board[1][1]
if (
self.board[0][0] == self.board[1][1] == self.board[2][2]
and self.board[1][1] != " "
):
return self.board[1][1]
if blank_count == 0:
return "C"
return False
if __name__ == "__main__":
game = TicTacToe()
game.play_game()
The parts of the code that need fixing are in the comments.
Code is in Python.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education