add robot prototype

This commit is contained in:
Redo
2022-10-28 16:28:16 -06:00
parent 5ecd2ce020
commit 8edbb986c7
4 changed files with 27 additions and 34 deletions

View File

@@ -16,9 +16,7 @@ local function rotateVector(vec, rot)
end
return function(gate)
print("robot update")
if not gate.waiting then
print("not waiting")
local action = ""
if Gate.getportstate(gate, 7)~=0 then -- remove brick
action = action.."R\t"
@@ -37,33 +35,26 @@ return function(gate)
end
local movePos = {0, 0, 0}
if Gate.getportstate(gate, 9)~=0 then movePos[3] = movePos[3]-1 end -- down
if Gate.getportstate(gate, 10)~=0 then movePos[3] = movePos[3]+1 end -- up
if Gate.getportstate(gate, 11)~=0 then movePos[3] = movePos[1]+1 end -- right
if Gate.getportstate(gate, 12)~=0 then movePos[3] = movePos[1]-1 end -- left
if Gate.getportstate(gate, 13)~=0 then movePos[3] = movePos[2]-1 end -- back
if Gate.getportstate(gate, 14)~=0 then movePos[3] = movePos[2]+1 end -- fore
if Gate.getportstate(gate, 9)~=0 then movePos[3] = movePos[3]-0.2 end -- down
if Gate.getportstate(gate, 10)~=0 then movePos[3] = movePos[3]+0.2 end -- up
if Gate.getportstate(gate, 11)~=0 then movePos[1] = movePos[1]+0.5 end -- right
if Gate.getportstate(gate, 12)~=0 then movePos[1] = movePos[1]-0.5 end -- left
if Gate.getportstate(gate, 13)~=0 then movePos[2] = movePos[2]-0.5 end -- back
if Gate.getportstate(gate, 14)~=0 then movePos[2] = movePos[2]+0.5 end -- forward
local moveRotation = 0
--if Gate.getportstate(gate, 13)~=0 then moveRotation = moveRotation+1 end -- right
--if Gate.getportstate(gate, 14)~=0 then moveRotation = moveRotation-1 end -- left
gate.robotdir = (gate.robotdir + moveRotation)%4
if movePos[1]~=0 or movePos[2]~=0 or movePos[3]~=0 then
if movePos[1]~=0 or movePos[2]~=0 or movePos[3]~=0 or moveRotation~=0 then
movePos = rotateVector(movePos, gate.robotdir)
gate.robotpos = { gate.robotpos[1]+movePos[1], gate.robotpos[2]+movePos[2], gate.robotpos[3]+movePos[3] }
action = action.."M "..gate.robotpos[1].." "..gate.robotpos[2].." "..gate.robotpos[3].."\t"
end
if moveRotation~=0 then
action = action.."A "..gate.robotdir.."\t"
action = action.."M "..gate.robotpos[1].." "..gate.robotpos[2].." "..gate.robotpos[3].." "..gate.robotdir.."\t"
end
if action~="" then
print("robot action")
print(action)
Gate.cb(gate, action:sub(1, #action-1))
gate.waiting = true
end
else
print("waiting")
end
end