Hello I have been building a tic tac toe game and I am having a hard time with the winning conditions. I am storing all of the squares in play in a list of tuples, each player also has a list of tuples to store the "captured squares"
class Board():
def __init__(self,window, tilesize ,padding ,spaces): # Self is class instance, tilesize is the size of your tiles in pixels, padding is side padding in pixels, spaces is how many rows and colums
self.spaces = spaces # [(x,y)for x in range(0,spaces) for y in range(0,spaces)]
self.padding = padding
self.paddingBottom = self.padding // 2
self.paddingTop = int(self.padding * 1.25)
self.tilesize = tilesize
self.tiles = [(x,y)for x in range(0,3) for y in range(0,3)]
self.window = window
def DrawBoard(self):
for space in range(self.spaces + 1):
#Up and Downs
pygame.draw.line(self.window, (255,0,0),
( self.padding+(space * self.tilesize) ,self.paddingTop ), #start point
( self.padding + (space * self.tilesize), self.paddingTop + ((self.spaces* self.tilesize)) ),) #end point
# Side To Sides
pygame.draw.line(window, (255,0,0),
( self.padding ,self.paddingTop+(space * self.tilesize) ), #start point
( win_width - self.padding , self.paddingTop + (space * self.tilesize)),) #end point
def CheckWin(self,players):
self.player1 = players[0]
self.player2 = players[1]
self.inplay = self.player2.pos + self.player1.pos
print(f'Player1: {self.player1.pos} Player2: {self.player2.pos}')
if type(self.inplay) == 'None':
pass
if type(self.inplay) == 'list':
if len(self.inplay) == len(self.tiles):
print('TIE')
if (0,0) and (1,0) and (2,0) in self.player1.pos.sort():
print('Player 1 wins')
class Player():
def __init__(self, icon, player): #Icon = pygame image Player = string
self.score = 0
self.name = str(player)
self.icon = pygame.transform.scale(icon, (iconSize,iconSize))
self.pos = []
def Draw(self,window,board):
for square in self.pos:
x = ((square[0] * 125 ) + board.padding ) + ((1/8) * tileSize)
y = ((square[1] * 125 ) + board.paddingTop) + ((1/8) * tileSize)
window.blit(self.icon, (x,y))
pygame.display.update()
def CaptureSquare(self, pos, board, enemy):
newpos = round((pos[0] - board.padding)//125), round((pos[1] -board.paddingTop)//125)
if newpos in self.pos:
pass
elif newpos in enemy.pos:
pass
elif newpos[0] >= 0 and newpos[0] < 3 and newpos[1] >= 0 and newpos[1] < 3 :
self.pos.append(newpos)
how can I go through the list and compare it to some win conditions?