Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- should be the same as as position
- -- but uses a table with positions
- -- so that several positions can be used
- x="x" -- forward, back
- y="y" -- up, down
- z="z" -- right, left (not turn)
- rot="rot" -- direction/rotation the turtle is facing
- -- this can be used to make sure
- -- the turtle isn't outside a
- -- cube of a certain size
- function getLargest(posT)
- -- make local copies of the coordinates
- -- but use the absolute value
- local x=math.abs(posT[x])
- local y=math.abs(posT[y])
- local z=math.abs(posT[z])
- if x>y then
- if x>z then
- return x
- else
- return z
- end
- else
- if y>z then
- return y
- else
- return z
- end
- end
- end
- function printit(posT)
- print("before: "..posT[x].." "..posT[y].." "..posT[z].." "..rot)
- end
- function reset(posT)
- posT[x]=0
- posT[y]=0
- posT[z]=0
- posT[rot]=0
- end
- function getAPosT(x,y,z,rot)
- if x==nil then x=0 end
- if y==nil then y=0 end
- if z==nil then z=0 end
- if rot==nil then rot=0 end
- local posT={
- x=x,
- y=y,
- z=z,
- rot=rot,
- }
- return posT
- end
- -- put function in the table
- horzT={
- [0]=function(posT,length)
- posT[x]=posT[x]+length
- end,
- [1]=function(posT,length)
- posT[z]=posT[z]+length
- end,
- [2]=function(posT,length)
- posT[x]=posT[x]-length
- end,
- [3]=function(posT,length)
- posT[z]=posT[z]-length
- end,
- }
- -- table that can update the coordinates
- -- if you go a given length in the
- -- in a direction
- updateT={
- f=function(posT,length)
- horzT[rot](posT,length)
- end,
- b=function(posT,length)
- horzT[rot](posT,length)
- end,
- u=function(posT,length)
- y=y+length
- end,
- d=function(posT,length)
- y=y-length
- end,
- r=function(posT,length)
- posT[rot]=(posT[rot]+length)%4
- end,
- l=function(posT,length)
- posT[rot]=(posT[rot]-length)%4
- end,
- }
- -- updates the position values
- -- given the input values
- -- returns nil
- function update(posT, dir, length)
- --print("before: "..x.." "..y.." "..z.." "..rot)
- --print(dir.." "..length)
- updateT[dir](posT, length)
- --print("after: "..x.." "..y.." "..z.." "..rot)
- end
- function whatIf(posT, dir, length)
- update(posT, dir,length)
- local a, b, c, d=get(posT)
- update(posT, dir,-length)
- return a,b,c,d
- end
- function whatIfLargest(posT, dir, length)
- update(posT, dir,length)
- local res=getLargest()
- --print(x.." "..y.." "..z" "..rot)
- update(posT, dir,-length)
- return res
- end
- -- returns the position values
- -- x,y,z,rot
- function get(posT)
- return posT[x], posT[y],posT[z], posT[rot]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement