Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.27 KB | None | 0 0
  1.     func nextStep(withMCPoints points: [[MCPoint]], andNeighbourhood neighbourhood: Neighbourhood) -> [[MCPoint]] {
  2.         let size = (height: points.count, width: points[0].count)
  3.         var points = MCPoint.clearChosen(forMCPoints: points)
  4.         while MCPoint.chechForNotDrawnElements(forPoints: points) {
  5.             var x = Int(arc4random_uniform(UInt32(size.height)))
  6.             var y = Int(arc4random_uniform(UInt32(size.width)))
  7.             while points[x][y].chosen || points[x][y].selected {
  8.                 x = Int(arc4random_uniform(UInt32(size.height)))
  9.                 y = Int(arc4random_uniform(UInt32(size.width)))
  10.             }
  11.             let chosenID = points[x][y].id
  12.             let neighbours = neighbourhood.generateNeighbourhood(forMCPoints: points, i: x, j: y)
  13.             let newID = self.drawNewID(forNeighbours: neighbours)
  14.             if self.calculateEnergy(forChosenID: newID, neighbourhood: neighbours) <= self.calculateEnergy(forChosenID: chosenID, neighbourhood: neighbours) {
  15.                 points[x][y].id = newID
  16.             }else {
  17.                 if arc4random_uniform(100) < 5 {
  18.                     points[x][y].id = newID
  19.                 }
  20.             }
  21.             points[x][y].chosen = true
  22.         }
  23.         return points
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement