Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Tortues CC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yann Roberge
Tortues CC
Commits
4cff00bd
Commit
4cff00bd
authored
4 years ago
by
Yann Roberge
Browse files
Options
Downloads
Patches
Plain Diff
Implémentation des fonctions nécéssaires au bûcheronnage
parent
a72da072
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
bucher.lua
+107
-5
107 additions, 5 deletions
bucher.lua
rsiTurtle.lua
+74
-2
74 additions, 2 deletions
rsiTurtle.lua
test.lua
+41
-16
41 additions, 16 deletions
test.lua
with
222 additions
and
23 deletions
bucher.lua
+
107
−
5
View file @
4cff00bd
...
...
@@ -31,20 +31,122 @@ function RSI_Bucheron:print()
self
.
base_
:
print
()
end
---
-- \brief Abattre un arbre
-- \return bool Succès
function
RSI_Bucheron
:
chopTree
()
--TODO: Implementer
local
success
local
countMovedUp
=
0
success
=
self
.
base_
:
dig
(
ID_LOG
)
if
(
not
success
)
then
return
false
end
success
=
self
.
base_
:
forward
()
print
(
"Chopping down"
)
while
(
self
.
base_
:
dig
(
ID_LOG
,
"down"
)
)
do
self
.
base_
:
down
()
end
print
(
"Moving up"
)
-- Remonter pour couper les bûches vers le haut. Essaie de trouver des
-- bûches sur quelques blocs de haut avant d'abandonner et redescendre.
while
(
countMovedUp
<
3
and
self
.
base_
:
up
())
do
countMovedUp
=
countMovedUp
+
1
printf
(
"Moved up %d\n"
,
countMovedUp
)
end
print
(
"Chopping up"
)
while
(
self
.
base_
:
dig
(
ID_LOG
,
"up"
)
)
do
self
.
base_
:
up
()
end
self
.
base_
:
ground
()
return
success
end
---
-- \brief Couper les arbres tout en avançant le long d'une ligne
-- \param int distance Nombre de blocs à parcourir
-- \return bool Succès
function
RSI_Bucheron
:
moveChop
(
distance
)
--TODO: Implémenter
local
success
=
true
local
traveled
=
0
self
:
chopTree
()
self
.
base_
:
ground
()
self
.
base_
:
climb
()
while
(
traveled
<
distance
)
and
turtle
.
forward
()
do
self
:
chopTree
()
self
.
base_
:
ground
()
self
.
base_
:
climb
()
self
:
chopTree
()
traveled
=
traveled
+
1
end
if
self
.
facing_
==
0
then
self
.
base_
.
pos_
[
"x"
]
=
self
.
base_
.
pos_
[
"x"
]
+
traveled
elseif
self
.
base_
.
facing_
==
3
then
self
.
base_
.
pos_
[
"z"
]
=
self
.
base_
.
pos_
[
"z"
]
+
traveled
elseif
self
.
base_
.
facing_
==
6
then
self
.
base_
.
pos_
[
"x"
]
=
self
.
base_
.
pos_
[
"x"
]
-
traveled
elseif
self
.
base_
.
facing_
==
9
then
self
.
base_
.
pos_
[
"z"
]
=
self
.
base_
.
pos_
[
"z"
]
-
traveled
end
return
(
traveled
==
distance
)
end
---
-- \brief Couper les arbres dans la zone
-- \param int
nLig
nes
Nombre de lignes
-- \param int
nColonnes
Nombre de colonnes
-- \param int
li
nes Nombre de lignes
-- \param int
cols
Nombre de colonnes
-- \return bool Succès
function
RSI_Bucheron
:
main
(
nLignes
,
nColonne
s
)
function
RSI_Bucheron
:
chopArea
(
lines
,
col
s
)
--TODO: Implementer
local
success
=
true
assert
(
lines
>=
1
)
assert
(
cols
>=
1
)
-- La ligne de la case de départ compte comme 1
lines
=
lines
-
1
self
.
base_
:
ground
()
self
:
chopTree
()
for
i
=
1
,
cols
,
1
do
print
(
"Debut de colonne."
)
success
=
self
:
moveChop
(
lines
)
-- FIXME: Remplacer moveForward par moveChop
self
.
base_
:
ground
()
self
.
base_
:
climb
()
if
not
success
then
return
success
end
if
(
(
i
%
2
)
==
0
)
then
success
=
self
.
base_
:
left
(
true
)
self
.
base_
:
turnLeft
()
else
success
=
self
.
base_
:
right
(
true
)
self
.
base_
:
turnRight
()
end
self
:
chopTree
()
end
return
success
end
return
RSI_Bucheron
return
RSI_Bucheron
\ No newline at end of file
This diff is collapsed.
Click to expand it.
rsiTurtle.lua
+
74
−
2
View file @
4cff00bd
...
...
@@ -556,13 +556,85 @@ end
---
-- \brief Vérifier si l'ID du bloc en face contient la regex
-- \param string blockIdRegex Regex correspondant au bloc à vérifier
-- \param string side Direction parmi: front, back, up, down, left, right
-- Si vide, prend "front" par défaut
-- \return bool Bloc en face match la regex
function
RSI_Turtle
:
facesBlock
(
blockIdRegex
)
local
isNotAir
,
blockData
=
turtle
.
inspect
()
function
RSI_Turtle
:
facesBlock
(
blockIdRegex
,
side
)
local
isNotAir
,
blockData
if
side
==
nil
then
side
=
"front"
end
if
side
==
"up"
then
isNotAir
,
blockData
=
turtle
.
inspectUp
()
elseif
side
==
"down"
then
isNotAir
,
blockData
=
turtle
.
inspectDown
()
elseif
side
==
"front"
then
isNotAir
,
blockData
=
turtle
.
inspect
()
elseif
side
==
"back"
then
self
:
turn180
()
isNotAir
,
blockData
=
turtle
.
inspect
()
elseif
side
==
"left"
then
self
:
turnLeft
()
isNotAir
,
blockData
=
turtle
.
inspect
()
elseif
side
==
"right"
then
self
:
turnRight
()
isNotAir
,
blockData
=
turtle
.
inspect
()
end
if
(
isNotAir
)
then
return
string.match
(
blockData
.
name
,
blockIdRegex
)
else
return
false
end
end
---
-- \brief Casser un bloc dans la direction souhaitée
-- \param string blockIdRegex Regex correspondant au bloc à casser.
-- Si vide, casse n'importe quoi.
-- \param string side Direction parmi: front, back, up, down, left, right
-- Si vide, prend "front" par défaut
-- \return bool Succès
function
RSI_Turtle
:
dig
(
blockIdRegex
,
side
)
--TODO: Tester
local
success
if
blockIdRegex
==
nil
then
blockIdRegex
=
''
end
if
side
==
nil
then
side
=
"front"
end
if
(
self
:
facesBlock
(
blockIdRegex
,
side
))
then
if
(
side
==
"up"
)
then
success
=
turtle
.
digUp
()
elseif
(
side
==
"down"
)
then
success
=
turtle
.
digDown
()
else
success
=
turtle
.
dig
()
end
end
return
success
end
return
RSI_Turtle
This diff is collapsed.
Click to expand it.
test.lua
+
41
−
16
View file @
4cff00bd
...
...
@@ -10,19 +10,19 @@ rsiE = require("excaver")
require
(
"bloc_ids"
)
rsiT
.
helloWorld
()
--
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
()
b
:
print
()
print
(
"Test de RSI_Excavatrice"
)
e
=
rsiE
:
init
()
e
:
print
()
--
print("Test de RSI_Excavatrice")
--
e = rsiE:init()
--
e:print()
-- print("Test de l'API turtle")
-- print(turtle.inspect())
...
...
@@ -75,10 +75,10 @@ e: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
...
...
@@ -151,12 +151,37 @@ end
-- assert(t:goThroughArea(15, 15, true, nil))
-- assert(t:goThroughAreaGrounded(3, 3, turtle.placeUp))
print
(
"Tests facesBlock"
)
assert
(
t
:
facesBlock
(
ID_LOG
))
--print("Tests facesBlock")
--assert(t:facesBlock(ID_LOG))
--assert(t:facesBlock(ID_LOG, "front"))
--assert(t:facesBlock(ID_LOG, "back"))
--assert(t:facesBlock(ID_LOG, "down"))
--assert(t:facesBlock(ID_LOG, "up"))
--assert(t:facesBlock(ID_LOG, "right"))
--assert(t:facesBlock(ID_LOG, "left"))
-- print("Test dig")
--assert(b.base_:dig(ID_LOG, "left"))
--b.base_:face(12)
--assert(b.base_:dig(ID_LOG, "right"))
--b.base_:face(12)
--assert(b.base_:dig(ID_LOG, "front"))
--b.base_:face(12)
--assert(b.base_:dig(ID_LOG, "back"))
--b.base_:face(12)
--assert(b.base_:dig(ID_LOG, "down"))
--b.base_:face(12)
--assert(b.base_:dig(ID_LOG, "up"))
--print("Test chopTree")
--assert(b:chopTree())
print
(
"Test chopArea"
)
assert
(
b
:
chopArea
(
15
,
20
))
assert
(
t
:
moveToOrigin
())
print
(
t
:
getPos
())
assert
(
checkPos
(
0
,
0
,
0
))
--
assert(t:moveToOrigin())
--
print(t:getPos())
-- test
assert(checkPos(0,0,0))
print
(
"Fin des tests"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment