|
22 | 22 | import java.nio.charset.StandardCharsets; |
23 | 23 |
|
24 | 24 | /** |
25 | | - * PrologService class provides functionality to generate Prolog facts |
26 | | - * and rules from Java objects representing items, recipes, and inventory, and |
27 | | - * to query which items are craftable given the current inventory using Prolog |
28 | | - * logic. |
29 | | - * |
| 25 | + * PrologService class provides functionality to generate Prolog facts and rules |
| 26 | + * from Java objects representing items, recipes, and inventory, and to query |
| 27 | + * which items are craftable given the current inventory using Prolog logic. |
| 28 | + * |
30 | 29 | * <p> |
31 | 30 | * This service is responsible for: |
32 | | - * |
| 31 | + * |
33 | 32 | * <ul> |
34 | 33 | * <li>Serializing items and inventory into Prolog facts.</li> |
35 | 34 | * <li>Writing utility rules for crafting logic in Prolog.</li> |
@@ -84,6 +83,14 @@ public HashMap<Item, Integer> craftableItems() throws IOException { |
84 | 83 | this.toFile(tempFileWriter); |
85 | 84 | tempFileWriter.close(); |
86 | 85 |
|
| 86 | + // Clear previous Prolog definitions to avoid redefinition warnings |
| 87 | + new Query(String.format("abolish(%s/1)", this.baseItemFactName)).hasSolution(); |
| 88 | + new Query(String.format("abolish(%s/4)", this.ingredientFactName)).hasSolution(); |
| 89 | + new Query(String.format("abolish(%s/2)", this.itemInInventoryFactName)).hasSolution(); |
| 90 | + new Query("abolish(craftable_items/2)").hasSolution(); |
| 91 | + new Query("abolish(maximum_craftable_items/2)").hasSolution(); |
| 92 | + new Query("abolish(maximum_craftable_items/3)").hasSolution(); |
| 93 | + |
87 | 94 | // Build query |
88 | 95 | String consultQuery = String.format("consult(\"%s\")", tempFilePath); |
89 | 96 | Query consult = new Query(consultQuery); |
|
0 commit comments