ewust / blokus

blokus board game played over a network
0 stars 0 forks source link

Piece rotation change rationale? #7

Closed nslottow closed 12 years ago

nslottow commented 12 years ago

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).

ppannuto commented 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.

nslottow commented 12 years ago

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.

ppannuto commented 12 years ago

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:

  1. Play first piece.
  2. Update set of 'open-corners' with piece just placed
  3. Attempt to play all pieces [at all orientations] at root until
    • A piece is placed, Goto 2
    • Skip all remaining turns

This logic is much harder with the tetris model. I think the root model fits the style / requirements of this game better.

nslottow commented 12 years ago

I'm convinced, thanks.