A Unity 6 card sorting puzzle game where you compete against a smart AI algorithm. Arrange 14 cards into valid groups using sequences and sets to maximize your score.
Card Master Sort is a competitive card arrangement puzzle where you face off against an AI opponent using a sophisticated smart sorting algorithm. Your goal is to arrange 14 randomly dealt cards into valid groups while minimizing leftover cards.
- ๐ค AI Competition: Play against a smart AI that uses dynamic programming to find optimal arrangements
- ๐ 104-Card Deck System: Two complete decks with 4 colors and 13 numbers each
- ๐ฏ Three Sorting Algorithms: Numeric Sort, Color Sort, and Smart Sort with joker support
- ๐จ Modern UI: Clean split-screen interface with animations and drag-and-drop
- โก Real-time Validation: Manual arrangement validation with group detection
- ๐ Command Pattern: Full undo/redo support for all actions
- ๐ Scoring System: Dynamic scoring based on grouped cards vs leftovers
You can create two types of valid groups:
1. Sequences (Runs)
- Same color, sequential numbers
- Minimum 3 cards, no maximum
- Example: Red-7, Red-8, Red-9, Red-10
2. Sets
- Different colors, same number
- Minimum 3 cards, maximum 4 cards
- Example: Blue-5, Black-5, Yellow-5, Red-5
- One random card per round becomes a joker
- Can substitute any card in sequences or sets
- Only one joker per group
- Can be placed at start, middle, or end of groups
- Each card in a valid group: +1 point
- Each leftover card: -2 points
- Best possible score: 14 points (all cards grouped, 0 leftover)
- 
Arrange Cards - Drag and drop cards to manually arrange them
- OR click NUMERIC,COLOR, orSMARTbuttons for auto-sorting
 
- 
Calculate (Validate) - Click CALCULATEbutton to validate your manual arrangement
- Groups are detected left-to-right with spacers added between them
 
- Click 
- 
Compare (Compete!) - Click COMPAREbutton to compete against the AI
- AI uses the SMART algorithm with dynamic programming
- Winner popup shows results
 
- Click 
- 
Next Round - Click NEXT ROUNDto start a new round
- Cards animate back to deck and new cards are auto-dealt
 
- Click 
- 1- Numeric Sort
- 2- Color Sort
- 3- Smart Sort
- Z- Undo
- Y- Redo
- Unity 6.0+ - Game engine
- C# 9.0 - Primary programming language
- Universal Render Pipeline (URP) - Rendering pipeline
- Unity Input System - Modern input handling
- TextMeshPro - UI text rendering
- Command Pattern - All user actions (Deal, Sort, Undo/Redo)
- Strategy Pattern - Three sorting algorithm implementations
- Unidirectional Data Flow (UDF) - Redux-like state management
- Object Pooling - Card GameObject reuse for performance
- Event-Driven Architecture - Decoupled component communication
Assets/
โโโ _Project/
โ   โโโ Scenes/
โ   โ   โโโ MainMenu.unity        # Main menu with instructions
โ   โ   โโโ MainGame.unity        # Game scene with split-screen layout
โ   โโโ Scripts/
โ   โ   โโโ Actions/              # State actions (InitializeDeck, DealCards, SortCards)
โ   โ   โโโ Commands/             # ICommand implementations (DealCardsCommand, SortCardsCommand)
โ   โ   โโโ Components/           # MonoBehaviour UI components (CardView, WinnerPopup)
โ   โ   โโโ Core/                 # Pure C# sorting logic (no Unity dependencies)
โ   โ   โ   โโโ NumericSortStrategy.cs
โ   โ   โ   โโโ ColorSortStrategy.cs
โ   โ   โ   โโโ SmartSortStrategy.cs
โ   โ   โ   โโโ ManualArrangementValidator.cs
โ   โ   โ   โโโ DPCardSolver.cs
โ   โ   โโโ Managers/             # GameManager, CommandManager, GridManager, CardPool
โ   โ   โโโ Models/               # Data structures (Card, CardGroup, SortResult)
โ   โ   โโโ Reducers/             # State reducers for UDF pattern
โ   โ   โโโ State/                # Global state schema (GameState, CardSystemState)
โ   โ   โโโ Utils/                # Helper utilities
โ   โ   โโโ Editor/               # Unity Editor tools and setup scripts
โ   โโโ Prefabs/
โ   โ   โโโ P_Card.prefab         # Card prefab with CardView component
โ   โ   โโโ P_Spacer.prefab       # Group separator prefab
โ   โโโ Settings/                 # URP and Input System settings
โโโ Docs/                         # Design documents (GDD, TDD, Project Brief)
โโโ Tests/                        # Unit tests for sorting algorithms
The core technical challenge is the Smart Sort algorithm, which uses dynamic programming with bitmask optimization:
- Generate All Possible Groups - Both sequences and sets (with/without joker)
- Evaluate Combinations - Use bitmask to represent selected groups
- Validate Non-Overlapping - Ensure no card is used in multiple groups
- Optimize Score - Maximize grouped cards, minimize leftovers
- Target: <10ms execution time for 14-card hand
- Approach: Bitmask DP for efficient state exploration
- Optimization: Early pruning of invalid combinations
totalScore = groupedCards - (leftoverCards * 2)Critical principle: Sorting logic in Core/ is pure C# with no Unity dependencies. This allows:
- Unit testing without Unity Test Framework overhead
- Algorithm validation independent of UI
- Potential reuse in other contexts
Global state follows Redux-like UDF pattern:
User Input โ Command โ Action โ Reducer โ State Update โ View Update
All state changes flow through GameStore with event notifications.
- Auto-sort buttons use full optimization algorithms
- Manual dragging preserves player intent
- Calculate button validates manual arrangements in exact visual order
- Compare button re-validates current arrangement before competing
Joker rules designed for maximum flexibility:
- Can start groups (second card establishes pattern)
- Works in both sequences and sets
- Only one per group (standard Rummikub rules)
- Unity 6.0 or later
- Git (for cloning)
- Clone the repository:
git clone https://github.com/yourusername/card-master-sort.git
cd card-master-sort- 
Open in Unity Hub: - Open Unity Hub
- Click "Add" and select the project folder
- Select Unity 6.0+ and open the project
 
