Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local printy = print
- local print = function() end
- tArgs = {...}
- if not tArgs[1] then
- printy("Error: no cards specified")
- do return end
- end
- file = tArgs[1]
- os.loadAPI("fileAPI")
- os.loadAPI("stringAPI")
- lines = fileAPI.lines_from("cards/"..file)
- cards = {}
- for k,v in pairs(lines) do
- t = stringAPI.split(v)
- i, ifUntidy , ifTidy = t[1],t[2],t[3]
- cards[i] = {ifTidy = ifTidy, ifUntidy = ifUntidy}
- if not iFirst then
- iFirst = i
- end
- end
- for k,v in pairs(cards) do
- print(k," ",v.ifUntidy ," ",v.ifTidy )
- end
- turns = {}
- turns["00"] = function() printy("going forward") end
- turns["01"] = function() printy("turning left") turtle.turnLeft() end
- turns["10"] = function() printy("turning right") turtle.turnRight() end
- turns["11"] = function() printy("turning around") for i=1,2 do turtle.turnLeft() end end
- function interpret(str)
- t = {}
- t.untidy = str:sub(1,1)=="1"
- print(t.untidy and "untidy" or "tidy")
- t.doSomething = str:sub(2,2)=="1"
- t.turn = str:sub(3,4)
- t.goto = str:sub(5)
- return t
- end
- index = iFirst
- repeat
- if turtle.detectUp() then
- printy("Error: out of bounds")
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- end
- printy(index," ",cards[index].ifUntidy," ",cards[index].ifTidy," ",turtle.detectDown())
- instructions = turtle.detectDown() and interpret(cards[index].ifUntidy) or interpret(cards[index].ifTidy)
- if instructions then
- print(instructions.doSomething," ",instructions.untidy)
- if instructions.untidy and instructions.doSomething then
- turtle.digDown()
- end
- if not instructions.untidy and instructions.doSomething then
- turtle.placeDown()
- end
- turns[instructions.turn]()
- turtle.forward()
- index = instructions.goto
- end
- until index == string.rep("0",iFirst:len())
- printy("Operation complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement