Complete this code using python language #Write the conditions to check if anyone has won the game. This function will be called from the placeCharacter function. # r : In which row the current character was placed # c : In which column the current character was placed #returned value: True if anyone has won;Otherwise Flase def checkBoard(r,c): #Write your code here #Write the necessary code to put the "char" in proper position of the board and check if anyone has won. #pos : The position that has been given by the player as input. #char : The character representing the player. It can be X or O.

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
icon
Related questions
icon
Concept explainers
Question

 

Complete this code using python language

#Write the conditions to check if anyone has won the game. This function will be called from the placeCharacter function.
# r : In which row the current character was placed
# c : In which column the current character was placed
#returned value: True if anyone has won;Otherwise Flase
def checkBoard(r,c):
#Write your code here


#Write the necessary code to put the "char" in proper position of the board and check if anyone has won.
#pos : The position that has been given by the player as input.
#char : The character representing the player. It can be X or O.
#count: It represents the number of turns. It can be from 0 to 8.
#returned value: True if anyone has won;Otherwise Flase
def placeCharacter(pos,char,count):
#Write your code here



def gameInitialization():
global player1,player2
player1 = input("Enter player 1's name:")
player2 = input("Enter player 2's name:")
print(f"{player1}, your character is X")
print(f"{player2}, your character is O")

def runGame():
counter = 0
f=False
p_name=None
while counter<9:
printBoard()
if counter%2==0:
if (placeCharacter(input(f"{player1}, where do you want to place 'X':"),'X',counter)):
p_name = player1
f = True
break
else:
if (placeCharacter(input(f"{player2}, where do you want to place 'O':"),'O',counter)):
p_name = player2
f = True
break
counter+=1
printBoard()
if f == False:
print("The game ends in a draw.")
else:
print(f"{p_name} has won the game!!!!")

board = [[1,2,3],[4,5,6],[7,8,9]]
player1 = player2 = None #Take input of player names in these 2 variables
gameInitialization()
runGame()

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Control Structure
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.
Similar questions
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education