Evaluacion-Cacho Turns a Dice Game Into a Rules Engine

A WinForms student project hides a surprisingly thoughtful scoring system, including dice flips, first-roll bonuses, and brute-force move suggestions.

8 min read View on GitHub More from ar2two99

Five dice sit on a white tabletop beside a scoring sheet. One die appears caught between faces, as if the code is testing alternate outcomes before settling on a legal hand. The scene explains how the project turns a physical dice game into a search problem instead of a simple roll-and-check toy.
The project’s cleverness is not the UI. It is the search for alternate dice states that might unlock a valid score.
Key Takeaways

The interesting trick is not the UI. It is the dice-flip search.

Most student game projects stop at roll, score, repeat. This one does something more interesting. It asks whether a hand can become valid if some dice are flipped to their opposite faces, then runs the scoring logic again on each variant.

That is the heart of `Evaluacion-Cacho`. The code does not just judge the current hand. It explores a small space of alternate hands, which turns a tabletop rule into a compact search problem.

Cacho Alalay, translated into code

The game logic is rooted in Cacho Alalay, a dice game with categories, special hands, and a first-roll bonus for natural outcomes. That matters because the scorer is not generic. It needs to know when a hand is just a hand, and when it is a special result earned immediately on the first throw.

A hand becomes a family of candidate hands before the score logic decides which ones are legal and which one is best.

That structure explains why the project’s scoring code feels more like a rules engine than a simple if-else ladder. It is tracking both the category and the context of the roll, especially whether the result was achieved de mano, on the first throw.

`CalculadoraPuntajes.cs` is the real engine

The most interesting file is `CalculadoraPuntajes.cs`. It uses LINQ to recognize patterns in the dice, which is exactly what you want in a scorer. Group the values, count them, and test for combinations like poker, full house, straight, and grande.

var grupos = dados.GroupBy(d => d).ToList();
var esPoker = grupos.Any(g => g.Count() >= 4);
var esFull = grupos.Count == 2 && grupos.Any(g => g.Count() == 3) && grupos.Any(g => g.Count() == 2);
var esEscalera = dados.OrderBy(d => d).SequenceEqual(new[] { 1, 2, 3, 4, 5 }) ||
                 dados.OrderBy(d => d).SequenceEqual(new[] { 2, 3, 4, 5, 6 });

The real surprise is the vuelcos logic. Rather than hardcoding one special case, the scorer generates flipped-dice variants and re-evaluates them. That means the code is not just checking a hand. It is searching for the best legal hand inside a tiny state space.

A mechanical sorting device takes in five dice values and sends them through branching paths labeled keep, reroll, and flip. On the far side, stamped result boxes collect different scoring outcomes. The image explains how the scorer expands one hand into several candidate hands before ranking them.
The scorer branches one hand into several candidates, then filters them through the rule set until the best valid outcome remains.

The turn state is simple, but not elegant

`ControladorDados.cs` handles the physical side of the game. It keeps the current dice values, rerolls only the dice the player did not hold, and tracks how many attempts have happened in the turn. That is enough for a game loop, even if it is not the cleanest object model.

`Form1.cs` does the glue work, and it shows the project’s prototype shape. A large set of booleans tracks which scoring categories each player has already used. It works, but it ties the UI to the rules more tightly than a larger codebase would want.

Current repo shapeCleaner long-term shape
Many booleans in `Form1.cs`A `Player` object with a structured scorecard
Variant generation inside the scorerA separate rule-evaluation pipeline
UI and logic closely coupledState, rules, and presentation split apart
Turn tracking by flags and arraysExplicit turn and hand objects

The helper system is a tiny hint of AI

The suggestion logic, `MarcarMejorJugada`, is a small but useful touch. It scans the available scoring options and points the player toward the best one. That is not machine learning, but it is decision support, and for a classroom project that is a meaningful step up from a passive scorer.

This is where the repo quietly stops being just a game UI. It starts behaving like an assistant that understands the rules well enough to recommend a move.

A student project with a real architectural smell

The codebase reads like a late prototype, and that is not a criticism so much as a diagnosis. There is redundancy, there is hardcoding, and there is a lot of state pinned directly to the form. Those are signs of a project built to work, explain itself, and submit cleanly.

But the interesting part survives the rough edges. Even with the prototype shape, the project contains a genuine rules engine and a brute-force search idea that feels more ambitious than the average course submission.

What this project would look like with a cleaner model

A more scalable version would probably separate `Player`, `Turn`, `Scorecard`, and `RulesService`. That would make the code easier to test, easier to extend, and easier to read without carrying the entire UI state in one file.

Still, the current design has a useful honesty to it. You can see exactly where the logic lives, exactly where the state changes, and exactly how a hand gets evaluated. For an explainer, that transparency matters.