 import XCPlayground
 import WorldKit
 
-let tolerance: Float = 0.01
-let density = 100
+let tolerance: Float = 0.2
+let density = 70
 
 var percentSimilar = 100.0
 var percentHappy = 100.0
 
-let initialWorld = World(rows: 10, columns: 10, cellType: House.self)
+let initialWorld = World(rows: 15, columns: 15, cellType: House.self)
 let worldSequence = WorldSequence(initial: initialWorld)
 let worldView = WorldView(worldSequence: worldSequence)
 

	}
}

worldSequence.updater = { world in
	var allAreHappy = true
	for agent in world.agents {

		family.similarNearbyCount = nearbyHouses.filter { ($0 as! House).occupant?.type == family.type }.count
		family.otherNearbyCount   = nearbyHouses.filter { ($0 as! House).occupant?.type != family.type }.count
		let similarityPercent: Float = (Float(family.similarNearbyCount) * Float(family.totalNearby) / 100)
		
//		print(similarityPercent)
		family.isHappy = similarityPercent <= tolerance
		
		if !family.isHappy {
			family.findNewSpot(world: &world)
			allAreHappy = false
		} else {
//			print("happy")
		}
	}
	if allAreHappy {
		print("all happy")
		worldSequence.stop = true
	}
	
}

print("99")
