diff options
author | scratko <m@scratko.xyz> | 2024-11-16 14:59:17 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2024-11-16 21:26:41 +0300 |
commit | 22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4 (patch) | |
tree | 8c86594705005c380560e87b68b01993fc1928ef /puzzle.cpp | |
parent | 060fe2ebc6f5ed26c445f95b3cd6c9ee5bc24e28 (diff) | |
download | picture-puzzle-22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4.tar.gz picture-puzzle-22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4.tar.bz2 picture-puzzle-22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4.zip |
Added A* solution algorithm
Diffstat (limited to 'puzzle.cpp')
-rw-r--r-- | puzzle.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -7,6 +7,8 @@ #include <utility> #include <memory> +GameParams* GameParams::instance = nullptr; + void GameParams::CalculateStandardPuzzlePos() { coordinates tmp; @@ -14,8 +16,6 @@ void GameParams::CalculateStandardPuzzlePos() int i, j, k = 0; for(i = 0; i < puzzles_per_side; ++i) for(j = 0; j < puzzles_per_side; ++j, ++k) { - if(i == puzzles_per_side-1 && j == puzzles_per_side-1) - break; tmp.x = i * (puzzle_size + spacing) + spacing; tmp.y = j * (puzzle_size + spacing) + spacing + 30; standard_puzzle_coordinates[k] = tmp; @@ -49,15 +49,22 @@ void GameParams::NextUntestedPuzzles() */ win->begin(); for(int i = 0; i < puzzle_pieces; ++i) { - tmp_puzzle = - std::unique_ptr<Puzzle>(new Puzzle(standard_puzzle_coordinates[i].x, - standard_puzzle_coordinates[i].y)); idx_random_puzzle = 0 + (int)((double)puzzle_pieces * rand()/(RAND_MAX + 1.0)); while(!free_puzzles[idx_random_puzzle]) idx_random_puzzle = 0 + (int)((double)puzzle_pieces * rand()/(RAND_MAX + 1.0)); free_puzzles[idx_random_puzzle] = 0; + /* empty puzzle */ + if(idx_random_puzzle == puzzle_pieces-1) { + SetXYEmptyBox(standard_puzzle_coordinates[i].x, + standard_puzzle_coordinates[i].y); + continue; + } + /* common puzzle */ + tmp_puzzle = + std::unique_ptr<Puzzle>(new Puzzle(standard_puzzle_coordinates[i].x, + standard_puzzle_coordinates[i].y)); tmp_puzzle->sequence_number = idx_random_puzzle; find_path_to_picture(tmp_puzzle->path, tmp_puzzle->sequence_number); Fl_JPEG_Image *img = new Fl_JPEG_Image(tmp_puzzle->path.c_str()); |