#include "shapes.h" #include <map> using namespace std; // Layouts of each type of block shape of each version (rotation orientation) map<char,map<int,vector<pair<int,int>>>> Shapes::layouts = { {'I', {{0, {{0,0}, {0,1}, {0,2}, {0,3}}}, {1, {{0,0}, {-1,0}, {-2,0}, {-3,0}}}, {2, {{0,0}, {0,1}, {0,2}, {0,3}}}, {3, {{0,0}, {-1,0}, {-2,0}, {-3,0}}}}}, {'J', {{0, {{0,0}, {0,1}, {0,2}, {-1,0}}}, {1, {{0,0}, {-1,0}, {-2,0}, {-2,1}}}, {2, {{-1,0}, {-1,1}, {-1,2}, {0,2}}}, {3, {{0,0}, {0,1}, {-1,1}, {-2,1}}}}}, {'L', {{0, {{0,0}, {0,1}, {0,2}, {-1,2}}}, {1, {{0,0}, {0,1}, {-1,0}, {-2,0}}}, {2, {{0,0}, {-1,0}, {-1,1}, {-1,2}}}, {3, {{0,1}, {-1,1}, {-2,1}, {-2,0}}}}}, {'O', {{0, {{0,0}, {0,1}, {-1,0}, {-1,1}}}, {1, {{0,0}, {0,1}, {-1,0}, {-1,1}}}, {2, {{0,0}, {0,1}, {-1,0}, {-1,1}}}, {3, {{0,0}, {0,1}, {-1,0}, {-1,1}}}}}, {'S', {{0, {{0,0}, {0,1}, {-1,1}, {-1,2}}}, {1, {{0,1}, {-1,1}, {-1,0}, {-2,0}}}, {2, {{0,0}, {0,1}, {-1,1}, {-1,2}}}, {3, {{0,1}, {-1,1}, {-1,0}, {-2,0}}}}}, {'Z', {{0, {{0,2}, {0,1}, {-1,1}, {-1,0}}}, {1, {{0,0}, {-1,0}, {-1,1}, {-2,1}}}, {2, {{0,2}, {0,1}, {-1,1}, {-1,0}}}, {3, {{0,0}, {-1,0}, {-1,1}, {-2,1}}}}}, {'T', {{0, {{-1,0}, {-1,1}, {-1,2}, {0,1}}}, {1, {{-1,0}, {-2,1}, {-1,1}, {0,1}}}, {2, {{0,0}, {0,1}, {0,2}, {-1,1}}}, {3, {{0,0}, {-1,0}, {-2,0}, {-1,1}}}}}, {'*', {{0, {{0,0}}}}} }; map<char,vector<vector<bool>>> Shapes::binaries = { {'I', {{true, true, true, true}}}, {'J', {{true, false, false}, {true, true, true}}}, {'L', {{false, false, true}, {true, true, true}}}, {'O', {{true, true}, {true, true}}}, {'S', {{false, true, true}, {true, true, false}}}, {'Z', {{true, true, false}, {false, true, true}}}, {'T', {{true, true, true}, {false, true, false}}} }; map<char,map<int,int>> Shapes::heights = { {'I', {{0,1}, {1,4}, {2,1}, {3,4}}}, {'J', {{0,2}, {1,3}, {2,2}, {3,3}}}, {'L', {{0,2}, {1,3}, {2,2}, {3,3}}}, {'O', {{0,2}, {1,2}, {2,2}, {3,2}}}, {'S', {{0,2}, {1,3}, {2,2}, {3,3}}}, {'Z', {{0,2}, {1,3}, {2,2}, {3,3}}}, {'T', {{0,2}, {1,3}, {2,2}, {3,3}}}, {'*', {{0,1}, {1,1}, {2,1}, {3,1}}} }; Shapes::Shapes(char type) : type{type} {} char Shapes::getType() const noexcept { return type; } vector<pair<int,int>> Shapes::getLayout(int version) { return layouts.find(type)->second.find(version)->second; } vector<vector<bool>> &Shapes::getBinary() { return binaries.find(type)->second; } int Shapes::getHeight(int version) const { return heights.find(type)->second.find(version)->second; }