Game Logic - How Decisions Are Made
What is NewBlockBlastLogic?
NewBlockBlastLogic is the intelligent system that picks which shapes to give you. It's not random - it's smart!
Goal: Keep game challenging but not impossible.
Why do we need smart logic?
Without smart logic (pure random):
With smart logic:
Game gives: [small line] [single] [medium square]
Board: 90% full
Result: Player can clear lines and continue! 😊
How it works - Simple explanation
The 3-Step System
Step 1: Try to find COMBO shape
↓ Found?
Yes → Give it + 2 balanced shapes
No → Go to Step 2
↓
Step 2: Try to find NEAR-MISS shape
↓ Found?
Yes → Give it + 2 balanced shapes
No → Go to Step 3
↓
Step 3: Give 3 SAFE shapes
(Always fit somewhere)
What are these shape types?
| Type | Description | Example |
|---|---|---|
| COMBO | Instantly completes a line | Line that fills last 3 cells in row |
| NEAR-MISS | Almost completes line (1-2 cells missing) | Would complete if 1 more piece placed |
| SAFE | Small, always fits somewhere | Single cell, small 2×2 square |
The Strategy
Early Game (Board <50% full)
Give: Mostly medium/large shapes
Why: Player has space, can handle bigger pieces
Effect: Faster scoring, more freedom
Mid Game (Board 50-75% full)
Give: Mix of sizes
- 1 combo/near-miss opportunity
- 1 medium shape
- 1 small/safe shape
Why: Balance challenge with possibility
Late Game (Board >75% full)
Give: More small shapes, higher combo chance
Why: Player needs help clearing space
Effect: Still challenging but not impossible
Key Algorithms
1. Find Immediate Combo
For each shape in pool:
For each position on board:
If placing shape here clears any line:
→ Return this shape! ✓
If no combo found:
→ Continue to next step
2. Find Near-Miss
For each line (row/column):
Count empty cells
If 1-2 empty cells:
→ This is "almost full"
For each shape:
For each position:
If placing shape fills almost-full line:
→ Return this shape! ✓
3. Safe Fallback
Filter shapes by:
- Can be placed SOMEWHERE on board
- Sorted by size (small → large)
Give mix:
- 1 small (always fits)
- 1 medium
- 1 random
Adaptive Difficulty
System tracks player performance:
Player clearing many combos:
↓
Increase difficulty
↓
Give fewer combo opportunities
Give larger shapes
Constants (Tuning Knobs)
These control the system:
SHAPES_PER_TURN = 3 // How many shapes per turn
MAX_MISSING_CELLS = 8 // Max empty cells in "near-miss"
HIGH_FILL_THRESHOLD = 0.76 // When board is "full" (76%)
MIN_PLAYABLE_SHAPES = 3 // Min shapes that must fit
MAX_ATTEMPTS = 150 // Max tries to find good set
What they do
| Constant | Effect if increased | Effect if decreased |
|---|---|---|
SHAPES_PER_TURN |
More choices → easier | Fewer choices → harder |
MAX_MISSING_CELLS |
More "near-miss" → easier | Stricter matching → harder |
HIGH_FILL_THRESHOLD |
Earlier help → easier | Later help → harder |
MIN_PLAYABLE_SHAPES |
Must fit more → easier | Can give impossible → harder |
Pattern Recognition
Almost-Full Lines
System detects patterns:
Full row:
■ ■ ■ ■ ■ ■ ■ ■ ← Would clear
Almost full (1 missing):
■ ■ □ ■ ■ ■ ■ ■ ← Could give shape to fill
Almost full (2 missing):
■ □ ■ ■ ■ □ ■ ■ ← Could give shape to fill
Smart Shape Selection
If missing cells are:
Adjacent (■ ■ □ □ ■):
→ Give 2-cell line shape
Scattered (■ □ ■ □ ■):
→ Give L or T shape
Corners (□ ■ ■ ■ □):
→ Give corner shape
Balance System
After picking priority shape, fills remaining:
Priority shape picked: Large (5 cells)
↓
Balance:
Shape 2: Small (1-2 cells)
Shape 3: Medium (3-4 cells)
Why? Ensures at least ONE shape is easy to place!
Validation
Before giving shapes to player:
Check: Can player place at least 3 shapes?
↓ Yes
Give shapes ✓
↓ No
Try again (up to 150 attempts)
↓ Still no?
Give 3 guaranteed-safe shapes
This prevents impossible situations!
Example Scenario
Board State
0 1 2 3 4 5 6 7
0 ■ ■ □ ■ ■ ■ ■ ■ ← 1 cell missing!
1 □ □ □ ■ □ □ □ □
2 ■ ■ ■ ■ □ □ □ □
3 □ □ □ ■ □ ■ ■ □
Logic Decision Process
1. Check for combo:
→ Row 0 needs 1 cell at position (0,2)
→ Found single-cell shape! ✓
2. Pick combo shape:
Shape 1: Single cell ■
3. Balance with 2 more:
Shape 2: 3-cell line ■ ■ ■
Shape 3: 2×2 square ■ ■
■ ■
Result: Player has combo opportunity + backup options
Common Modifications
Make game easier
// Give more combo opportunities
HIGH_FILL_THRESHOLD = 0.60f; // Was 0.76
// Require more shapes to fit
MIN_PLAYABLE_SHAPES = 4; // Was 3
// Allow more missing cells
MAX_MISSING_CELLS = 12; // Was 8
Make game harder
// Give fewer combo opportunities
HIGH_FILL_THRESHOLD = 0.85f;
// Can give fewer playable shapes
MIN_PLAYABLE_SHAPES = 2;
// Stricter near-miss
MAX_MISSING_CELLS = 4;
Remove intelligence (pure random)
// In NewBlockBlastLogic.cs
public ShapeData[] PickTurnSet(ShapeData[] pool)
{
// Just pick 3 random shapes
return pool.OrderBy(x => Random.value).Take(3).ToArray();
}
Performance
- Very fast - runs in <1ms even on slow devices
- Cached checks - board state analyzed once
- Early exits - stops when good solution found
- Fallback safety - always has backup plan
What's Next?
- 🧠 AI & Difficulty - deep dive into NewBrain
- 📊 Scoring - how points are calculated
- ⚙️ Customization - tune the logic
For Advanced Users
Modifying these algorithms can dramatically change game feel. Test extensively!