// Given a seed, find a reasonably good set of moves for it. #include #include"ai.h" #include"state.h" int main(int argc, char **argv) { // Initialize game settings. int seed; if( argc != 2 || sscanf(argv[1], "%d", &seed) != 1 ) { printf("%s \n", *argv); return 1; } printf("Seed = %d\n", seed); const BlockList block_list = GenerateBlockList(seed); puts("Blocks ="); DumpBlockList(block_list); // Run solver. Grid grid; std::string move_history; int score = 0; for(int i = 0; i < static_cast(block_list.size()); i++) { DumpGrid(grid); // Generate block, and make sure 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 ) { printf("Game over at move %d\n", i + 1); break; } printf("%s Move %d of %d, score = %d\n" "%s\n", GetTile(block.color[1]), i + 1, static_cast(block_list.size()), score, GetTile(block.color[0])); const std::string move = GenerateMove(grid, block_list, i); if( move.empty() || move.back() != PendingBlock::kDrop ) { printf("Unexpected move: %s\n", move.c_str()); return 1; } // Apply moves. ApplyMoves(grid, move, &block); score += DropBlock(block, &grid); move_history.append(move); } // Dump final grid state and output list of generated moves. DumpGrid(grid); printf("\nFinal score = %d\nMoves =\n%s\n", score, move_history.c_str()); return 0; }