Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. # KTdCW WS 201819 Situation Calculus Assignment 2
  2. # Group Number XX
  3. # Lastname, Firstname, Matriculum Number
  4. # Lastname, Firstname, Matriculum Number
  5. # Lastname, Firstname, Matriculum Number
  6. # Lastname, Firstname, Matriculum Number
  7.  
  8. # DON'T change this include or the signature of S0 or main
  9. include "hooks.yagi"
  10.  
  11.  
  12. fact recipe_workbench[Item, Item, int[0:31]] {
  13. #Result #ingredient #number of ingredients
  14. [Item.WOOD, Item.LOG, 1],
  15. [Item.WOOD, Item.WOOD, 0],
  16. [Item.WOOD, Item.STICK, 0],
  17. [Item.WOOD, Item.COAL, 0],
  18. [Item.WOOD, Item.IRON_ORE, 0],
  19. [Item.WOOD, Item.IRON_INGOT, 0],
  20. [Item.WOOD, Item.IRON_SWORD, 0],
  21. [Item.WOOD, Item.TORCH, 0],
  22.  
  23. [Item.STICK, Item.LOG, 0],
  24. [Item.STICK, Item.WOOD, 2],
  25. [Item.STICK, Item.STICK, 0],
  26. [Item.STICK, Item.COAL, 0],
  27. [Item.STICK, Item.IRON_ORE, 0],
  28. [Item.STICK, Item.IRON_INGOT, 0],
  29. [Item.STICK, Item.IRON_SWORD, 0],
  30. [Item.STICK, Item.TORCH, 0],
  31.  
  32. [Item.IRON_SWORD, Item.LOG, 0],
  33. [Item.IRON_SWORD, Item.WOOD, 0],
  34. [Item.IRON_SWORD, Item.STICK, 1],
  35. [Item.IRON_SWORD, Item.COAL, 0],
  36. [Item.IRON_SWORD, Item.IRON_ORE, 0],
  37. [Item.IRON_SWORD, Item.IRON_INGOT, 2],
  38. [Item.IRON_SWORD, Item.IRON_SWORD, 0],
  39. [Item.IRON_SWORD, Item.TORCH, 0],
  40.  
  41. [Item.TORCH, Item.LOG, 0],
  42. [Item.TORCH, Item.WOOD, 0],
  43. [Item.TORCH, Item.STICK, 1],
  44. [Item.TORCH, Item.COAL, 1],
  45. [Item.TORCH, Item.IRON_ORE, 0],
  46. [Item.TORCH, Item.IRON_INGOT, 0],
  47. [Item.TORCH, Item.IRON_SWORD, 0],
  48. [Item.TORCH, Item.TORCH, 0],
  49. }
  50.  
  51. fact recipe_furnace [Item, Item, int[0:31]] {
  52. [Item.IRON_INGOT, Item.LOG, 0],
  53. [Item.IRON_INGOT, Item.WOOD, 1],
  54. [Item.IRON_INGOT, Item.STICK, 0],
  55. [Item.IRON_INGOT, Item.COAL, 0],
  56. [Item.IRON_INGOT, Item.IRON_ORE, 1],
  57. [Item.IRON_INGOT, Item.IRON_INGOT, 0],
  58. [Item.IRON_INGOT, Item.IRON_SWORD, 0],
  59. [Item.IRON_INGOT, Item.TORCH, 0],
  60.  
  61. [Item.COAL, Item.LOG, 1],
  62. [Item.COAL, Item.WOOD, 1],
  63. [Item.COAL, Item.STICK, 0],
  64. [Item.COAL, Item.COAL, 0],
  65. [Item.COAL, Item.IRON_ORE, 0],
  66. [Item.COAL, Item.IRON_INGOT, 0],
  67. [Item.COAL, Item.IRON_SWORD, 0],
  68. [Item.COAL, Item.TORCH, 0],
  69. }
  70.  
  71.  
  72. fact destination[Block, Block] {
  73. [Block.WORKBENCH, Block.FURNACE],
  74. [Block.WORKBENCH, Block.CHEST],
  75. [Block.CHEST, Block.FURNACE],
  76. [Block.CHEST, Block.WORKBENCH],
  77. [Block.FURNACE, Block.CHEST],
  78. [Block.FURNACE, Block.WORKBENCH],
  79. }
  80.  
  81.  
  82. #fluent isMoving[Block]
  83. #fluent isEmpty[Block]
  84. #TODO fluent isValid[Item]
  85. #TODO fluent recipeContainsItems
  86. #fluent chestItems[Item, int[0:31]]
  87. fluent amountOfChestItems[Item,int[0:31]]
  88.  
  89. fluent steveAt[Block]
  90. fluent isHolding[Item]
  91. fluent requests[Item]
  92. fluent contains[Item, Block, int[0:31]]
  93.  
  94.  
  95.  
  96. action moveSteve(Block $to){
  97. poss (exists [$from] in steveAt such destination[$from, $to] || destination[$to, $from])
  98. do {
  99. steveAt = [$to];
  100. }
  101. signal sigMove($to)
  102. }
  103.  
  104. action put() {
  105. poss {
  106. pick [$item] in isHolding;
  107. pick [$location] in steveAt;
  108. pick [$itemInLocation, $location, $numberOfItems] in contains;
  109. pick [$item, $location, $numberOfItems] in contains;
  110. $numberOfItems>0;
  111. }
  112. do {
  113. isHolding -= [$item];
  114. #contains += [$item, $location, int[0:31] ($numberOfItems +1)];
  115. }
  116. signal sigPut()
  117. }
  118.  
  119. action take(Item $item) {
  120. poss {
  121. pick [$itemContained,$loc,$number] in contains;
  122. $number > 0;
  123. pick [$location] in steveAt;
  124. exists [$location] in steveAt such contains [$item, $location, $number];
  125. !(exists [$item] in isHolding);
  126. }
  127. do {
  128. $temp = $number;
  129. contains -= [$item, _ , int[0:31] ($temp-1)];
  130. isHolding += [$item];
  131. }
  132. signal sigTake($item)
  133. }
  134.  
  135. action craft() {
  136. poss {
  137. pick [$rkvst] in requests;
  138. pick [$ajtem, $loc, $nmbr] in contains;
  139. exists [$location] in steveAt such $location == Block.WORKBENCH;
  140.  
  141. exists [$request] in requests such for [$item, Block.WORKBENCH, $number] in contains such {
  142. exists [$item, Block.WORKBENCH, $number ] in contains such $number > 0;
  143. recipe_workbench[$request, $item,int[0:31] $number];
  144. };
  145. }
  146. do{
  147. if($rkvst == Item.WOOD)
  148. {
  149.  
  150. }
  151. #contains = [$rkvst, $ajtem, $nmbr];
  152. #moveSteve(Block.CHEST);
  153. }
  154. }
  155.  
  156.  
  157. situation S0 {
  158. amountOfChestItems = {};
  159. steveAt = {[Block.WORKBENCH]};
  160. isHolding = {};
  161. contains = {
  162. [Item.LOG, Block.CHEST, 1],
  163. [Item.IRON_ORE , Block.CHEST, 2],
  164. };
  165. }
  166.  
  167.  
  168. action senseRequests() {
  169. do {
  170. #pick [$count] in amountOfItemsInChest;
  171. $valid = true;
  172. while($valid) {
  173. [$valid, $request] = sense senseDetectRequest();
  174. if($valid) {
  175. requests += [$request];
  176. }
  177. }
  178. }
  179. }
  180.  
  181. action senseChestItems() {
  182.  
  183. do {
  184. $valid = true;
  185. while($valid) {
  186. [$valid, $item] = sense senseDetectChestItem();
  187.  
  188. if($valid) {
  189.  
  190. if(contains[$item, Block.CHEST, _])
  191. {
  192. pick [$item, Block.CHEST, $number] in contains;
  193. contains -= [$item, Block.CHEST, _];
  194. $temp = $number + 1;
  195. contains += [$item, Block.CHEST, int[0:31]($temp)];
  196. amountOfChestItems += [$item , int[0:31] ($temp)];
  197. }
  198. else
  199. {
  200. contains += [$item, Block.CHEST, 1];
  201. }
  202.  
  203. }
  204.  
  205. }
  206. }
  207. }
  208.  
  209. proc moveSteveToWorkBench()
  210. {
  211. pick[$item , $location, $nmbr] in contains;
  212. while (amountOfChestItems[_, _]) {
  213. println("aaaa");
  214. moveSteve(Block.CHEST);
  215. take($item);
  216. moveSteve(Block.WORKBENCH);
  217. put();
  218. pick[$item , $location, $nmbr] in contains;
  219. }
  220. }
  221.  
  222.  
  223. # TODO Add procedures for the business logic
  224. proc main() {
  225.  
  226. senseRequests();
  227. senseChestItems();
  228.  
  229. moveSteveToWorkBench();
  230.  
  231. println("If you can read this, you've come pretty far.");
  232. println("If you read this in the console, you've come even farther. Congrats, you're almost done!");
  233. # TODO Read all requests and available items
  234. # TODO Make an unordered TODO list of abstract steps to take
  235. # TODO Find sequence of concrete steps to achieve the abstract steps
  236. # TODO Transfer all requested items into the chest
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement