Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Python: Help writing the winner module for tictactoe code. Need help adding a checkWinner ( p , board ) function where p is the parameter
Python: Help writing the winner module for tictactoe code. Need help adding a checkWinnerpboard function where p is the parameter for player whose move it is that is p is parameter for the argument player either X or O and board is the dimensional list array that is the checkerboard. The function should return a Boolean that is True if the player won and False otherwise. My code: def main: # initializes board and alternates getting player's moves # and checking for winner after moves and if moves cat's game gameOver False playerX moveCounter board while not gameOver: #get player move printBoardboard moveCountermoveCounter if moveCounter : printcats game" break getMoveplayerboard if moveCounter : gameOvercheckWinnerplayerboard if playerX: playerO else: playerX def printBoardb: print print bbb print print bbb print print bbb print def getMovepb: validMove False while not validMove: move inputplayer p enter valid untaken square on board shown above: if move and move and lenmove: row intmove col intmove if browcolX or browcolO: printsquare on board taken try again" else: validMoveTrue browcol p else: printnot valid square on board try again" def checkWinnerpb: # check rows, cols and diagonals printcheck winner player",p #this print statement is a "program stub" #to be removed when you add checkWinner logic main
Python: Help writing the winner module for tictactoe code.
Need help adding a checkWinnerpboard function where p is the parameter for player whose move it is that is p is parameter for the argument player either X or O and board is the dimensional list array that is the checkerboard. The function should return a Boolean that is True if the player won and False otherwise.
My code:
def main:
# initializes board and alternates getting player's moves
# and checking for winner after moves and if moves cat's game
gameOver False
playerX
moveCounter
board
while not gameOver:
#get player move
printBoardboard
moveCountermoveCounter
if moveCounter :
printcats game"
break
getMoveplayerboard
if moveCounter :
gameOvercheckWinnerplayerboard
if playerX:
playerO
else:
playerX
def printBoardb:
print
print bbb
print
print bbb
print
print bbb
print
def getMovepb:
validMove False
while not validMove:
move inputplayer p enter valid untaken square on board shown above:
if move and move and lenmove:
row intmove
col intmove
if browcolX or browcolO:
printsquare on board taken try again"
else:
validMoveTrue
browcol p
else:
printnot valid square on board try again"
def checkWinnerpb:
# check rows, cols and diagonals
printcheck winner player",p #this print statement is a "program stub"
#to be removed when you add checkWinner logic
main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started