game logic extracted from the UI