Question: def drop _ disc _ one _ square ( board , x , y ) : def can _ disc _ fall ( board ,
def dropdisconesquareboard x y: def candiscfallboard x y:
Given board and xy location.
Assume xymathrm is in bounds and contains a disc.
Is moving the disc down one square ok
Return True if the disc can fall, or False otherwise.
Disc can fall if the square exactly one space downward is in bounds and empty.Outofbounds OB testsboard yFalseboard Noner NoneNone None, yTrueFalseboard None NoneryFalse
# TODO: What ylocation should you check is in bounds and doesn't already have a disc?
return False def updatewholeboardboard:
Given board, do one round of falling discs over the whole board.
If there is no disc at a location, no need to change the board.
If there is a disc, check if it can fall, then drop the disc,
one square at a time. Call your helper functions from above!
Return the board in all cases.
tests provided, code TBDupdatewholeboardboard
yryNone None, rNoney NoneyryNone None, rNone None, y
for y in reversedrangelenboard:
for x in rangelenboard:pass
return board
def checkhorizontalwinboard player:
Takes in the board and a player's token y for player
or r for player
Returns True if the player has tokens in a row horizontally
anywhere on the board and False if otherwise.
for y in rangelenboard:
for x in rangelenboard:pass
return False def checkverticalwinboard player:
Takes in the board and a player's token y for player
or r for player
Returns True if the player has tokens in a row vertically
anywhere on the board and False if otherwise.
for y in rangelenboard:
for x in rangelenboard:pass
return False
def checkdiagonalwinsboard player:
PROVIDED DO NOT EDIT
Takes in a board and a player's token.
Check if that player wins by getting inarow in two diagonal
directions, toplefttodownright and bottomlefttotopright.
for y in rangelenboard:
for x in rangelenboard:
if
boardxy player
and boardxy player
and boardxy player
and boardxy player
:
return Truefor y in rangelenboard:
for x in range lenboard:
if
boardxy player
and boardxy player
and boardxy player
and boardxy player
:
return Truedef checkwinboard player:
Takes in a board and a player's token.
Check if that player wins by calling each helper boolean function.
Return True if the player wins in any of the ways, False if not.
primeHint: this is where decomposition helps with readability!
isplayerdiagonalwinner checkdiagonalwinsboard player
return isplayerdiagonalwinner
def isfullboard:
primeprimeprime
PROVIDED DO NOT EDIT
Take in a board and return True if all the slots are filled.
Ignores the top row since that is invisible and not treated as the board.
prime
for y in range lenboard:
for x in rangelenboard:
if boardxy is None:
return False
return True
Given board and xy location containing a disc.
Move the disc one square downwards and return the resulting board.
Assume that this is a legal move: all coordinates are in
bounds, the location contains a disc, and the square below is empty.
ie a different function checks that this is a
legal move before dropdisconesquare is called
Note: the board is a list of equallylengthed lists. Each inner list
represents one whole column in the board. For example, board
is the entire first column in the Connect board, from top to bottom.
tests provided, code TBDdropdisconesquareboard
NoneryNoney Noneboard ry NoneNoney Nonery NoneNone None, y
disc boardxy # is either y for Player Yellow or r for Player Redcurrent location and write it again at the square below?
return board
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
