Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- individual={
- pos={
- x=1,y=1
- },
- rot=3,
- fuel=15,
- new=function(this,...)
- object = {}
- setmetatable(object,this)
- this.__index=this
- return object
- end,
- go=function(this,world)
- if not world then error("specify world please",2) end
- if this.fuel<=0 then print("out of fuel") return false end
- if this.rot==1 and world[this.pos.y-1] then --up
- this.pos.y=this.pos.y-1
- elseif this.rot==2 and world[this.pos.y][this.pos.x-1] then --left
- this.pos.x=this.pos.x-1
- elseif this.rot==3 and world[this.pos.y+1] then --down
- this.pos.y=this.pos.y+1
- elseif this.rot==4 and world[this.pos.y][this.pos.x+1] then --right
- this.pos.x=this.pos.x+1
- else
- print"can't reach destination"
- return false
- end
- this.fuel=this.fuel-1
- return true
- end,
- turnLeft=function(this)
- if this.rot~=4 then this.rot=this.rot+1
- else this.rot=1 end
- end,
- turnRight=function(this)
- if this.rot~=1 then this.rot=this.rot-1
- else this.rot=4 end
- end,
- feed=function(this,world)
- if not world then error("specify world please",2) end
- if this.rot==1 then
- if type(world[this.pos.y-1][this.pos.x])=="number" and world[this.pos.y-1][this.pos.x]==1 then
- this.fuel=this.fuel+5
- world[this.pos.y-1][this.pos.x]=0
- return world
- end
- elseif this.rot==2 then
- if world[this.pos.y][this.pos.x-1] and world[this.pos.y][this.pos.x-1]==1 then
- this.fuel=this.fuel+5
- world[this.pos.y][this.pos.x-1]=0
- return world
- end
- elseif this.rot==3 then
- if world[this.pos.y+1][this.pos.x] and world[this.pos.y+1][this.pos.x]==1 then
- this.fuel=this.fuel+5
- world[this.pos.y+1][this.pos.x]=0
- return world
- end
- elseif this.rot==4 then
- if world[this.pos.y][this.pos.x+1] and world[this.pos.y][this.pos.x+1]==1 then
- this.fuel=this.fuel+5
- world[this.pos.y][this.pos.x+1]=0
- return world
- end
- return false
- end
- end,
- }
Advertisement
Add Comment
Please, Sign In to add comment