diff --git a/main.cpp b/main.cpp index c8eb24d..855f375 100644 --- a/main.cpp +++ b/main.cpp @@ -12,6 +12,7 @@ static void finish(int sig); void init_colors(); void PlacePiece(Piece piece, const std::vector &flips, Rotation rotation, int y, int x); +void GetPosition(unsigned long position, int &y, int &x); int main(int argc, char *argv[]) { @@ -44,6 +45,8 @@ int main(int argc, char *argv[]) Flip horizontal = (0b1000 & input_val) ? Flip::FLIP_HORIZONTAL : Flip::FLIP_NONE; Flip vertical = (0b10000 & input_val) ? Flip::FLIP_VERTICAL : Flip::FLIP_NONE; Rotation rotation = static_cast((0b1100000 & input_val) >> 5); + unsigned long position = (0b1111110000000 & input_val) >> 7; + GetPosition(position, y, x); PlacePiece(piece, { horizontal, vertical }, rotation, @@ -113,3 +116,57 @@ void PlacePiece(Piece piece, const std::vector &flips, Rotation rotation, PD_DrawPiece(data, y, x, piece); } + +void GetPosition(unsigned long position, int &y, int &x) +{ + if(position < 6) + { + y = 0; + x = position; + return; + } + + if(position < 12) + { + y = 1; + x = position - 6; + return; + } + + if(position < 19) + { + y = 2; + x = position - 12; + return; + } + + if(position < 26) + { + y = 3; + x = position - 19; + return; + } + + if(position < 33) + { + y = 4; + x = position - 26; + return; + } + + if(position < 40) + { + y = 5; + x = position - 33; + return; + } + + if(position < 43) + { + y = 6; + x = position - 40; + } + + x = y = 0; + return; +}