Tetris-SQL is a full Tetris implementation in a SQL query, optimized for Postgres and compatible with various terminals. The game loop, enabled by recursive CTEs, updates the game state based on user input and gravity, rendering the game using RAISE NOTICE. Input handling is done through a table, with dblink ensuring real-time updates. Movement, collision detection, and next piece generation are efficiently managed. The game state includes frame, score, board array, and position details. Resource usage is monitored, with CPU usage remaining low. Overall, Tetris-SQL showcases the power and versatility of SQL beyond traditional data querying.
https://github.com/nuno-faria/tetris-sql