Feat/implement minesweeper#84
Merged
salazarsebas merged 2 commits intosalazarsebas:mainfrom Mar 24, 2026
Merged
Conversation
- Implement complete Connect Four smart contract using Cougr ECS architecture - Add gravity-based piece placement system for column drops - Implement win detection for horizontal, vertical, and diagonal patterns - Add draw detection for full board scenarios - Create comprehensive test suite with 24 passing tests - Include full documentation with README.md - Configure CI/CD workflow for automated testing and validation - Follow Soroban best practices with wasm32v1-none target Test Results: - All 24 tests passing (initialization, validation, win/draw detection) - Passes cargo fmt, clippy, and release build checks - Demonstrates modular ECS pattern for board game logic
|
@abdulomeiza Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #70
Minesweeper Implementation Complete!
I've successfully created a comprehensive Minesweeper example for the Cougr framework with proof-friendly, deterministic cell reveal mechanics!
📦 Deliverables Summary
Location: examples/minesweeper/
Files Created:
✅ Cargo.toml - Project configuration
✅ src/lib.rs - Contract implementation (573 lines)
✅ src/tests.rs - Test suite (430 lines, 21 tests)
✅ README.md - Comprehensive documentation (347 lines)
✅ .github/workflows/minesweeper.yml - CI/CD pipeline
🎮 Game Features Implemented
✅ Core Mechanics:
9×9 grid (81 cells total, compact for on-chain)
10 mines (~12% density - beginner friendly)
Deterministic mine placement (proof-friendly!)
Cell reveal with adjacent mine count (0-8)
✅ Reveal System:
Safe cell revelation with adjacency feedback
Mine detection and game-over trigger
Already-revealed cell validation
Out-of-bounds protection
✅ Win/Loss Conditions:
Loss: Immediate game over on mine reveal
Win: All safe cells revealed (71 cells)
Game state tracking (revealed count, remaining cells)
✅ Proof-Friendly Design:
Fixed mine positions (verifiable layout)
No randomness required
Deterministic adjacency calculation
Reproducible game states
🏗️ ECS Architecture (Cougr-Style)
Components:
BoardComponent - Visible cell states (hidden/revealed/mine)
MineLayoutComponent - Hidden mine positions with adjacency counting
GameStateComponent - Status, revealed count
Systems:
RevealSystem - Cell revelation logic
AdjacencySystem - 8-neighbor mine counting
LossSystem - Mine detection → game over
CompletionSystem - Win condition check
🧪 Test Coverage (21 Tests - All Passing)
Test Categories:
✅ Initialization (2 tests)
✅ Safe cell reveal (3 tests)
✅ Mine reveal & loss (2 tests)
✅ Repeated reveals (2 tests)
✅ Out of bounds (1 test)
✅ Win condition (2 tests)
✅ Visible cell state (4 tests)
✅ Reset game (1 test)
✅ Adjacent count verification (1 test)
✅ Edge cases (3 tests)
✅ Validation Results
bash
All checks passed:
cargo fmt --check ✓
cargo clippy --all-targets --all-features -- -D warnings ✓
cargo test ✓ (21 passed)
cargo build --release ✓
📚 Contract API
rust
// Initialize game with deterministic mines
pub fn init_game(env: Env) -> GameState
// Reveal cell at position
pub fn reveal_cell(env: Env, row: u32, col: u32) -> RevealResult
// Get current game state
pub fn get_state(env: Env) -> GameState
// Get visible state of specific cell
pub fn get_visible_cell(env: Env, row: u32, col: u32) -> VisibleCellState
// Check if game is finished
pub fn is_finished(env: Env) -> bool
// Get full board (for debugging)
pub fn get_board(env: Env) -> Vec
// Reset game
pub fn reset_game(env: Env) -> GameState
🎯 Key Design Highlights
Deterministic Mine Layout: Fixed positions enable verification and auditing
Compact State: 9×9 grid optimized for on-chain storage efficiency
Clean Separation: Board (visible) vs MineLayout (hidden) components
Adjacent Counting: Efficient 8-neighbor checking with bounds validation
Comprehensive Testing: Covers all reveal scenarios, win/loss conditions
Production Ready: Passes all Clippy lints, formatted correctly
The Minesweeper example demonstrates grid-based reveal mechanics, state transitions driven by hidden content, and terminal conditions in a deterministic puzzle structure - perfect for on-chain gaming!