Skip to content

yusufkaraaslan/deck_deck_go

Repository files navigation

Card Master Sort

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.

Unity Version C# Version License

๐ŸŽฎ Game Overview

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.

Key Features

  • ๐Ÿค– 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

๐ŸŽฒ Game Rules

Card Groups

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

Joker (Wildcard)

  • 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

Scoring

  • Each card in a valid group: +1 point
  • Each leftover card: -2 points
  • Best possible score: 14 points (all cards grouped, 0 leftover)

๐ŸŽฏ How to Play

  1. Arrange Cards

    • Drag and drop cards to manually arrange them
    • OR click NUMERIC, COLOR, or SMART buttons for auto-sorting
  2. Calculate (Validate)

    • Click CALCULATE button to validate your manual arrangement
    • Groups are detected left-to-right with spacers added between them
  3. Compare (Compete!)

    • Click COMPARE button to compete against the AI
    • AI uses the SMART algorithm with dynamic programming
    • Winner popup shows results
  4. Next Round

    • Click NEXT ROUND to start a new round
    • Cards animate back to deck and new cards are auto-dealt

Keyboard Shortcuts

  • 1 - Numeric Sort
  • 2 - Color Sort
  • 3 - Smart Sort
  • Z - Undo
  • Y - Redo

๐Ÿ› ๏ธ Technical Stack

Core Technologies

  • 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

Architecture Patterns

  • 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

๐Ÿ“ Project Structure

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

๐Ÿง  Smart Sort Algorithm

The core technical challenge is the Smart Sort algorithm, which uses dynamic programming with bitmask optimization:

Algorithm Overview

  1. Generate All Possible Groups - Both sequences and sets (with/without joker)
  2. Evaluate Combinations - Use bitmask to represent selected groups
  3. Validate Non-Overlapping - Ensure no card is used in multiple groups
  4. Optimize Score - Maximize grouped cards, minimize leftovers

Performance

  • Target: <10ms execution time for 14-card hand
  • Approach: Bitmask DP for efficient state exploration
  • Optimization: Early pruning of invalid combinations

Scoring Formula

totalScore = groupedCards - (leftoverCards * 2)

๐ŸŽจ Design Decisions

Separation of Concerns

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

State Management

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.

Manual vs Auto Arrangement

  • 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 Flexibility

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)

๐Ÿš€ Getting Started

Prerequisites

  • Unity 6.0 or later
  • Git (for cloning)

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/card-master-sort.git
cd card-master-sort
  1. Open in Unity Hub:

    • Open Unity Hub
    • Click "Add" and select the project folder
    • Select Unity 6.0+ and open the project
  2. Open the MainMenu scene:

    • Navigate to Assets/_Project/Scenes/MainMenu.unity
    • Press Play to start

Building

To build a standalone version:

  1. Go to File > Build Settings
  2. Add scenes: MainMenu.unity and MainGame.unity
  3. Select your target platform (Windows/Mac/Linux)
  4. Click Build and choose output directory

๐Ÿงช Testing

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:

  1. Open Unity Test Runner: Window > General > Test Runner
  2. Select "EditMode" tab
  3. Click "Run All"

๐Ÿ“Š Performance Metrics

  • 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

๐ŸŽฏ Key Achievements

  • โœ… 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

๐Ÿ”ฎ Future Enhancements

  • 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

๐Ÿ“ Documentation

  • 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

๐Ÿค Contributing

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

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘ Acknowledgments

  • 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

๐Ÿ“ง Contact

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!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •