Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you solve this python code for me? Using the attached code bellow that displays a labeled Pegity board and accepts only valid moves from

can you solve this python code for me? Using the attached code bellow that displays a labeled Pegity board and accepts only valid moves from alternating players and checks for ROW-based winners, add functionality to check for column or diagonal wins. Note that the code will make use of the "list of lists (list of rows)" structure that we discussed in class. This is the only way to keep the state of the game in synch with the graphical board. The real game is not the graphics - it is the list of lists!!!The requirement for MP06 is that the game declares a winner and quits when it finds five consecutive squares in a row column, or diagonal, of the same color. The game should declare the color of the winner in an appropriate message. Here is the starter code: import turtle import random def drawSquare(t): for i in range(4): t.forward(1) t.left(90) def drawBoard(numSquares): wn=turtle.Screen() bob=turtle.Turtle() bob.up() wn.setworldcoordinates(-2,numSquares+1,numSquares+1,-2) wn.tracer(False) #drawing rows and columns of squares for row in range(numSquares): for col in range(numSquares): drawSquare(bob) bob.forward(1) bob.backward(numSquares) bob.left(90) bob.forward(1) bob.right(90) #label the board bob.speed(0) bob.goto(0,0) bob.up() bob.forward(.5) for col in range(numSquares): bob.write(col,align='center',font=('Arial',16,'bold')) bob.forward(1) bob.goto(-.3,0) bob.left(90) bob.forward(.8) for row in range(numSquares): bob.write(chr(row+65),align='center',font=('Arial',16,'bold')) bob.forward(1) wn.tracer(True) bob.goto(numSquares//2,-1) bob.color("black","black") bob.write("PEGITY",align='center',font=('Lucida Calligraphy',20,'bold')) bob.ht() row=['']*15 board=[] for i in range(15): board.append(row[:]) return bob,wn,board def createValidMovesList(): validMovesList=[] for row in "ABCDEFGHIJKLMNO": for col in range(0,15): validMovesList.append(row+str(col)) validMovesList.append("QUIT") return validMovesList def drawPeg(t,move,color,validMovesList,board): row=(ord(move[0]))-65 col=int(move[1:]) board[row][col]=color[0] t.up() t.goto(col+1,row+.5) t.color(color,color) t.down() t.begin_fill() t.circle(.5,360,360) t.end_fill() def getMove(validMovesList,player): move=input(player+" enter a move => ").upper() while move not in validMovesList: print("Bad move! Try again . . .") move=input(player+" enter a move => ").upper() validMovesList.remove(move) return move def randomizeFirstPlayer(): player=random.randint(0,1) if player==0: player="blue" else: player="green" return player def switchPlayer(currentPlayer): if currentPlayer=="blue": currentPlayer="green" else: currentPlayer="blue" return currentPlayer def showBoard(board): for rowList in board: print(rowList) def win(board): for row in range(15): for col in range(15): if board[row][col]!='': #check for row win if col<11: main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions