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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 20PE
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning