Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Play Battleships on PostgreSQL (github.com/firemoon777)
96 points by firemoon777 on Sept 22, 2020 | hide | past | favorite | 13 comments



Battleship AI is pretty interesting actually. Board and ship geometry can be exploited to create an edge over random strategies. With a slight chance for "the perfect game" completed in 17 hits, no misses. A pure SQL implementation would be formidable to say the least ;)

http://www.datagenetics.com/blog/december32011/


This is one of the coolest things I've read this year, thanks for sharing!


Love the method used for I/O, super clever.

My long running pet project is a multi-player space battle game played entirely via SQL inside postgres https://schemaverse.com/


Ha! I attempted this a while back but never came up with a good solution for handling user inputs so it was just the computer playing itself...

https://github.com/sidpalas/battleship-sql

This is next level!


Looks like they are getting the user input from the postgres log: https://github.com/Firemoon777/sql-battleships/blob/master/k...


Yeah -- Using the second session for grabbing inputs is clever!



Can someone explain how this works?

I followed the instructions and it asked to me to open two psql processes and call an instruction from the other which I did.

> postgres=# INFO: Let's connect keyboard. Open another psql process and enter "K1GSFJF0;"


K1GSFJF0 is a random password generated here:

https://github.com/Firemoon777/sql-battleships/blob/87770216...

It then queries every second looking for a session in the postgres_log for a query that matches that password and stores the session id into a table named ks_id.

Once it knows the session_id it can then listen for any input associated to that session.


Also space invaders in sqlalchemy (actually a decent primer) https://github.com/sqlalchemy/sqlalchemy/blob/master/example...


You sunk my battleship


Nice one !


Why was I downvoted?




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: