Liar games
Minority Rule Game on Flow blockchain - vote strategically, survive elimination, win the prize pool!
Problem Statement
Minority Rule Game - A Blockchain Implementation of the Psychological Strategy Game from Liar GameMinority Rule Game is a fully decentralized psychological strategy game inspired by the Japanese drama series "Liar Game", built on the Flow blockchain using Cadence smart contracts. This game brings the intense psychological warfare and strategic voting mechanics from the TV series into the Web3 space.Core Game Mechanics: Players stake FLOW tokens to enter the game and participate in elimination rounds where they must vote on binary (YES/NO) questions. The twist: those who vote with the minority survive while the majority gets eliminated. This creates a fascinating game theory dynamic where players must predict and counter-predict group behavior. The game continues until fewer than 3 players remain, with winners splitting the entire prize pool.Key Features:Fully On-Chain Game Logic: All game mechanics handled by smart contracts ensuring trustless, transparent gameplayStrategic Voting System: Private vote submission with simultaneous reveal after deadline to prevent manipulationPlayer Reputation System: Complete voting history and statistics tracked on-chain, allowing players to analyze opponents' patternsDynamic Prize Pool: Entry fees accumulate into winner-takes-all prize pool (or split among final survivors)Edge Case Handling: Sophisticated logic for ties, non-voters, and unanimous votesTechnical Implementation:Smart Contracts: Written in Cadence with comprehensive game state management, secure voting mechanisms, and automated round processingFrontend: React/Next.js application with Flow Client Library (FCL) integration for seamless wallet connectionsTesting: 9 comprehensive test scenarios covering all game paths, edge cases, and security considerationsSecurity: Implements commit-reveal pattern for voting, prevents double voting, and ensures fair eliminationGame Theory Elements: The game creates multiple layers of strategic depth:Level 1: Random voting (50% survival chance)Level 2: Vote opposite of public consensusLevel 3: Analyze player histories and tendenciesLevel 4: Reputation manipulation and bluffingLevel 5: Coalition forming and betrayalWhy Blockchain? Blockchain ensures complete transparency and fairness - all votes are cryptographically secured and revealed simultaneously, preventing any manipulation. The immutable voting history creates a permanent reputation system that adds long-term strategic considerations. Smart contracts guarantee automatic and fair prize distribution.Current Status:Fully functional smart contracts deployed on Flow emulatorWorking frontend with game creation, joining, voting, and prize claimingComplete test suite with 100% scenario coverageReady for testnet deploymentThis project demonstrates how classic game theory concepts can be enhanced through blockchain technology, creating engaging experiences that are both entertaining and intellectually challenging.
Solution
Tech Stack & Architecture:Smart Contracts (Cadence on Flow): We built the core game logic using Cadence, Flow's resource-oriented programming language. The main contract MinorityRuleGame.cdc manages the entire game lifecycle through nested resources and structs:GameManager resource: Singleton pattern for managing multiple games simultaneouslyGame resource: Encapsulates individual game state with commit-reveal voting mechanismPlayerProfile struct: Tracks comprehensive player statistics and voting historyEvent-driven architecture for real-time updates and transparencyFrontend (React/Next.js):Next.js 14 with App Router for optimal performance and SEOFlow Client Library (FCL) for wallet integration and blockchain interactionsReact Context API for global game state managementReal-time game updates through event listeners and polling mechanismsTailwind CSS for responsive UI designKey Technical Implementations:Commit-Reveal Voting System: The most challenging aspect was implementing secure voting. We store votes privately during the voting phase using Cadence's access control: access(contract) var currentVotes: {Address: Bool} // Hidden until reveal When the deadline passes, all votes are revealed simultaneously, preventing last-second manipulation.Automatic Round Processing: We implemented a sophisticated round processing system that handles multiple edge cases:Tie detection (equal YES/NO votes → all survive)Non-voter elimination (automatic removal of inactive players)Unanimous vote dismissal (rounds where everyone votes the same are void)Dynamic game ending when player count drops below 3Gas Optimization Hacks:Batch processing eliminations in single transaction to reduce gas costsEfficient event emission using structured data instead of multiple eventsOptimized player lookup using dictionary access patternsTesting Infrastructure: We built a comprehensive testing framework with 9 detailed scenarios:Created helper functions for complex game simulationsImplemented time manipulation for testing round deadlinesBuilt automated test scenarios covering every possible game pathNotable Hacky Solutions:Deadline Enforcement Without Oracles: Since Flow doesn't have built-in scheduling, we implemented a clever deadline system:Store deadline as block timestampAny transaction after deadline triggers automatic round processingFirst valid action after deadline processes the round before executingPlayer Activity Tracking: We track both hasVoted and actual votes separately to distinguish between:Players who haven't voted yetPlayers who voted but we can't reveal yetNon-voters who should be eliminatedDynamic Winner Determination: Instead of fixed elimination rounds, we implemented flexible game ending: if activePlayers.length < 3 { // End game with 0, 1, or 2 winners self.completeGame() }Partner Technologies & Benefits:Flow Blockchain:Cadence's resource model perfectly suited for game assets and prize poolsBuilt-in capability-based security for vote privacyLow transaction costs enabling micro-stakes gamesFast finality for responsive gameplayFlow Client Library (FCL):Simplified wallet integration (supports multiple Flow wallets)Built-in transaction status handlingAutomatic script decoding and error handlingDevelopment Process:Contract-First Development: Started with smart contracts to ensure game logic was solid before building UIIncremental Testing: Built test scenarios parallel to features, ensuring each mechanism worked before adding complexityEmulator-Driven Development: Used Flow emulator extensively for rapid iteration without testnet delaysEvent-Driven Architecture: Designed system around events for easier debugging and frontend integrationInteresting Technical Challenges Solved:Preventing Vote Manipulation: Implemented multiple checks:One vote per player per roundNo vote changes after submissionNo viewing others' votes until revealFair Prize Distribution: Used Flow's Vault resources for atomic prize transfers: let prizePortion <- self.prizePool.withdraw(amount: portionAmount) recipient.deposit(from: <-prizePortion)State Consistency: Maintained consistency across complex state transitions using careful ordering:Update state firstEmit events secondExternal interactions lastThe entire system demonstrates how traditional game concepts can be enhanced with blockchain's transparency and trustlessness while maintaining engaging gameplay mechanics.
Hackathon
ETHGlobal New Delhi
2025
Contributors
- agyn-ub
39 contributions