BlockSlide is 3x3 puzzle game and interactive NFT where players attempt to solve puzzle game driven by NFT contract itself. Quality of solution impacts the outcome NFT while providing a complete interactive music experience. Every combination of moves done results in a unique and pleasant music built from a initial set of 16 indivial music files with hundreds of thousands of combination possible. NFT itself is a replay of user's solution of puzzle with traits depending on quality of solution
Replay of moves user did to solve puzzle
Score assigned based on moves count compared to least possible moves
Different display traits assigned based on score
Unique music in each NFT generated based on solution
Combination of puzzle and solution results in a unique music associated with NFT
Every user will get unique music based on moves done to solve puzzle
Hundreds of thousands of unique music possible
Contract code at https://github.com/naman14/BlockSlide/blob/main/cadence/FlowPuzzleNFT.cdc
Contract determines shuffling order for each tokenId
User solves the puzzle, user’s solution moves are packed in a format that is highly gas efficient
Mint function is called by user with packed moves
Contract verifies the moves with the original shuffle order determined by the contract itself.
Contract saves the packed moves of user for interactive NFT metadata and replay NFTBlock
Keeping the full logic of 3v3 puzzle game on chain was challenging. There were multiple challenges.
First step was creating the shuffling order for the puzzle itself. Some shuffling orders are unsolvable puzzles and we had to verify in the contract itself if a puzzle is solvable or not. Contract code needs to do extra shuffling iterations for such cases.
https://github.com/naman14/BlockSlide/blob/0e0cdb8ae2ff4da9dee64fb0e366e20900da4fbd/cadence/FlowPuzzleNFT.cdc#L455
To solve a puzzle, users might take upto 300 moves sometimes or even more. Sending such large move arrays in transaction and storing such large moves array is not feasible. We spent lot of time to efficiently pack user moves array into a highly gas efficient manner. Steps included, changing moves into base 5 (representing left, right up, down as 1,2,3,4) and then chaining them into an indivifual BigNumber of each max 76 digits. This way, we can store upto 76 moves in a single uint256.
https://github.com/naman14/BlockSlide/blob/main/src/onchainmoves.js
Other challenges included creating interactive music experience and the puzzle logic itself in UI, and finding the shortest puzzle solution to calculate relative scores for NFT interactivity
Tracks Applied (2)
Technologies used
Discussion