From 22d4fdabf17aebebfcb73c7d86b5bbc81b6530f4 Mon Sep 17 00:00:00 2001 From: scratko Date: Sat, 16 Nov 2024 14:59:17 +0300 Subject: Added A* solution algorithm --- puzzle.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'puzzle.cpp') diff --git a/puzzle.cpp b/puzzle.cpp index a42be91..1addc73 100644 --- a/puzzle.cpp +++ b/puzzle.cpp @@ -7,6 +7,8 @@ #include #include +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(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(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()); -- cgit v1.2.3