Question: The class GameBoard is used to implement the game board ( grid ) . In Section 1 you will implement basic functionality including adding a
The class GameBoard is used to implement the game board grid In Section you will implement basic functionality including adding a disk into the board, testing whether a game is finished, and displaying the game board.
The class GameBoard is defined as follows:
class GameBoard:
def initself size:
self.size size
self.numdisks size
self.items size for i in rangesize
self.points
The variable size specifies the size of the game board, ie the number size of columns and rows. You can assume that size and you dont need to test for this.
The variable numdisks is a list, which specifies the number of disks in each column. The initial value for each column is zero.
The game board itself is represented by the D array items. This is a list of lists. The first dimension refers to the column number and the second dimension to the row number, ie itemsij is the value of the item in the ith column and jth row. Each item is initialised with the value meaning no disk The value will represent a disk of player and the value a disk of player
The variable points represents the points number of lines of connected pieces of each player: points are the points of player and points are the points of player
So here is the source code from me so far.
class GameBoard:
def initself size:
self.size size
self.numdisks size
self.items size for i in rangesize
self.points
def numfreepositionsincolumnself column:
return self.size self.numdiskscolumn
def gameoverself:
return allnumdisk self.size for numdisk in self.numdisks
def displayself:
for row in rangeselfsize :
for col in rangeselfsize:
if self.itemscolrow:
print end
elif self.itemscolrow:
printo end
elif self.itemscolrow:
printx end
print
printselfsize
for col in rangeselfsize:
printcol end
print
printPoints player : self.points
printPoints player : self.points
def numnewpointsself column, row, player:
return
def addself column, player:
if column or column self.size or self.numdiskscolumn self.size:
return False
row self.numdiskscolumn
self.itemscolumnrow player
self.numdiskscolumn
self.pointsplayer self.numnewpointscolumn row, player
return True
and I need help with the question in the image below with some test cases and expected result.
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
