I'm trying to find a hash function that describes solid tetromino in a matrix 4x4 consisting of '0' and '1'. Here is what I mean:
1) 1111 0000 0000 0000 - solid tetromino, all this ones have the same hash 0000 1111 0000 0000 0000 0000 1111 0000 0000 0000 0000 1111 2) 0111 0100 0010 - NOT solid tetromino, any other different hashes 1000 1000 0010 (this examples shows that simple byte code 0000 1000 0100 on rows\columns\their combination will not 0000 0000 0100 work correctly) 3) 0100 0010 0000 - some more examples for the same hash and what 1110 0111 0000 I mean by "solid" tetromino 0000 0000 0100 0000 0000 1110
I am stuck on an idea with the representation of a matrix as a binary number of length 16 made up of a series of rows or columns. It does not work correctly with series 1 and 2 above.
You can find picture of all possible tetrominos on wiki-page.
Ok, I found the perfect function for myself. This clusters all figures of the same type into groups with the same hash.
This takes as input a binary number obtained by condensing the rows of the matrix horizontally.
$$f(x) = \sum_{i=0}^{15} (x[i] == 1) ? (1 << ((i + i div 4) - (fo + fo div 4))) : 0 $$