Skip to content

GUI for the Problems

Ostap Trush edited this page Jun 2, 2021 · 1 revision

Library choice

For the GUI pygame library was chosen due to prior experience of using this library.

Pygame is a good choice for simple visuals due to it's power and ease of use.

How it was written

As you can see in the project, each problem with visuals has a main.py file, which stores the Game/Visualization class. This is a simple pre-written body from my previous game projects and it suits here perfectly.

Generally in pygame the screen has to be updated every call of the update() function in my Game/Visualization body. However, because the solve() functions in every algorithm work as a whole, I couldn't call update() every step of the algorithm. That is why I had to add a new parameter vizual=None to every problem's class. The whole Game/Visualization class is passed to the visual variable and if it is there, in the solve function we have:

if self.vizual:
   update_screen()

which makes the GUI update on every important step.

This structure allows each algorithm to be used without the GUI for various problems where GUI is not needed.

Clone this wiki locally