Rule Categories
The game contains 15 rules organized by function:- Initialization - Board setup
- Display - Board rendering
- Player Moves - Human input and validation
- AI Strategy - Cat movement logic
- Endgame - Win condition detection
Initialization Rules
ingresar-tablero-en-blanco
ingresar-tablero-en-blanco
Purpose: Creates the initial 8x8 checkerboard with alternating black and white squares.Conditions:Location: raton_y_gatos.clp:164-207
(ingresar-tablero)control fact exists
- Generates all 64 squares using nested loops
- Assigns valor 0 (white) or 1 (black) based on position parity
- Asserts
(ingresar-pos-iniciales)to trigger piece placement
posiciones-piezas-iniciales
posiciones-piezas-iniciales
Purpose: Places the mouse and four cats in their starting positions.Conditions:Location: raton_y_gatos.clp:209-259
(ingresar-pos-iniciales)control fact exists- Captures fact indices for row 1, col 4 (mouse) and row 8, cols 1,3,5,7 (cats)
- Modifies mouse square to valor 4
- Modifies cat squares to valor 5 with unique IDs (5 1, 5 2, 5 3, 5 4)
- Retracts control fact
Display Rules
actualizar-tablero
actualizar-tablero
Purpose: Renders the board to console using ASCII art in a 3-pass system.Conditions:
(imprime ?i ?j)where i*j ≤ 64- Matching pieza fact for current square’s valor
(parteImprimir ?part)indicates which line to print (1-3)(actualizar-tablero)control fact exists
- Prints appropriate part (1, 2, or 3) of the piece ASCII art
- Advances column, or wraps to next row and next part
- After completing all 64 squares × 3 parts, asserts
(pedir-movimiento-raton)
- Each square is rendered in 3 horizontal passes
- Borders and row numbers are added automatically
- Column indices printed at bottom
Player Move Rules
pedir-movimiento-raton
pedir-movimiento-raton
Purpose: Prompts player to enter mouse movement destination.Conditions:
(pedir-movimiento-raton)control fact exists- Captures current mouse position
- Prompts for row and column input
- Validates input is within board bounds (1-8)
- Validates destination is within mouse’s diagonal reach
- Asserts
(fila-columna-a-mover row col)and(comprobar-casilla-ocupada)
- Must be exactly one diagonal square away from current position
- Row and column must both change
- Sum of row difference + column difference must equal 2
comprobar-casilla-ocupada
comprobar-casilla-ocupada
Purpose: Verifies the destination square is unoccupied.Conditions:
(comprobar-casilla-ocupada)control fact exists(fila-columna-a-mover ?f ?c)from player input- Captures valor of destination square
- If valor = 1 (empty black square): Assert
(ejecutar-movimiento-jugador-raton) - If occupied: Print error, re-assert
(pedir-movimiento-raton)and(actualizar-tablero)
ejecutar-movimiento-jugador-raton
ejecutar-movimiento-jugador-raton
Purpose: Executes the validated mouse movement.Conditions:
(ejecutar-movimiento-jugador-raton)control fact exists(fila-columna-a-mover ?f1 ?c1)with destination- Captures both destination and current mouse squares
- Modifies destination square to valor 4 (mouse)
- Modifies current square to valor 1 (empty black)
- Asserts
(calcular-esquinas-raton)to trigger AI response
AI Strategy Rules
buscar-diagonales-gatos
buscar-diagonales-gatos
Purpose: Calculates the two diagonal forward squares for each cat.Conditions:
(buscar-diagonales-gatos)control fact exists- Captures each cat’s position
- For each cat, asserts
(esquina-gato ?idGato ?filaArriba ?colIzq ?colDer) - Handles edge cases (cats at column 1 or 8)
- Cats on row 1 have no forward moves
ejecutar-movimiento-completar-fila-gatos
ejecutar-movimiento-completar-fila-gatos
Purpose: Implements “block formation” strategy - cats advance together as a solid line.Salience: Default (0)Strategy:
- Identifies cats with only ONE available forward diagonal
- If multiple cats qualify, moves the one farthest from mouse
- Moves toward the available diagonal
- Mouse position
- All four cat diagonal squares
- Values of all eight diagonal destinations
- Determines which cat(s) have exactly one open diagonal
- Compares row distances to mouse to pick deepest cat
- Asserts
(fila-columna-mover-gatos row col catID)and(ejecutar-movimiento-maquina-gato) - Re-asserts
(buscar-diagonales-gatos),(semi-encerrar-raton),(gato-mas-alejado)
This is the primary AI strategy that keeps cats advancing as a coordinated group.
mover-gato-mas-alejado-raton
mover-gato-mas-alejado-raton
Purpose: Moves the cat farthest from mouse when no other strategy applies.Salience: -10 (lowest priority)Conditions:
(gato-mas-alejado)control fact exists- All cat positions
- Mouse column position
- Calculates column distance from each cat to mouse
- If any cat is >2 columns away, moves that cat diagonally toward mouse
- Direction based on which side of board mouse is on (column 4 threshold)
- If all cats close, moves cat 4 to its right diagonal
semi-encerrar-raton-que-esta-en-medio
semi-encerrar-raton-que-esta-en-medio
Purpose: Detects when mouse is surrounded on both sides and tightens the formation.Pattern Detected:Conditions:
(semi-encerrar-raton)control fact exists- Tests for specific cat formation: two cats one row above mouse flanking it, two cats same row as mouse on outer edges
- Moves the cat 2 columns away from mouse (on mouse’s row) diagonally forward toward mouse
- Direction depends on which side of board mouse is on
calcular-esquinas-raton
calcular-esquinas-raton
Purpose: Computes the 2-4 diagonal squares around the mouse.Conditions:
(calcular-esquinas-raton)control fact exists- Mouse position
- Calculates up to 4 diagonal squares (fewer if mouse is on edge/corner)
- Asserts
(esquinasRaton ?filaInf ?filaSup ?colIzq ?colDer) - Triggers
(cubrirPosibleAvanceRaton)and(encerrar-raton)checks
- Row 1: only 2 upward diagonals
- Column 1 or 8: only 2 diagonals
- Row 1 + Column 8: only 1 diagonal (corner)
encerrar-raton
encerrar-raton
Purpose: Detects endgame - when mouse has only ONE available diagonal and a cat can reach it.Salience: 10 (highest priority)Conditions:
(encerrar-raton)control fact exists(esquinasRaton)fact with all mouse diagonal values- All cat positions
- Checks each of 4 diagonals to find the one with valor 1
- Confirms exactly 3 diagonals are blocked
- Checks if any cat’s forward diagonal matches that open square
- If yes: moves that cat and asserts
(finalizar-juego)
cubrir-posible-avance-raton
cubrir-posible-avance-raton
Purpose: Detects and responds to 4 specific tactical patterns to prevent mouse escape.Patterns:
- 3D Plane Right: Cat directly in front of mouse, with formation extending right
- Three in Row One Down: Three cats in horizontal line 2 rows above mouse
- 3D Plane Left: Cat directly in front, formation extending left
- Snake Pattern: Cats in S-shaped formation
- Straggler Recovery: Catches cats that fell behind and brings them forward
- Each pattern has specific cat movement to maintain trap integrity
- Typically moves a cat to block mouse’s most promising escape route
ejecutar-movimiento-maquina-gato
ejecutar-movimiento-maquina-gato
Purpose: Executes the cat movement determined by AI strategy rules.Conditions:
(buscar-diagonales-gatos)control fact(ejecutar-movimiento-maquina-gato)control fact(fila-columna-mover-gatos ?row ?col ?catID)with movement details- Destination square
- Retrieves cat’s valor using
fact-slot-value - Modifies destination square to cat’s valor
- Modifies cat’s current square to valor 1 (empty)
- Prints move notification with cat ID and destination
- Asserts
(actualizar-tablero)to refresh display
Endgame Rules
finalizar-juego
finalizar-juego
Purpose: Displays game over message when cats win.Conditions:
(finalizar-juego)fact exists (asserted byencerrar-ratonrule)
- Prints ASCII art victory message:
- Prompts player to type
(jugar)to start new game - Calls
(halt)to stop rule execution
The game currently only detects cat victory. Mouse victory (reaching row 8) is not implemented in the rule set.
Rule Execution Order
Rules fire based on CLIPS conflict resolution strategy:-
Salience (priority): Higher salience fires first
encerrar-raton: salience 10- Most rules: salience 0 (default)
mover-gato-mas-alejado-raton: salience -10
- Recency: More recently asserted facts have priority
- Specificity: Rules with more conditions have priority
Typical Turn Sequence
pedir-movimiento-raton- Get player inputcomprobar-casilla-ocupada- Validate moveejecutar-movimiento-jugador-raton- Apply movecalcular-esquinas-raton- Analyze new mouse positionencerrar-raton- Check for immediate win (highest priority)cubrirPosibleAvanceRaton- Check tactical patternsbuscar-diagonales-gatos- Calculate cat optionsejecutar-movimiento-completar-fila-gatos- Main strategysemi-encerrar-raton- Tightening formationmover-gato-mas-alejado-raton- Fallback strategy (lowest priority)ejecutar-movimiento-maquina-gato- Apply cat moveactualizar-tablero- Redraw board