diff --git a/rsiTurtle.lua b/rsiTurtle.lua index 23f509662c9e9717708986c3df5d965d2e264174..ba8617da7cdd971dceadf48e9fc01caea627e491 100644 --- a/rsiTurtle.lua +++ b/rsiTurtle.lua @@ -500,17 +500,12 @@ function RSI_Turtle:goThroughArea(lines, cols, action, grounded) end action() - for i=1,cols,1 + success = self:moveForward(lines, grounded, action) + for i=2,cols,1 do print("Debut de colonne.") - success = self:moveForward(lines, grounded, action) - if not success - then - return success - end - - if ( (i%2) == 0 ) + if ( (i%2) == 1 ) then success = self:left(grounded) self:turnLeft() @@ -520,6 +515,13 @@ function RSI_Turtle:goThroughArea(lines, cols, action, grounded) end action() + success = self:moveForward(lines, grounded, action) + + if not success + then + return success + end + end return success end @@ -650,4 +652,34 @@ function RSI_Turtle:dig(blockIdRegex, side) end +--- +-- \brief Quadriller une zone carrée. La tortue traverse chaque case, ligne par +-- ligne. N'affecte pas l'altitude. +-- \param pointeur_de_fonction action Pointeur de l'action à réaliser juste +-- après être arrivé sur chaque nouveau bloc. +-- \param int lines Nombre de lignes (direction: avant) +-- \param int cols Nombre de colonnes (direction: droite) +-- \param int depth Profondeur (direction: bas) +-- \param function_pointer action Action immédiatement après chaque déplacement +-- \return bool Succès +function RSI_Turtle:goThroughVolume(lines, cols, depth, action) + local success = true + + assert(lines >= 1) + assert(cols >= 1) + assert(depth >= 1) + + for i=1,depth,1 + do + success = self:goThroughArea(lines, cols, action) + success = self:moveTo2D(0,0) + action() + success = self:down() + self:face(12) + end + + return success +end + + return RSI_Turtle diff --git a/test.lua b/test.lua index 80e4932451c179b661df84ee8a86ef77e545a7bd..4211df35ebf3524d7113b828dbbe177e6793579c 100644 --- a/test.lua +++ b/test.lua @@ -12,9 +12,9 @@ require("bloc_ids") -- rsiT.helloWorld() --- print("Test de RSI_Turtle") --- t = rsiT:init() --- t:print() +print("Test de RSI_Turtle") +t = rsiT:init() +t:print() print("Test de RSI_Bucheron") b = rsiB:init() @@ -75,10 +75,10 @@ b:print() -- print("Test moveBackward;") -- t:moveBackward(5) --- function checkPos(x,y,z) --- xPos, yPos, zPos = t:getPos() --- return ( xPos == x and yPos == y and zPos == z ) --- end +function checkPos(x,y,z) + xPos, yPos, zPos = t:getPos() + return ( xPos == x and yPos == y and zPos == z ) +end -- print("Tests face;") -- for i=0,9,3 @@ -179,13 +179,16 @@ b:print() --print("Test chopArea") --assert(b:chopArea(15, 20)) -print("Test moveToOriginGounded") -b.base_:moveTo(5,5,5) -assert(b.base_:moveToOriginGrounded()) +--print("Test moveToOriginGounded") +--b.base_:moveTo(5,5,5) +--assert(b.base_:moveToOriginGrounded()) --- assert(t:moveToOrigin()) --- print(t:getPos()) --- testassert(checkPos(0,0,0)) +print("Test goThroughVolume") +assert(t:goThroughVolume(4,3,3, turtle.digDown)) + +assert(t:moveToOrigin()) +print(t:getPos()) +assert(checkPos(0,0,0)) print("Fin des tests")