I am programming a board game with ab board of 4x4 squares and use a unsigned short to save whether a stone is on each square. 0 := empty square
and 1 := stone on square
A board with 8 stones like this:
1111
0000
0101
1010
is saved line by line like this:
unsigned short board = 0b1111000001011010 // = 61530
I need to flip the board vertically,horizontally and diagonally.
Example:
Vertically |
Horizontally |
Diagonally |
1010 0101 0000 1111 |
1111 0000 1010 0101 |
1001 1010 1001 1010 |
0b1010010100001111 //= 42255 |
0b1111000010100101 //= 61605 |
0b1001101010011010 //= 39578 |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…