from connect4cell2 import Connect4Cells
make sure the file you are importing is saved as connect4cell2.py
self.cells = Connect4Cells(rows, columns, 3)
self.cells can now use any of the instances methods like
row_flag = self.cells.checkRow(rowIndex)
you have to supply the rowIndex value
sneekula
Nearly a Posting Maven
2,483 posts since Oct 2006
Reputation Points: 1,000
Solved Threads: 231
Skill Endorsements: 2
You could also have a list of win squares instead of checking for rows, diagonals, and columns separately. The following is pseudo-code:
def check_row(self, row):
control=this_column[0]
for column in row
## not occupied or not all the same
if column == 0 or column != control:
return False
return True
def checkWin(self):
## check rows
for j in range(self.rows)
result = self.check_row(self.rows[j]) ## or just use for row in self.rows
if result:
print "Winner is player", self.player
return result, self.player
## check_column would be the same as check_row, i.e. you could use
## the same function if you sent it a list of all rows[0] instead
## for example, and the same for diagonals
result = check_column()
result = check_diagonal()
woooee
Posting Maven
2,707 posts since Dec 2006
Reputation Points: 827
Solved Threads: 780
Skill Endorsements: 9
Question Answered as of 5 Months Ago by
sneekula
and
woooee