Diagonal Tiling
WHAT IS IT?
My father, Jim, a gifted mathematician, has accoustical ceiling tiles with identical punched patterns of holes in his bedroom. He asked me what the probability is if identical square tiles fill a plane at random that four adjacent corners will be identical. My first reaction was that it would be about one in four.
Diagonal Tiling distributes 361 (19 * 19) identical turtiles on the surface of a torus. Each tile will eventually settle in one of four possible orientations. That was the easy part, requiring literally three lines of code excluding the "to"s and "end"s and designing the turtile.
The Tally routine is the rest of the program, and asks each turtile to poll its neighbors at its southwest (screen coordination) corner to see if they are oriented so as to place similar corners together. I played with little cards I made, and tried several procedures before I settled on this one. I got substantial help in the process from Nick Bennett, who pointed out that each turtile only needs to be responsible for one of its corners.
During the debugging process, while trying to figure out why the tally was coming out wrong (because I was trying to decrement xcor and ycor, instead of trusting heading-at to understand it was already relative to the calling turtle) I added the stamp command, and immediately encountered another problem. The patch refused to be stamped until I had opened and closed the shape-chooser window. Eventually I learned that a patch does not actually display its new stamped color until the turtle has moved. Hence the last line in the program, "set xcor xcor + .01." Gently bump the turtiles.
HOW TO USE IT
Press 'setup' to initialize everything. Press 'settle' to make the tiles settle in an orientation. FInally, press 'tally' to start the polling process.
THINGS TO NOTICE
Consider this: Two tiles next to each other have a .5 probability of coincidence in one corner, a .25 probability in a specific corner. Adding another tile at that corner lowers the probability to 1:16, and another drags it down to 1:64. Even this number is too high, because if two tiles have coincidental corners, then there cannot be a coincidence at their other corner. Therefore close calls eliminate other possibilities, and more coincidences at one corner eliminate the possibility of more coincidences at the other corners.
EXPLORATIONS
This program can be used in a statistics class as an example of using a very simple StarLogo program to experiment with a complex problem. It is also a pretty decent demonstration that we can do a lot more with Starlogo than rabbits and grass! :)
Turtle procedures
to settle
if count-turtles-here > 1 [seth (random 4) * 90 fd 1] ;The whole program. Move around until you are the only turtile here.
end
to tally-up
case heading[ ;This procedure has each turtle check her own orientation and that of her 3 southwestern neighbors.
;Depends on the checker's own orientation (case), and then her neighbors.
0 [if (heading-at 0 -1) = 90 and (heading-at -1 -1) = 180 and (heading-at -1 0) = 270 [stamp brown set tally tally + 1]]
90 [if (heading-at 0 -1) = 180 and (heading-at -1 -1) = 270 and (heading-at -1 0) = 0 [stamp brown set tally tally + 1]]
180 [if (heading-at 0 -1) = 270 and (heading-at -1 -1) = 0 and (heading-at -1 0) = 90 [stamp brown set tally tally + 1]]
270 [if (heading-at 0 -1) = 0 and (heading-at -1 -1) = 90 and (heading-at -1 0) = 180 [stamp brown set tally tally + 1]]
]
set xcor xcor + .01 ;Turtiles are transparent, but StarLogo doesn't stamp until the turtle moves. Even a tiny bit.
end
