Please see and run attached code: test.py. You need to convert test.py into new code using: function, OOP and exception handling. The code should as the user to key-in the size of playing grid (e.g., 3x3, 6x6, ..etc). For example current grid and final should be printed using function. In addition, invali input should be handled. You need to develop three main classes: Board Player, GameState. Each class must be implemented and tested. It is ex pected that your program can accept various grid sizes, so all input should b set automatically based on the gird size. You must use the same names fo classes (Board, Player, GameState) and functions. The main steps are: 1. Once you run the program, the user will be prompted with a menu. 2. The user will need to enter their choice. 3. The choice will be to either begin the game, or quit. 4. If the user enters an invalid choice, the user should be prompted appro priately letting them choose once more. 5. The program should not end unless the user chooses otherwise.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Test.py

 

 

 

## test
# 3 * 3 grid : board
grid = [' *','* ','*','*','*','*','*','*','*']


# we have two players denomted as "X" and "O"

play=True
count=0

while play:
# add first player
add_x=True
# loop to add player
while add_x:
# at which postion you would like to add the player
player_postion_x=int(input ("Enter postion for player X: "))
## add X player into the board
if grid[player_postion_x-1]!="X" and grid[player_postion_x-1]!="O":
grid[player_postion_x-1]="X"
add_x=False
#to count the number of added players
count=count+1
else:
print ("The postion has been taken")
if grid[0]=="X" and grid[1]=="X" and grid[2]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[3]=="X" and grid[4]=="X" and grid[5]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[6]=="X" and grid[7]=="X" and grid[7]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[0]=="X" and grid[3]=="X" and grid[6]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[1]=="X" and grid[4]=="X" and grid[7]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[2]=="X" and grid[5]=="X" and grid[8]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[0]=="X" and grid[4]=="X" and grid[8]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[2]=="X" and grid[4]=="X" and grid[6]=="X":
print ("Player X win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break

print(grid[0:3])
print(grid[3:6])
print(grid[6:9])

add_o=True

## add O player
player_postion_O=int(input ("Enter postion for player O: "))

while add_o:
# at which postion you would like to add the player
player_postion_O=int(input ("Enter postion for player O: "))
## add X player into the board
if grid[player_postion_x-1]!="X" and grid[player_postion_x-1]!="O":
grid[player_postion_x-1]="O"
add_o=False
#to count the number of added players
count=count+1
else:
print ("The postion has been taken")
if grid[0]=="O" and grid[1]=="O" and grid[2]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[3]=="O" and grid[4]=="O" and grid[5]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[6]=="O" and grid[7]=="O" and grid[7]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[0]=="O" and grid[3]=="O" and grid[6]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[1]=="O" and grid[4]=="O" and grid[7]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[2]=="O" and grid[5]=="O" and grid[8]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[0]=="O" and grid[4]=="O" and grid[8]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break
elif grid[2]=="O" and grid[4]=="O" and grid[6]=="O":
print ("Player O win")
print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
break

print(grid[0:3])
print(grid[3:6])
print(grid[6:9])
if count==9:
print ("Game Over")

Please see and run attached code: test.py . You need to convert test.py into a
new code using: function, OOP and exception handling. The code should ask
the user to key-in the size of playing grid (e.g., 3x3, 6x6, ..etc). For example,
current grid and final should be printed using function. In addition, invalid
input should be handled. You need to develop three main classes: Board,
Player, GameState. Each class must be implemented and tested. It is ex-
pected that your program can accept various grid sizes, so all input should be
set automatically based on the gird size. You must use the same names for
classes (Board, Player, GameState) and functions.
The main steps are:
1. Once you run the program, the user will be prompted with a menu.
2. The user will need to enter their choice.
3. The choice will be to either begin the game, or quit.
4. If the user enters an invalid choice, the user should be prompted appro-
priately letting them choose once more.
5. The program should not end unless the user chooses otherwise.
Transcribed Image Text:Please see and run attached code: test.py . You need to convert test.py into a new code using: function, OOP and exception handling. The code should ask the user to key-in the size of playing grid (e.g., 3x3, 6x6, ..etc). For example, current grid and final should be printed using function. In addition, invalid input should be handled. You need to develop three main classes: Board, Player, GameState. Each class must be implemented and tested. It is ex- pected that your program can accept various grid sizes, so all input should be set automatically based on the gird size. You must use the same names for classes (Board, Player, GameState) and functions. The main steps are: 1. Once you run the program, the user will be prompted with a menu. 2. The user will need to enter their choice. 3. The choice will be to either begin the game, or quit. 4. If the user enters an invalid choice, the user should be prompted appro- priately letting them choose once more. 5. The program should not end unless the user chooses otherwise.
6. If the user begins the game, the game will be terminated if one player win
the game or all playing grid square have been filled up with neither player
winning.
Transcribed Image Text:6. If the user begins the game, the game will be terminated if one player win the game or all playing grid square have been filled up with neither player winning.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY