Minority Rule Game - A Blockchain Implementation of the Psychological Strategy Game from Liar Game
Minority 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 gameplay
- Strategic Voting System: Private vote submission with simultaneous reveal after deadline to prevent manipulation
- Player Reputation System: Complete voting history and statistics tracked on-chain, allowing players to analyze opponents'
patterns
- Dynamic 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 votes
Technical Implementation:
- Smart Contracts: Written in Cadence with comprehensive game state management, secure voting mechanisms, and automated round
processing
- Frontend: React/Next.js application with Flow Client Library (FCL) integration for seamless wallet connections
- Testing: 9 comprehensive test scenarios covering all game paths, edge cases, and security considerations
- Security: Implements commit-reveal pattern for voting, prevents double voting, and ensures fair elimination
Game Theory Elements:
The game creates multiple layers of strategic depth:
- Level 1: Random voting (50% survival chance)
- Level 2: Vote opposite of public consensus
- Level 3: Analyze player histories and tendencies
- Level 4: Reputation manipulation and bluffing
- Level 5: Coalition forming and betrayal
Why 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 emulator
- Working frontend with game creation, joining, voting, and prize claiming
- Complete test suite with 100% scenario coverage
- Ready for testnet deployment
This project demonstrates how classic game theory concepts can be enhanced through blockchain technology, creating engaging
experiences that are both entertaining and intellectually challenging.
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 simultaneously
- Game resource: Encapsulates individual game state with commit-reveal voting mechanism
- PlayerProfile struct: Tracks comprehensive player statistics and voting history
- Event-driven architecture for real-time updates and transparency
Frontend (React/Next.js):
- Next.js 14 with App Router for optimal performance and SEO
- Flow Client Library (FCL) for wallet integration and blockchain interactions
- React Context API for global game state management
- Real-time game updates through event listeners and polling mechanisms
- Tailwind CSS for responsive UI design
Key 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 3
- Gas Optimization Hacks:
- Batch processing eliminations in single transaction to reduce gas costs
- Efficient event emission using structured data instead of multiple events
- Optimized player lookup using dictionary access patterns
- Testing Infrastructure:
We built a comprehensive testing framework with 9 detailed scenarios:
- Created helper functions for complex game simulations
- Implemented time manipulation for testing round deadlines
- Built automated test scenarios covering every possible game path
Notable Hacky Solutions:
- Deadline Enforcement Without Oracles:
Since Flow doesn't have built-in scheduling, we implemented a clever deadline system:
- Store deadline as block timestamp
- Any transaction after deadline triggers automatic round processing
- First valid action after deadline processes the round before executing
- Player Activity Tracking:
We track both hasVoted and actual votes separately to distinguish between:
- Players who haven't voted yet
- Players who voted but we can't reveal yet
- Non-voters who should be eliminated
- Dynamic 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 pools
- Built-in capability-based security for vote privacy
- Low transaction costs enabling micro-stakes games
- Fast finality for responsive gameplay
Flow Client Library (FCL):
- Simplified wallet integration (supports multiple Flow wallets)
- Built-in transaction status handling
- Automatic script decoding and error handling
Development Process:
-
Contract-First Development:
Started with smart contracts to ensure game logic was solid before building UI
-
Incremental Testing:
Built test scenarios parallel to features, ensuring each mechanism worked before adding complexity
-
Emulator-Driven Development:
Used Flow emulator extensively for rapid iteration without testnet delays
-
Event-Driven Architecture:
Designed system around events for easier debugging and frontend integration
Interesting Technical Challenges Solved:
- Preventing Vote Manipulation:
Implemented multiple checks:
- One vote per player per round
- No vote changes after submission
- No viewing others' votes until reveal
-
Fair 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 first
- Emit events second
- External interactions last
The entire system demonstrates how traditional game concepts can be enhanced with blockchain's transparency and trustlessness
while maintaining engaging gameplay mechanics.