Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Some structured programming design techniques: [ A ] Your S 1 ( for Game 1 ) may be defined as follows: # Nice to show

Some structured programming design techniques:
[A] Your S1(for Game 1) may be defined as follows:
# Nice to show row index 0 to 8 and column index 0 to 8 for readability of your code
S1=[ # Game 1
# column index: 012345678
[1,2,3,4,5,6,7,8,9], # Python row 0|| Users row 1
[2,3,4,5,6,7,8,9,1], # 12
[3,4,5,6,7,8,9,1,2], # 23
[4,5,6,7,8,9,1,2,3], # 34
[5,6,7,8,9,1,2,3,4], # 45
[6,7,8,9,1,2,3,4,5], # 56
[7,8,9,1,2,3,4,5,6], # 67
[8,9,1,2,3,4,5,6,7], # 78
[9,1,2,3,4,5,6,7,8]] # 89
# Python column 012345678
# Users column 123456789
----------------------------------------------------------------------------------------------------------------------.
[B] Your main program may have the following code to drive your game 1.
n =1 # line number for each separation line for readability
print()
print(n,"=============================================================");n=n+1;
print("Your game 1 is as follows: ")
showGame(S1) # to print 9x9 game board
print()
print(n,"=============================================================");n=n+1;
print("Your game 1: ") # show the check result
checkGame(S1) # to check 9 rows/columns/squares. Total 27 checkings.
print()
print(n,"=============================================================");n=n+1;
You may have similar code to drive your game 2 to 4.
--------------------------------------------------------------------------------------------------------------------------.
[C] Your checkGame() function must call the following 3 functions:
RowOK(S1, row) to check row: 0 through 8(meaning Row 1 through 9 from users view).
ColumnOK(S1, column) to check column: 0 through 8(meaning Column 1 through 9 from users view).
SquareOK(S1, square) to check square: 0 through 8(meaning Square 1 through 9 from users view).
-----------------------------------------------------------------------------------------------------------------------------.
[D] Your checkGame() function may look as follows:
def checkGame(S): # check game board S for 9 rows, 9 columns, 9 squares
countBad =0 # count how many problems being detected
for r in range(9): # 9 rows check with r =0 to 8
if (not RowOK(S, r)): # r =0 to 8 from computers view
print("Row ", r +1," has a problem.") # Row 1 to 9 from users view
countBad +=1 # increment countBad by 1
for c in range(9): # 9 columns check: 0 to 8, actually they mean column 1 to 9 for user.
# more your coding here ################### if (not ColumnOK(S, c)):
for q in range(9): # 9 squares check: 0 to 8, actually they mean square 1 to 9 for user.
# more your coding here ################### if (not SquareOK(S, q)):
if countBad ==0: # perfect game since nothing is bad
print("Congratulations! You won the game.")
----------------------------------------------------------------------------------------------------------------------.
[E] Your RowOK() function may look as follows:
def RowOK(S, r): # check Row r in S board is OK or not
goodlist =[1,2,3,4,5,6,7,8,9] # a perfect list of 1 thru 9 sorted order
slist = S[r] # get row r, which can be 0,1,..., or 8
clist =[] # We must make a real copy of the original source list to avoid changing it here.
for element in slist:
clist.append(element) # make a real copy to avoid side effect to the original 9x9 array
clist.sort() # sort the list before comparing with goodlist
return (clist == goodlist) # true means OK for row r in S since they are equal
# end of RowOK()
Your ColumnOK(S, c) and SquareOK(S, q) functions are similar to RowOK(S, r) function.
--------------------------------------------------------------------------------------------------------------------------.
[F1] How to define Slist1 to be Square 1?
Slist1=[S[0][0],S[0][1],S[0][2],S[1][0],S[1][1],S[1][2],S[2][0],S[2

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_2

Step: 3

blur-text-image_3

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions