Skip to content
Back to skills

Hierarchical Rule Engine

ASecurity

Two-level group-then-pattern dispatch for game AI agents where groups filter by game state and ordered patterns within a group fire the first matching action

  • 61 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
ai-agentspythongoperformance

Security analysis

A100/100

Scanned September 12, 2026

npx -y skills add wenmin-wu/ds-skills --skill hierarchical-rule-engine --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hierarchical Rule Engine?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hierarchical Rule Engine
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/wenmin-wu-hierarchical-rule-engine/badge)](https://www.skillsdirectory.com/skills/wenmin-wu-hierarchical-rule-engine)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: tabular-hierarchical-rule-engine
description: Two-level group-then-pattern dispatch for game AI agents where groups filter by game state and ordered patterns within a group fire the first matching action
---

# Hierarchical Rule Engine

## Overview

For heuristic game AI agents, a flat if-else chain becomes unmaintainable past ~20 rules. A two-level dispatch — groups that test broad game state (attacking, defending, set piece), then ordered patterns within the matching group — scales to hundreds of rules while staying readable. Each pattern is a dict with `environment_fits` (predicate) and `get_action` (callback), evaluated in priority order.

## Quick Start

```python
def make_pattern(predicate, action_fn):
    return lambda obs, x, y: {
        "environment_fits": predicate,
        "get_action": action_fn,
    }

def make_group(group_predicate, patterns_fn):
    return lambda obs, x, y: {
        "environment_fits": group_predicate,
        "get_memory_patterns": patterns_fn,
    }

groups = [attack_group, defend_group, set_piece_group, fallback_group]

def get_action(obs, x, y):
    for make_grp in groups:
        grp = make_grp(obs, x, y)
        if grp["environment_fits"](obs, x, y):
            for make_pat in grp["get_memory_patterns"](obs, x, y):
                pat = make_pat(obs, x, y)
                if pat["environment_fits"](obs, x, y):
                    return pat["get_action"](obs, x, y)
    return default_action
```

## Workflow

1. Define groups by broad game state (ball ownership, field zone, game mode)
2. Within each group, define patterns ordered by priority (most specific first)
3. Each pattern has a predicate (`environment_fits`) and action callback
4. At each timestep, find the first matching group, then first matching pattern
5. Always include a fallback group/pattern to avoid returning None

## Key Decisions

- **Group ordering**: most common states first for performance; most critical (set pieces) first for correctness
- **Pattern priority**: specific patterns (corner kick near goal) before general ones (has ball)
- **Shared state**: pass a mutable obs dict so patterns can set flags for downstream patterns
- **vs. decision trees**: rule engine is hand-crafted but transparent; use when domain expertise > data
- **Extensibility**: adding a new behavior = adding one pattern dict to the right group

## References

- [GFootball with Memory Patterns](https://www.kaggle.com/code/yegorbiryukov/gfootball-with-memory-patterns)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.