Two ideas

If you have a design you're proud of, share the cfdg file here. It's also a good place to ask for feedback and collaborate.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
otto
Posts: 5
Joined: Mon Dec 26, 2005 11:17 pm
Location: Chicago, IL
Contact:

Two ideas

Post by otto »

I've got a couple of ideas I want to do with context free. I haven't put too much thought into the algorithms for them yet, but maybe someone else will have some good input.

1. Tetris. Here's some code for the tetris shapes. But I'd like to also be able to generate what looks like a tetris game. You know, with some blocks already placed at the bottom, and a shape falling from above. In my 30 mins of effort so far, I've only been able to generate some pretty random looking towers.

Tetris shape code:
rule zig
{
brick{hue 200 sat 0.3}
brick{hue 200 sat 0.3 x 1.1}
brick{hue 200 sat 0.3 x 1.1 y 1.1}
brick{hue 200 sat 0.3 x 2.2 y 1.1}
}

rule zag
{
zig{flip 90 hue 40}
}

rule T
{
brick{hue 160 sat 0.3}
brick{hue 160 sat 0.3 x 1.1}
brick{hue 160 sat 0.3 x 2.2}
brick{hue 160 sat 0.3 x 1.1 y 1.1}
}

rule L
{
brick{hue 120 sat 0.3}
brick{hue 120 sat 0.3 x 1.1}
brick{hue 120 sat 0.3 x 2.2}
brick{hue 120 sat 0.3 x 2.2 y 1.1}
}

rule line
{
brick{hue 80 sat 0.3}
brick{hue 80 sat 0.3 x 1.1}
brick{hue 80 sat 0.3 x 2.2}
brick{hue 80 sat 0.3 x 3.3}
}

rule block
{
brick{hue 20 sat 0.3}
brick{hue 20 sat 0.3 x 1.1}
brick{hue 20 sat 0.3 y 1.1}
brick{hue 20 sat 0.3 x 1.1 y 1.1}
}

rule brick
{
square{b 0.5}
}

rule square
{
SQUARE{}
SQUARE{s 0.8 b 1}
}


2. Maze Generation. Has anyone done this with context free yet? I've briefly looked over a few algorithms, but they all seem to need a more traditional programming language that can keep state. Here's some code. It's probably not the best beginning for maze generation, but its useful for...I dunno...something. Connect the rules together to create a path.

rule intersection4
{
corridor{}
corridor{r 90 y 2.2}
corridor{r -90 x 2.2 y 4.4}
corridor{y 4.4}
}

rule intersectionT
{
corridor{}
corridor{r 90 y 2.2}
corridor{r -90 x 2.2 y 4.4}
wall{r -90 y 4.4}
}

rule deadEnd
{
wall{}
wall{x 2.2}
wall{r 90 x 2.2 y 2.2}
}

rule corner
{
wall{x 2.2}
wall{r 90 x 2.2 y 3.3}
}

rule corridor
{
wall{}
wall{x 2.2}
}

rule wall
{
brick{}
brick{y 1.1}
brick{y 2.2}
}

rule brick
{
square{b 0.5}
}

rule square
{
SQUARE{}
SQUARE{s 0.8 b 1}
}

robo git
Posts: 47
Joined: Sat Jul 09, 2005 11:36 pm
Location: looking for his marbles
Contact:

Post by robo git »

Nice work with the tetris shapes - excellent way to start building up a primatives library.

Maze: Unfortunately I can't see any way to generate random mazes short of pre-generating larger maze-segments made from the basic shape-set youve done above (or similar) and randomly combining them. Even then it would be very hard to guarantee only a single solution, or that it is actually solvable at all.

Post Reply