Game Control Functions
The game provides two main functions for player interaction.jugar()
Starts a new game session.Signature
Parameters
NoneReturn Value
None (void)Behavior
(clear-window)- Clears the console screen(reset)- Resets the CLIPS environment:- Removes all facts except initial facts
- Activates rules from
deffacts hechos-iniciales - Sets up blank board and piece definitions
(run)- Starts the inference engine:- Rules begin firing in priority order
- Board is initialized and rendered
- Player is prompted for first move
Usage
This function skips the instruction screen and goes directly to gameplay.
Source Location
raton_y_gatos.clp:21-26instrucciones()
Displays game instructions then starts a new game.Signature
Parameters
NoneReturn Value
None (void)Behavior
Screen 1: Setup Instructions
- Clears window
- Displays header: “JUEGO DEL RATON Y LOS GATOS”
- Shows setup instructions:
- Requires two players and a chess board
- Four cat pieces (same color)
- One mouse piece (different color)
- Initial placement: cats on row 8 black squares, mouse on row 1
- Waits for user to press any key
Screen 2: Game Rules
- Clears window and redisplays header
- Shows five game rules:
- Rule 1: Mouse moves first, can move to any adjacent black diagonal square
- Rule 2: Cats move forward only, one at a time
- Rule 3: Players alternate turns
- Rule 4: Mouse wins by reaching row 8
- Rule 5: Cats win by trapping the mouse
- Waits for user to press any key
- Calls
(jugar)to start the game
Usage
Full Source Code
Source Location
raton_y_gatos.clp:28-71Common CLIPS Built-in Functions Used
The game also uses several CLIPS built-in functions:I/O Functions
Syntax:
(printout <target> <items>...)Prints text to output stream. Target t means standard output.Special tokens:crlf- Carriage return + line feed (newline)
(printout t "Hello" crlf)Syntax:
(read)Reads a single token from standard input.Returns: Number or symbol entered by userExample: (bind ?input (read))Syntax:
(clear-window)Clears the console screen (platform-dependent).Control Functions
Syntax:
(reset)Resets the CLIPS environment:- Removes all facts except those in deffacts
- Clears agenda
- Re-asserts initial facts
Syntax:
(run [limit])Starts executing rules from the agenda until:- No more rules can fire, or
- Optional limit is reached, or
(halt)is called
Syntax:
(halt)Stops rule execution immediately. Used in finalizar-juego rule.Fact Manipulation Functions
Syntax:
(assert <fact>)Adds a new fact to working memory.Example: (assert (pedir-movimiento-raton))Syntax:
(retract <fact-index>)Removes a fact from working memory.Example: (retract ?h)Syntax:
(modify <fact-index> (<slot> <value>)...)Changes slot values in an existing fact.Example: (modify ?casilla (valor 4))Syntax:
(fact-slot-value <fact-index> <slot-name>)Retrieves the value of a specific slot from a fact.Returns: The slot’s valueExample: (bind ?val (fact-slot-value ?gato valor))Math and Logic Functions
Syntax:
(bind <variable> <expression>)Assigns a value to a variable.Example: (bind ?suma (+ ?a ?b))Syntax:
(if <condition> then <actions> else <actions>)Conditional execution.Example:Syntax:
(loop-for-count (<var> <start> <end>) do <actions>)For loop iteration.Example: (loop-for-count (?i 1 8) do (printout t ?i crlf))