def geefVrijstand(self, huis, index): vrijstand = 2000 for i in range(len(self.houses) - self.bodies): if i == index: pass else: temp = checkVrijstand(huis, self.houses[i]) if temp < vrijstand: vrijstand = temp return vrijstand - huis.minVrij
def swappen(combinatie): random.shuffle(combinatie.houses) huis1 = combinatie.houses[0] huis2 = combinatie.houses[1] while huis1.type == huis2.type or huis1.type == "Water" or huis2.type == "Water": random.shuffle(combinatie.houses) huis1 = combinatie.houses[0] huis2 = combinatie.houses[1] xH1 = huis1.hoekpunt.x yH1 = huis1.hoekpunt.y xH2 = huis2.hoekpunt.x yH2 = huis2.hoekpunt.y swap(huis1, huis2) mogelijk = True if xH1 - huis1.minVrij < 0 or xH1 + huis1.width + huis1.minVrij > combinatie.map.width: mogelijk = False elif yH1 - huis1.minVrij < 0 or yH1 + huis1.length + huis1.minVrij > combinatie.map.length: mogelijk = False elif xH2 - huis2.minVrij < 0 or xH2 + huis2.width + huis2.minVrij > combinatie.map.width: mogelijk = False elif yH2 - huis2.minVrij < 0 or yH2 + huis2.length + huis2.minVrij > combinatie.map.length: mogelijk = False if mogelijk == True: for i in range(2, len(combinatie.houses)): if checkVrijstand(huis1, combinatie.houses[i]) < huis1.minVrij: mogelijk = False elif checkVrijstand(huis2, combinatie.houses[i]) < huis2.minVrij: mogelijk = False if mogelijk != True: swap(huis1, huis2) return False return True