def getWinner(self, board, pos): """Returns the player (boolean) who won, or None if nobody won""" tests = [] tests.append(board.getCol(pos[0])) tests.append(board.getRow(pos[1])) tests.append(board.getDiagonal(True, pos[0] - pos[1])) tests.append(board.getDiagonal(False, pos[0] + pos[1])) for test in tests: color, size = utils.longest(test) if size >= 4: return color
def getWinner2(self,pos,grille): #Reformulation de la fonction getWinner du module game tests = [] tests.append(grille.getCol(pos[0])) tests.append(grille.getRow(pos[1])) tests.append(grille.getDiagonal(True, pos[0] - pos[1])) tests.append(grille.getDiagonal(False, pos[0] + pos[1])) for test in tests: color, size = utils.longest(test) if size >= 4: return color return 0
def is_ended(self, pos, board): # checks wether the game is ended or not """Returns whether the game is over or not""" tests = [] tests.append(board.getCol(pos[0])) tests.append(board.getRow(pos[1])) tests.append(board.getDiagonal(True, pos[0] - pos[1])) tests.append(board.getDiagonal(False, pos[0] + pos[1])) for test in tests: color, size = utils.longest(test) if size >= 4: return True return False
def getWinner(self, pos): """Returns the player (boolean) who won, or None if nobody won""" tests = [] tests.append(self.board.getCol(pos[0])) tests.append(self.board.getRow(pos[1])) tests.append(self.board.getDiagonal(True, pos[0] - pos[1])) tests.append(self.board.getDiagonal(False, pos[0] + pos[1])) for test in tests: color, size = utils.longest(test) if size >= self.winning_length: for player in self.players: if player.color == color: return player
def playerGetWinner(self, board, pos): test = board.getCol(pos[0]) color, size = utils.longest(test) # print(pos[1]) // debug only ''' this is for deciding the winners ''' if size < 4: test = board.getRow(pos[1]) color, size = utils.longest(test) if size < 4: test = board.getDiagonal(True, pos[0] - pos[1]) color, size = utils.longest(test) if size < 4: test = board.getDiagonal(False, pos[0] + pos[1]) color, size = utils.longest(test) if size < 4: return self.evaluate(board, pos) if self.color == color: return 999 else: return -999
def hasWon(self, board, player, pos): tests = [] tests.append(board.getCol(pos[0])) tests.append(board.getRow(pos[1])) tests.append(board.getDiagonal(True, pos[0] - pos[1])) tests.append(board.getDiagonal(False, pos[0] + pos[1])) for test in tests: color, size = utils.longest(test) if size >= 4: if player == color: return math.inf else: return -math.inf return None