This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Niseg's profile picture

Variable size rectangular wall /room /octagon builder

Started by Niseg, 05 May 2013 - 01:20 AM
Niseg #1
Posted 05 May 2013 - 03:20 AM
I've made an any size rectangular room builder which places 3 blocks when building walls. At first it wasn't too robust after but after some work I made it a little better and more newbie proof .At this point I'm turning it into an "any shape wall builder".

This script can be used with either command line argument or a basic user interface. it will always stop in a valid building position so it can be chained to build more complex buildings.

command line demo video of building a small castle using auto length/width detection:
[media]http://youtu.be/MfKGmfCgPu0[/media]

pastebin :
http://pastebin.com/ip1SPj7q
pastebin get ip1SPj7q build

dev/beta versions:
Spoilerbeta version - doesn't always work (save a copy if you like it)
http://pastebin.com/0mqi84si

custom shape polygon test
http://pastebin.com/bxczYmxZ
parameters are 0-3 height repeat length1 halfturnL1 length2 halfturnL
the first parameter is a bit flag and when active it does a function . bit 0x1 means unconnected and bit 0x2 means start diagonal

this program doesn't turn around before building. it repeats the build length and half turn commands according to the parameter and then build another z level in the same way.

building an octagon(3 high 4 length ) is test 0 3 8 3 1 .
building a diamond is test 2 3 4 3 2
Basic Features
- Builds a wall of any height with an option of a floor/roof or both(mode 0,1,2,3). It can also build platforms(use height 1 and mode 1)

