Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func nextStep(withMCPoints points: [[MCPoint]], andNeighbourhood neighbourhood: Neighbourhood) -> [[MCPoint]] {
- let size = (height: points.count, width: points[0].count)
- var points = MCPoint.clearChosen(forMCPoints: points)
- while MCPoint.chechForNotDrawnElements(forPoints: points) {
- var x = Int(arc4random_uniform(UInt32(size.height)))
- var y = Int(arc4random_uniform(UInt32(size.width)))
- while points[x][y].chosen || points[x][y].selected {
- x = Int(arc4random_uniform(UInt32(size.height)))
- y = Int(arc4random_uniform(UInt32(size.width)))
- }
- let chosenID = points[x][y].id
- let neighbours = neighbourhood.generateNeighbourhood(forMCPoints: points, i: x, j: y)
- let newID = self.drawNewID(forNeighbours: neighbours)
- if self.calculateEnergy(forChosenID: newID, neighbourhood: neighbours) <= self.calculateEnergy(forChosenID: chosenID, neighbourhood: neighbours) {
- points[x][y].id = newID
- }else {
- if arc4random_uniform(100) < 5 {
- points[x][y].id = newID
- }
- }
- points[x][y].chosen = true
- }
- return points
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement