// Given a seed and a replay trace, show all scoring events for each block. #include #include"state.h" int main(int argc, char **argv) { // Initialize game settings. int seed; if( argc < 3 || sscanf(argv[1], "%d", &seed) != 1 ) { printf("%s \n", *argv); return 1; } // Trace moves. printf("Seed = %d\n", seed); const BlockList block_list = GenerateBlockList(seed); int score = 0; int input_i = 2; int input_j = 0; Grid grid; for(int i = 0; i < static_cast(block_list.size()); i++) { printf("Move %d of %d: ", i + 1, static_cast(block_list.size())); // Generate block and verify that we haven't reached a premature end. PendingBlock block(block_list[i]); if( block.y <= static_cast(grid[block.x].size()) && grid[block.x][block.y] != kEmpty ) { puts("Game over"); break; } // Collect moves from input. std::string input_keys; while( input_i < argc ) { const char m = argv[input_i][input_j++]; if( m == '\0' ) { input_i++; input_j = 0; continue; } input_keys.push_back(m); if( m == 'j' ) break; } printf("%s ->", input_keys.c_str()); if( input_keys.empty() || input_keys.back() != 'j' ) { puts(" Premature end of input"); break; } // Apply moves. ApplyMoves(grid, input_keys, &block); const std::vector score_steps = TraceDropBlock(block, &grid); for(int s : score_steps) { printf(" +%d", s); score += s; } if( static_cast(score_steps.size()) > 1 ) printf(" (%d chain)", static_cast(score_steps.size() - 1)); bool all_clear = true; for(const auto &column : grid) { if( !column.empty() ) { all_clear = false; break; } } if( all_clear ) printf(" (all clear)"); printf(" -> %d\n", score); } printf("Final score = %d\n", score); return 0; }