- Wall building is done in an optimal path by placing 3 blocks which conserve time and fuel
- Go through contiguous slots of blocks - can be planed to make more complex looking buildings
- can build a single wall ( mode 4 )
- breaks blocks in its way (slows it down)
- setting length or width to 0 or -1 will make the turtle search for dimensions. The height must be entered. The script waits for an enter to start this (in ui mode)
-symmetric octagon building (mode 5) to build octagonal walls (I got jealous of Lancey's towers) .the length is now used as flat wall length and width is now used and diagonal wall length. unfortunately diamond tower are not posible but it's close ( length 1 gives length 2 flat walls).
-new feature hexagon tower (6) , parallelogram tower s (7) (I liked MrCrainer's Diamond towers) diagonal wall (8)
- new improvement - the turtle now keeps the correct number of blocks in its inventory regardless of obstacles
-new mechanic wall building function was rewritten to work similar to "logo" language parameters
upcoming features
- haven't started on new version - check future plans

Instructions

Place the turtle in the bottom right corner ( will place a block where it starts , builds left) ,refuel the turtle . Afterwards you should load your building materials .

For the UI just type build . In the UI enter the length ,width , height and mode(walls,walls and floor etc) .Take note the height is inclusive of the floor and roof so if you want to include both and have walls height 3 you should enter height of 5. Using height of 1 with roof/floor mode will build a plate(floor) .

The script can also accept command line parameters in the same order as the UI. Entering valid command line parameters would not prompt you. and start building immediately (will exit if not enough fuel to build). . If you enter invalid parameters the UI will be open syntax will be printed.

For automatic building size detection place the turtle ,refuel it and then place blocks a certain distance in front of the turtle and then one left of the block(the size includes those blocks) . Start the script and enter 0 to either width or length . The turtle will then prompt you to press enter to start size detection. using mode 0 include the placed blocks. If you use width and length of -1 it will build inside the border (the placement should be different for the 2nd block).

If there are obstacles on the way make sure the turtle has an empty slot when it reaches it.

Advanced instructions (build planning / use in scripts etc)
build planning:
SpoilerThe turtle can create basic designs but it has a limited inventory. if you want a different floor/walls. Setting up a certain floor is trivial unless you want an outer wall frame (check next section). When building a wall frame you must first place 3*(length-2) blocks for the inner wall and then 3 blocks for the frame. You repeat the process 3 more times (use width on the 2nd and 4th time) .After you are done put in the blocks for the roof.

When the turtle is done it will always return to a valid building position where you can continue the build in any way you wish.

Take note you can also use the turtle program to replace the walls but due to the fact it turns around and throw away the block to do this.
Writing a front-end program
SpoilerDue to the inherit limitation of the program it sometimes fall short in custom builds but it's still useful if you run it multiple time.

In order to use the program with another script use shell.run("build x y z m") and then move the turtle to a new starting position and call the script again.
if you want to build a pyramid for example do

-- use  mode 1 if you want a filled pyramid
for w=11,3,-2 do
shell.run("build "..w.." "..w.." 1 0")
turtle.turnLeft()
turtle.forward()
turtle.turnRight()
turtle.forward()
end

turtle.placeDown()

You can customize the building in any way that you wish using diagonal movement like in the end of the loop.

There is still a limitation you need to consider when building plates (floor/wall) the turtle will not return to its x,y start position in this case(might add that option in the future).

Detailed features
Spoiler- UI tells the user the maximum height of each building modes
- UI tells the user how many block each layer takes (helps planning complex looking buildings)
- The program exits when there isn't enough fuel to build the requested building. Also tells the user an estimate on the fuel required.
- warns when there aren't enough blocks to build the requested building. gives an option to fill it up in the process (blocks must still be contiguous)
- command line parameters build <length> <width> <height> <0-4>
- return to a valid start position to allow the user to build again (would allow using a front end in the future)
- prints credit to the author (LOL ;)/> didn't exist in version)
- If the turtle is blocked when backing up it will turn around and try to break it. if it fails it will wait for the obstacle to move or be removed while trying to break it contentiously.
Limits
Spoiler- can only build with 1024 blocks (turtle inventory space) unless the user fills it up in the process
- must be pre fueled
- will not dig down a block when it fails to place (might add that) - fixed
- can't handle blocked roof - fixed
- the UI is currently horrible even though it's informative
- the end position may not have the same x,y coordinate to the start position
- inventory tracking system is simplistic
media

- StrayMav building a 7x7x50 tube (beyond constraint ) using an older version (past broadcasts periodically deleted)
- a carefully planed 10x10x5 I made in order to replicate : 100 stone bricks for the floor (64 ,36) ,then the 24 glass, 3 stone brick, repeat that 3 more times and then place 100 clay brick for the roof.

Spoilerthe inventory numbers should look like this
64 36 24 3
24 3 24 3
24 3 64 36



Useful scripts that work well with the builder
universal floor/ceiling breaker ( WAs7AETY ) - This follows the floor/ceiling and break it until it hits a wall, it then turns around and continue until it hit the corner. I made this script because I wasn't satisfied with the room height I built and I didn't feel like breaking the floor/ceiling by hand.

Plans for the future:
Spoiler— in beta version
—-

- add universal floor /roof builder
- custom shape mode - read a file
- auto resupply
- write a wall shape learner that can continue building along any wall.
- add cmd line parameter to return to initial xy position and one to return to start position.
- make the UI better
- elliptical shape builder using f(x,y) by finding best path to stay in the function . I have some preliminary code of coordinate generation is done
- general symmetrical polygons builder- pentagon/heptagon etc and maybe general triangle builder. I'll probably need to add a line drawing function (I've done this in the past in an A* path finding simulator).

- add or write a script that breaks the walls instead of building them (can be done by loading no blocks and using command line but it's slow)
- write a front end to this script to allow complex room building
- rewrite the floor builder in a way it conserves fuel
- separate planning and building
Benchmarks:
- Block placement rates:
- 12x12x12 tank - 0.7~ block/s (85 per minute)
- single wall mode (about 90 long 12 high) 0.56~ blocks/s (107~ per minute)
- worst case = tube inside a mountain 11x11x40 (might be longer) = 2.24 seconds per block(26~ per minute) - it can handle obstacles but block replacement has a huge overhead.

- fuel use for walls is ceil(height/3) *( 2 width +2*length - 4) . For each floor/roof add width*length. example the 12x12x12 tank takes about 4* (2*12+2*12 -4) + 2*12*12 = 176 +288= 464 fuel. when making diagonal walls it's about ceil(height/3) *(2*width +4*length -4) (length is used for diagonal walls in most cases
Keridos #2
Posted 07 May 2013 - 12:23 AM
Eh, no intent to make this look bad, but universal Size Rectangular Room building is fully supported by the versatile shape builder.
Niseg #3
Posted 07 May 2013 - 05:12 AM
Eh, no intent to make this look bad, but universal Size Rectangular Room building is fully supported by the versatile shape builder.

Other than the fact I like writing script my own scripts. My script is a tad more efficient than shape builder as far as I've seen .Shape builder builds walls at 2*h*(2*w +2*l-4) operations, my script as stated does 3 place per move so the movement is (4h/3) *(2*w+2+l -4) operations. the fuel cost of shape builder is about the same as the number of blocks you want to place my script take about a 1/3 for wall placement.

I might do the same program they made with a slightly different approach (suggested it on their thread). What need to be done is to separate the building part from the shape design part

Rectangular shaped buildings are fairly common in minecraft so you choice of script generally depend on what you want to achieve . people can use whatever script they want. It's not really a competition. I've seen a tad of what shape builder can do but I'm kind of obsessive about efficiency. They can go ahead and adopt my method if they want.

My script was more basic in the past but I hit it with some robustness and added some basic features. I don't think I'll invest too much more time in it because I have a lot of different ideas.
Keridos #4
Posted 09 May 2013 - 01:42 PM
Well you could try to write that into our program, I am one of the devs. The script is hosted on Github and we do appreciate any help with it.
There are quite some things that somehow need an overhaul. If you maange to rewrite the wallcode to be more efficient, it would be a great help.
Currently we are working on some other things like a bit refactoring of the code, writing gps support, fixing some small things etc. And as we are only 2 devs at this time, that takes quite a while.
Niseg #5
Posted 19 May 2013 - 04:16 AM
I added a few new features . The turtle will now break the blocks in its way and throw them away (use a mining turtle) . I added a single wall mode #4 which makes the turtle builds a single wall by moving back and forth (useful for quickly adding automatiion to an already built structure)

There is also a feature for the turtle to detect the size of the room the user want to build by detecting two corner blocks . This mode is entered when setting the length or width to 0.

I'll try to add a video to explain the mechanics.

Well you could try to write that into our program, I am one of the devs. The script is hosted on Github and we do appreciate any help with it.
There are quite some things that somehow need an overhaul. If you maange to rewrite the wallcode to be more efficient, it would be a great help.
Currently we are working on some other things like a bit refactoring of the code, writing gps support, fixing some small things etc. And as we are only 2 devs at this time, that takes quite a while.

I tried to modify your code but my modifications were too ambitious . I might be able to improve your basic features. You can feel free to learn what my code is doing and add it to yours (I'll be happy if you credit me for this) .

I also have a few project that I've been neglecting.
Niseg #6
Posted 05 June 2013 - 03:01 AM
Here is a demo of the new build function I made - it can build anything

[media]http://youtu.be/QTq7ERIXatU[/media]

the script can be found here
http://pastebin.com/EPwMT1ug

I might make it release version and move my debugging to another paste . Take note it's very early . the parameters it takes is connected(true/false) height repeat and afterwards pairs of numbers the first number is the length and the second number is number of half turn left (if you give it a negative number it turns right).
LazyNub #7
Posted 05 June 2013 - 03:26 PM
Nice. :)/>

I'm in the middle of making builder programs.. Your program maybe able to do everything I need already..