This Prolog program aims to solve the color cycle puzzle. Given a board consisting of cells with colors (Red, Yellow, or Blue), the program searches for cycles of at least 4 cells with the same color that are adjacent to each other.
Prolog interpreter (e.g., SWI-Prolog)
- Clone the repository to your local machine:
git clone https://github.com/AbdelrhmanReda17/color-cycle-solver.git
- Navigate to the project directory:
cd prolog-color-cycles-detection
- Run the Prolog program:
swipl color-detection.pl
- The program will output either a color cycle found or a message indicating that no cycles exist.
-
For example, as shown in the picture, cells 2,1 -> 2,2 -> 3,2 -> 3,1 form a blue cycle
NOTE : Another cycle could be cells 2,0 -> 2,1 -> 3,1 -> 3,0 -
Example Input:
?- detect_cycles([[yellow, yellow , yellow ,red], [blue, yellow, blue , yellow], [blue, blue , blue, yellow] ,[blue, blue , blue, yellow] ]).
-
Example Output:
blue cycle found: [[2,0],[3,0],[3,1],[3,2],[2,2],[2,1]]
blue cycle found: [[2,0],[3,0],[3,1],[2,1]]
blue cycle found: [[2,0],[2,1],[3,1],[3,0]]
blue cycle found: [[2,0],[2,1],[2,2],[3,2],[3,1],[3,0]]
blue cycle found: [[2,1],[3,1],[3,2],[2,2]]
blue cycle found: [[2,1],[3,1],[3,0],[2,0]]
blue cycle found: [[2,1],[2,2],[3,2],[3,1]]