- 
Open the MainMenu scene: - Navigate to Assets/_Project/Scenes/MainMenu.unity
- Press Play to start
 
- Navigate to 
To build a standalone version:
- Go to File > Build Settings
- Add scenes: MainMenu.unityandMainGame.unity
- Select your target platform (Windows/Mac/Linux)
- Click Buildand choose output directory
Unit tests are located in Assets/Tests/EditMode/:
- SortingEngineTests.cs- Algorithm validation tests
- Tests for numeric sequences, color sets, joker handling
- Edge case validation
To run tests:
- Open Unity Test Runner: Window > General > Test Runner
- Select "EditMode" tab
- Click "Run All"
- Target Frame Rate: 60 FPS (16.6ms frame time)
- Smart Sort Execution: <10ms per sort
- Object Pooling: Card instantiation eliminated during gameplay
- Animation Performance: Smooth 0.5s transitions with easing curves
- โ Clean architecture with separation of concerns
- โ Comprehensive state management with UDF pattern
- โ Smart AI opponent with optimal play
- โ Full undo/redo support via Command pattern
- โ Joker wildcard support in all detection algorithms
- โ Manual arrangement validation with group detection
- โ Real-time re-validation on Compare button
- โ Smooth animations with object pooling
- โ Auto-deal on scene start for streamlined UX
- Sound effects and music
- Particle effects for card animations
- Multiple difficulty levels for AI
- Tournament mode with multiple rounds
- Online multiplayer
- Card skin customization
- Achievement system
- Replay system
- Mobile platform support
- Game Design Document - Assets/Docs/GDD.md
- Technical Design Document - Assets/Docs/TDD.md
- Project Brief - Assets/Docs/ProjectBrief.md
- Workflow Guide - WORKFLOW.md
- Coding Standards - CLAUDE.md
This is a solo project, but suggestions and feedback are welcome! Feel free to:
- Open issues for bugs or feature requests
- Submit pull requests with improvements
- Share your high scores and strategies
This project is licensed under the MIT License - see the LICENSE file for details.
- Unity Technologies for the excellent game engine
- TextMeshPro for beautiful text rendering
- Claude AI for development assistance and architecture guidance
- Rummikub for game rule inspiration
For questions or feedback, please open an issue on GitHub.
Built with โค๏ธ using Unity 6 and C#
Compete against the AI and see if you can beat the smart sorting algorithm!