Closed nslottow closed 12 years ago
It was necessary when you consider that a Move is defined by a (ID, Rotation, Coordinate) tuple. Which coordinate was the piece played at? Answer: root. Also, what is the rotation point of this piece:
XXXX
...X
The center of mass for that piece does not lie in one of the 8 spaces of it's 4x2 grid. I cannot look at that piece and infer 1. how it will rotate, or 2. how to define where I play it. This problem gets worse as pieces grow or become non-contiguous. It also means to rotate you have to define a point not on the grid, which I did not like.
Storing the root in ASCII could be dropped. Right now all roots are the top-most then left-most defined block in the grid, but I find them a great convenience for easy human parsing.
Just to clarify, before pieces were defined in a square matrix and used a tetris-like rotation system. See: http://tetris.wikia.com/wiki/SRS
So the position of the piece was determined by the lower left corner of the bounding square, the center was always the center of the square.
None of the problems that you pointed out apply as long as the ASCII format is a square. So the piece you asked about would look like this
.... XXXX ...X ....
OR
..X. ..X. ..X. .XX.
See the unit tests.
I suppose that format works as well, but I do not like the property that a piece has an origin [bottom-left] but does not rotate about its own origin.
The root format also has some really nice properties for a slightly less dumb dummybot. A dummy bot now can:
This logic is much harder with the tetris model. I think the root model fits the style / requirements of this game better.
I'm convinced, thanks.
Why do Pieces now require a "root"? Before, they rotated around the center as per a tetris-like algorithm.
Adding the root seems to require you to now indicate the root in the ASCII, normalize coordinates and store a "shape," which is actually just a bounding box.
This seems much more complicated than the way it was before and without good reason (also all the unit tests are broken).