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 ;)
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.
http://www.datagenetics.com/blog/december32011/