1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 23:17:46 +00:00

Minesweeper: Use a faster method to generate game field

The existing method was simply using a "randomly generate until it fits
our criteria" method to generate a game field. While this worked OK in
most cases, the run time was increasing seriously in boards whose
mine count / board size ratio was too big.

The new approach simply generates every possible mine location, shuffles
the array and picks its head. This uses more memory (shouldn't be a big
deal since minesweeper boards are generally miniscule) but runs much
quicker. The generation could still use some improvement (regarding
error handling), though :^)
This commit is contained in:
Arda Cinar 2022-12-08 17:44:19 +03:00 committed by Sam Atkins
parent 1cdd3bb74f
commit 5562ef6cc5
2 changed files with 49 additions and 13 deletions

View file

@ -105,6 +105,7 @@ public:
void set_single_chording(bool new_val);
void reset();
void generate_field(size_t start_row, size_t start_column);
private:
Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_button, Function<void(Gfx::IntSize)> on_size_changed);