Added the main game logic function (redacted)