From 27ac93a9ac3b17a4fe80285bb4c7f11d2d8f82d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9tro?= <yann.roberge@polymtl.ca> Date: Sat, 31 Oct 2020 18:58:57 -0400 Subject: [PATCH] =?UTF-8?q?=CE=99mpl=C3=A9mentation=20de=20goThroughVolume?= =?UTF-8?q?;=20correctifs=20sur=20goThroughArea=20pour=20qu'il=20termine?= =?UTF-8?q?=20sur=20la=20bonne=20case.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rsiTurtle.lua | 48 ++++++++++++++++++++++++++++++++++++++++-------- test.lua | 29 ++++++++++++++++------------- 2 files changed, 56 insertions(+), 21 deletions(-) diff --git a/rsiTurtle.lua b/rsiTurtle.lua index 23f5096..ba8617d 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 80e4932..4211df3 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") -- GitLab