We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SwiftUI-2048/SwiftUI2048/Models/GameLogic.swift
Line 131 in 34f315a
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 }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
SwiftUI-2048/SwiftUI2048/Models/GameLogic.swift
Line 131 in 34f315a
This function can be optimized like this so that it can create any nums of blocks.
The text was updated successfully, but these errors were encountered: