Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # KTdCW WS 201819 Situation Calculus Assignment 2
- # Group Number XX
- # Lastname, Firstname, Matriculum Number
- # Lastname, Firstname, Matriculum Number
- # Lastname, Firstname, Matriculum Number
- # Lastname, Firstname, Matriculum Number
- # DON'T change this include or the signature of S0 or main
- include "hooks.yagi"
- fact recipe_workbench[Item, Item, int[0:31]] {
- #Result #ingredient #number of ingredients
- [Item.WOOD, Item.LOG, 1],
- [Item.WOOD, Item.WOOD, 0],
- [Item.WOOD, Item.STICK, 0],
- [Item.WOOD, Item.COAL, 0],
- [Item.WOOD, Item.IRON_ORE, 0],
- [Item.WOOD, Item.IRON_INGOT, 0],
- [Item.WOOD, Item.IRON_SWORD, 0],
- [Item.WOOD, Item.TORCH, 0],
- [Item.STICK, Item.LOG, 0],
- [Item.STICK, Item.WOOD, 2],
- [Item.STICK, Item.STICK, 0],
- [Item.STICK, Item.COAL, 0],
- [Item.STICK, Item.IRON_ORE, 0],
- [Item.STICK, Item.IRON_INGOT, 0],
- [Item.STICK, Item.IRON_SWORD, 0],
- [Item.STICK, Item.TORCH, 0],
- [Item.IRON_SWORD, Item.LOG, 0],
- [Item.IRON_SWORD, Item.WOOD, 0],
- [Item.IRON_SWORD, Item.STICK, 1],
- [Item.IRON_SWORD, Item.COAL, 0],
- [Item.IRON_SWORD, Item.IRON_ORE, 0],
- [Item.IRON_SWORD, Item.IRON_INGOT, 2],
- [Item.IRON_SWORD, Item.IRON_SWORD, 0],
- [Item.IRON_SWORD, Item.TORCH, 0],
- [Item.TORCH, Item.LOG, 0],
- [Item.TORCH, Item.WOOD, 0],
- [Item.TORCH, Item.STICK, 1],
- [Item.TORCH, Item.COAL, 1],
- [Item.TORCH, Item.IRON_ORE, 0],
- [Item.TORCH, Item.IRON_INGOT, 0],
- [Item.TORCH, Item.IRON_SWORD, 0],
- [Item.TORCH, Item.TORCH, 0],
- }
- fact recipe_furnace [Item, Item, int[0:31]] {
- [Item.IRON_INGOT, Item.LOG, 0],
- [Item.IRON_INGOT, Item.WOOD, 1],
- [Item.IRON_INGOT, Item.STICK, 0],
- [Item.IRON_INGOT, Item.COAL, 0],
- [Item.IRON_INGOT, Item.IRON_ORE, 1],
- [Item.IRON_INGOT, Item.IRON_INGOT, 0],
- [Item.IRON_INGOT, Item.IRON_SWORD, 0],
- [Item.IRON_INGOT, Item.TORCH, 0],
- [Item.COAL, Item.LOG, 1],
- [Item.COAL, Item.WOOD, 1],
- [Item.COAL, Item.STICK, 0],
- [Item.COAL, Item.COAL, 0],
- [Item.COAL, Item.IRON_ORE, 0],
- [Item.COAL, Item.IRON_INGOT, 0],
- [Item.COAL, Item.IRON_SWORD, 0],
- [Item.COAL, Item.TORCH, 0],
- }
- fact destination[Block, Block] {
- [Block.WORKBENCH, Block.FURNACE],
- [Block.WORKBENCH, Block.CHEST],
- [Block.CHEST, Block.FURNACE],
- [Block.CHEST, Block.WORKBENCH],
- [Block.FURNACE, Block.CHEST],
- [Block.FURNACE, Block.WORKBENCH],
- }
- #fluent isMoving[Block]
- #fluent isEmpty[Block]
- #TODO fluent isValid[Item]
- #TODO fluent recipeContainsItems
- #fluent chestItems[Item, int[0:31]]
- fluent amountOfChestItems[Item,int[0:31]]
- fluent steveAt[Block]
- fluent isHolding[Item]
- fluent requests[Item]
- fluent contains[Item, Block, int[0:31]]
- action moveSteve(Block $to){
- poss (exists [$from] in steveAt such destination[$from, $to] || destination[$to, $from])
- do {
- steveAt = [$to];
- }
- signal sigMove($to)
- }
- action put() {
- poss {
- pick [$item] in isHolding;
- pick [$location] in steveAt;
- pick [$itemInLocation, $location, $numberOfItems] in contains;
- pick [$item, $location, $numberOfItems] in contains;
- $numberOfItems>0;
- }
- do {
- isHolding -= [$item];
- #contains += [$item, $location, int[0:31] ($numberOfItems +1)];
- }
- signal sigPut()
- }
- action take(Item $item) {
- poss {
- pick [$itemContained,$loc,$number] in contains;
- $number > 0;
- pick [$location] in steveAt;
- exists [$location] in steveAt such contains [$item, $location, $number];
- !(exists [$item] in isHolding);
- }
- do {
- $temp = $number;
- contains -= [$item, _ , int[0:31] ($temp-1)];
- isHolding += [$item];
- }
- signal sigTake($item)
- }
- action craft() {
- poss {
- pick [$rkvst] in requests;
- pick [$ajtem, $loc, $nmbr] in contains;
- exists [$location] in steveAt such $location == Block.WORKBENCH;
- exists [$request] in requests such for [$item, Block.WORKBENCH, $number] in contains such {
- exists [$item, Block.WORKBENCH, $number ] in contains such $number > 0;
- recipe_workbench[$request, $item,int[0:31] $number];
- };
- }
- do{
- if($rkvst == Item.WOOD)
- {
- }
- #contains = [$rkvst, $ajtem, $nmbr];
- #moveSteve(Block.CHEST);
- }
- }
- situation S0 {
- amountOfChestItems = {};
- steveAt = {[Block.WORKBENCH]};
- isHolding = {};
- contains = {
- [Item.LOG, Block.CHEST, 1],
- [Item.IRON_ORE , Block.CHEST, 2],
- };
- }
- action senseRequests() {
- do {
- #pick [$count] in amountOfItemsInChest;
- $valid = true;
- while($valid) {
- [$valid, $request] = sense senseDetectRequest();
- if($valid) {
- requests += [$request];
- }
- }
- }
- }
- action senseChestItems() {
- do {
- $valid = true;
- while($valid) {
- [$valid, $item] = sense senseDetectChestItem();
- if($valid) {
- if(contains[$item, Block.CHEST, _])
- {
- pick [$item, Block.CHEST, $number] in contains;
- contains -= [$item, Block.CHEST, _];
- $temp = $number + 1;
- contains += [$item, Block.CHEST, int[0:31]($temp)];
- amountOfChestItems += [$item , int[0:31] ($temp)];
- }
- else
- {
- contains += [$item, Block.CHEST, 1];
- }
- }
- }
- }
- }
- proc moveSteveToWorkBench()
- {
- pick[$item , $location, $nmbr] in contains;
- while (amountOfChestItems[_, _]) {
- println("aaaa");
- moveSteve(Block.CHEST);
- take($item);
- moveSteve(Block.WORKBENCH);
- put();
- pick[$item , $location, $nmbr] in contains;
- }
- }
- # TODO Add procedures for the business logic
- proc main() {
- senseRequests();
- senseChestItems();
- moveSteveToWorkBench();
- println("If you can read this, you've come pretty far.");
- println("If you read this in the console, you've come even farther. Congrats, you're almost done!");
- # TODO Read all requests and available items
- # TODO Make an unordered TODO list of abstract steps to take
- # TODO Find sequence of concrete steps to achieve the abstract steps
- # TODO Transfer all requested items into the chest
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement