// All state management functions live here. // // These must match arle0.b implementation. #ifndef STATE_H_ #define STATE_H_ #include #include #include #include #include constexpr int kWidth = 6; constexpr int kHeight = 12; // (top color, bottom color) using Color = int8_t; using Block = std::array; // Syntactic sugar for marking empty cells. constexpr Color kEmpty = -1; // List of blocks. using BlockList = std::vector; // List of columns. using Grid = std::array, kWidth>; // List of (x, y) coordinates. using Cluster = std::vector>; // List of clusters. using ClusterList = std::vector; struct PendingBlock { // Allowed movements. static constexpr char kLeft = 'h'; static constexpr char kRight = 'l'; static constexpr char kRotate = 'k'; static constexpr char kDrop = 'j'; explicit PendingBlock(const Block &c) : color(c) {} // Block state. int x = (kWidth - 1) / 2; int y = kHeight - 1; int orientation = 0; Block color; }; // Access palette for a single tile const char *GetTile(Color c); // Print block list to stdout. void DumpBlockList(const BlockList &block_list); // Print grid state to stdout. void DumpGrid(const Grid &grid); // Generate list of blocks for a particular seed. BlockList GenerateBlockList(int seed); // Find all connected clusters in grid. ClusterList MarkClusters(const Grid &grid); // Apply a series of left/right/rotate movements to pending block. // Drop block commands are ignored. void ApplyMoves(const Grid &grid, const std::string &moves, PendingBlock *block); // Drop block onto grid, apply chains, and return change in score. int DropBlock(const PendingBlock &block, Grid *grid); // Drop block onto grid, apply chains, and return changes after each // chain. If only one element is returned, it means dropping this // block only scored the minimal one point for dropping it. // Otherwise, each additional array element records the score after // that many chains have been cleared. std::vector TraceDropBlock(const PendingBlock &block, Grid *grid); #endif // STATE_H_