Add input buffering, auto-start, and gameplay improvements

Input buffer system:
- Added 3-slot direction input buffer to handle rapid key presses
- Buffer ignores duplicate inputs (same key pressed multiple times)
- Opposite direction replaces last buffered input (e.g., LEFT→RIGHT replaces LEFT)
- Buffer overflow replaces last slot when full
- Multi-segment snakes skip invalid 180° turns when consuming buffer
- Head-only snakes (length=1) can turn 180° for flexibility

Gameplay improvements:
- Desktop client auto-starts game on connect (no SPACE needed)
- Field populates with 3 apples when no players connected
- HTTP server now binds to 0.0.0.0 for network access (matches game server)

Testing:
- Added 7 new tests for input buffer functionality
- Added test for zero-player apple spawning
- All 19 tests passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vladyslav Doloman
2025-10-04 19:11:20 +03:00
parent 97d6df1896
commit ce492b0dc2
5 changed files with 167 additions and 15 deletions

View File

@@ -80,8 +80,7 @@ async def main() -> None:
web_dir = Path(args.web_dir)
if web_dir.exists():
# Use same host as game server for HTTP
http_host = args.host if args.host != "0.0.0.0" else "localhost"
http_server = HTTPServer(web_dir, args.http_port, http_host)
http_server = HTTPServer(web_dir, args.http_port, args.host)
await http_server.start()
else:
print(f"Warning: Web directory '{web_dir}' not found. HTTP server disabled.")