-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Description
@discardableResult fileprivate func generateNewBlocks() -> Bool { |
This function can be optimized like this so that it can create any nums of blocks.
@discardableResult fileprivate func generateNewBlock() -> Bool {
var blankLocations = [BlockMatrixType.Index]()
for rowIndex in 0..<4 {
for colIndex in 0..<4 {
let index = (colIndex, rowIndex)
if _blockMatrix[index] == nil {
blankLocations.append(index)
}
}
}
guard blankLocations.count >= 1 else {
return false
}
// Don't forget to sync data.
defer {
objectWillChange.send(self)
}
_blockMatrix.place(IdentifiedBlock(id: newGlobalID, number: 2), to: blankLocations.randomElement()!)
return true
}
@discardableResult fileprivate func generateNewBlocks(_ num: Int = 1) -> Bool {
guard num > 0 else {
return false
}
for _ in 0..<num {
if !generateNewBlock() {
return false
}
}
return true
}
Metadata
Metadata
Assignees
Labels
No labels