Readit News logoReadit News
drekipus · 4 years ago
This reminds me of a project idea I had...

I was thinking of setting up a small server that can emulate some up multiplayer games, such as battleship, connect 4, even perhaps monopoly.

Then people submit code, or connect their machines to it, and it becomes "battle of the algorithms".

You'd have to register an algorithm name / version, and compete a few times against other algorithms, to be placed on the leaderboard for that game*.

Each game could just be stored as plaintext, so it would be easy to replay each move and visualise it on the website.

I haven't yet begun creating it, but it'd be great to see how your algorithm would work against another; You'd also have to consider how to place your ships as well. (probably sticking them in the corners could be easily dealt with, right?

Looking at this algorithm it seems like it's pretty optimal, I don't think there's much else that could be done with Battleships. Playing with other human players would be a different outcome..

* I would only really expect algorithms work per game, not across games.

hntcz · 4 years ago
About 20 years ago when I was a teenager Microsoft did this in my country with rock-paper-scissors. XML-RPC-based web services were new at the time and they promoted it this way. You hosted your own web service and they called it to play, I think 10 or 20 games against each opponent in your group. Obviously you can't get an edge against someone playing completely randomly but they placed a bunch of simpler bots in the groups that you could detect (e.g, always playing a pattern). Group winners made it to the final. It was awesome, thanks for reminding me of that memory!
mormegil · 4 years ago
> you can't get an edge against someone playing completely randomly

Sure, random choice is not only a Nash equilibrium, it even has a fixed expected value without regard to the other player's strategy, _but_ that is only in the basic two-player game. If you have a tournament and some players use other strategies, you can get better score against them by a non-random strategy, meaning you can beat the random strategy in the global tournament. But it also means someone can defeat you! Which means RPS tournaments are interesting even if the game seemed almost trivial!

evil-olive · 4 years ago
not exactly the same because it's not playing an established human vs. human game such as Battleship, but Core War [0] from 1984 is the earliest example of this idea that I'm aware of.

> At the beginning of a game, each battle program is loaded into memory at a random location, after which each program executes one instruction in turn. The goal of the game is to cause the processes of opposing programs to terminate (which happens if they execute an invalid instruction), leaving the victorious program in sole possession of the machine.

Battlecode [1] from MIT seems to be along similar lines as well

0: https://en.wikipedia.org/wiki/Core_War

1: https://battlecode.org/

jhbadger · 4 years ago
Corewar may be the first example of the game in its purest form, but earlier than that was Robotwar (first on the PLATO system in the 1970s then on the Apple ][ in 1981) which involved players writing simple programs to control robots in a BASIC like language. You could either compete against a friend or compete against a series of programs included with the game.

https://en.wikipedia.org/wiki/RobotWar

pr0gramm · 4 years ago
We (http://pr0gramm.com) had a multiplayer battleship[1] for our april's fools two days ago. All users were divided into a red and blue team and then voted for the next shot. For our april's fools in 2018 we did the same with connect 4[2].

The games itself are not that interesting (altough OP certainly disagrees), but the social dynamics, shitposts and memes that came out of this were fascinating.

[1] https://vid.pr0gramm.com/2022/04/02/e9c168457179b582.mp4

[2] https://vid.pr0gramm.com/2018/04/01/fa0b52dacd80da53.mp4

gusgus01 · 4 years ago
StarCraft 2 has a pretty active version of this! I've always wanted to play around with it but I lost a lot of steam when I wanted to upstream some changes to the various libraries involved and my employer vetoed the idea.

https://sc2ai.net/

Aeolun · 4 years ago
Your employer vetoed the idea?How are they related to that?
aleksiy123 · 4 years ago
There is a snake version of this called Battlesnake https://play.battlesnake.com/

Did it while I was in university. I even won one of the categories one year.

Carbocarde · 4 years ago
I actually started working on that with some of my friends, here's a link: https://github.com/Carbocarde/games

We were planning on eventually making it into a website and doing a leaderboard.

The program works by having agents that write to stdout and a game that reads from stdin. That way we can kinda avoid some of the security issues around running untrusted code.

Still has a lot of work to be done before it's ready to simulate battleship :)

dawidloubser · 4 years ago
One of the first incantations of this idea that I encountered, when I had just started working at my first corporate job back in the day, was Robocode ( https://robocode.sourceforge.io/ ) - it was great fun, and I see it's still going.
flir · 4 years ago
I think there's only two possible outcomes - either a best solution emerges, or a rock-paper-scissors scenario emerges with a number of solutions.

If there's another outcome I'm missing, I'd like to hear about it (stalemate?)

bckr · 4 years ago
Might want to chat with this user: https://news.ycombinator.com/user?id=mathgladiator

Who has a SaaS prototype for creating board game servers

Delgan · 4 years ago
It reminds me of the multiplayer section from CodinGame website: https://www.codingame.com/multiplayer/bot-programming

Although there is no specific implementation for Battleship, but I believe that some users sometimes have the possibility to create and submit their own games.

kwhitefoot · 4 years ago
Reminds me of Robert Axelrod's computer tournament, won by Anatol Rapoport's Tit for Tat. See https://lps.library.cmu.edu/NCMR/article/351/galley/355/view...
kayamon · 4 years ago
I wanna say the Metropolis-Hastings algorithm is probably the best way to explore any probability distribution like this. The core algorithm is pretty similar to battleships -- pick a random point from a map, then explore neighbouring points, use the difference between predicted and measured results to update the map, and when bored do random restarts.
onionisafruit · 4 years ago
I worked on something like that for a while that I never finished. One of the stumbling blocks was executing untrusted code. I settled on having players either connect via websocket or receiving webhooks and having to respond in a given time frame.
tomcam · 4 years ago
I don’t understand the executing of entrusted code part. If the instructions are plain text, how could it even be a problem? The instruction FIRE(5,7) isn’t going to turn into a zero day exploit, right?
kevinwang · 4 years ago
To add on to the list of bot competitions: there's a really great one with a nice interface for a version of blind chess: https://rbc.jhuapl.edu/
debbiedowner · 4 years ago
I participated in a "ruby fight club" like this a few years ago hosted by grouper: https://github.com/Grouper/battleship
captn3m0 · 4 years ago
Want to build the same, but using boardgame.io. Search for Gym here: https://github.com/captn3m0/ideas
dpflug · 4 years ago
There's some effort in that direction here: http://ggp.stanford.edu/
IIAOPSW · 4 years ago
I think you are teetering on the edge of the rabbit hole of a domain specific language for the representation of board game rules. Unless you want to write a new emulator for each new multiplayer game, that's the hole you'll dive down. But once down there, you'll realize you're basically making a programming language with a board game theme, as any language sophisticated enough to represent most board games is destined to become a Turing tarpit. At that point the project has become self defeating, as you are now coding each new game in a programming language you invented to avoid coding each new game.
gnopgnip · 4 years ago
Screeps is similar

Dead Comment

cmeacham98 · 4 years ago
A key point of this seems to be assuming that the other players place their ships at random, which obviously isn't true when humans are playing. For example, "hiding" a ship on the edge is super common behavior from people I've played against, despite the author's heatmap suggesting edges are one of the _least_ likely places.
IIAOPSW · 4 years ago
The discrepancy is probably explainable by game theory. There is some set of strategies, defined by the distribution you use to place your own ships and the distribution for picking guesses at enemy positions. If we start from the naive assumption of a uniform distribution for both, this strategy is exploitable using exactly the heatmap from the article. So next we can iterate, assume that the opposing player is using the heatmap from the article, and generate a new distribution of ship placements designed to be unlikely to be picked. From there we get a new heatmap, which can be iterated again in the same manner until eventual reaching convergence with the Nash Eq. I wonder what the Nash Eq of Battleship is and how similar it is to observed real player strategies.
cmeacham98 · 4 years ago
For placement, I am fairly confident the best possible strategy will be one in which every tile has a uniform chance of being chosen for a ship. Any other strategy will result in the opponent being able to gain an advantage by preferring certain tiles when firing, and thus the equilibrium and best strategy will be one where that cannot happen.

However, I am also fairly certain that human players, especially those playing a casual iMessage battleships game, do a very bad job of following this strategy.

kevinwang · 4 years ago
To be nitpicky, the process you described won't necessarily reach a Nash, as it may cycle. But if each player best-responds against the average of all opponent strategies so far, then said average strategies will converge to a Nash (fictitious play).
driscoll42 · 4 years ago
Agreed, while I understand he used random maps to generate the heatmap. Using the distributions from actual games would likely be far more useful.
SV_BubbleTime · 4 years ago
I look forward to the Recaptcha “Play this game of Battleship”.
greenbay20 · 4 years ago
Would be interesting to analyze what ship-placement strategy/distribution makes the opponent indifferent in terms of which cell to shot.
colordrops · 4 years ago
It's similar to rock-paper-scissors in this respect. Humans play in patterns rather than randomly, so you can actually win if you can predict the pattern.
Etherlord87 · 4 years ago
Also when you destroy a ship hidden in a corner, you only get to exclude half of usual surrounding tiles (since ships can't connect). So long ships of lengths 4, and 3 are best to be placed on edges, because they're going to be hit sooner rather than later anyway, while small ships can try dodge late-game shots.

Edit: just realized a lot of commenters here played a version where the ships can touch. My reasoning above won't apply in such case.

YossarianFrPrez · 4 years ago
This reminds me that Dr. Todd Gureckis, a researcher at NYU, has some work looking at inferring which hypothesis-testing strategies people are using as they play (a version of) battleship. The three strategies he and his colleagues identify are a 'naive' or 'positive-testing strategy', an 'label entropy reduction strategy' and an 'information gain' strategy.

The work is described in "A preference for the unpredictable over the informative during self-directed learning." It is an interesting paper. If you are interested in this post, you might like it:

https://escholarship.org/content/qt0059t11p/qt0059t11p.pdf

kqr · 4 years ago
This was interesting and highlighted some distinctions between strategies that I hadn't explicitly considered before. Thanks for sharing!
schoen · 4 years ago
Is the "no ships adjacent to other ships" rule part of the original commercial Battleship game? When I played it with my family, we didn't follow that rule, and so there was considerable scope for ambiguity about whether nearby hits were part of the same ship or not.
whitexn--g28h · 4 years ago
This is the commercial version I remember which has less ships, a smaller board and no adjacency rules https://www.hasbro.com/common/instruct/battleship.pdf
jtokoph · 4 years ago
I love how the game came without the labels pre-attached. Gone are the days of "some assembly required".
whiskyant · 4 years ago
Nope, don't think any commercial version has that rule. Seems like a house rule or a misunderstanding of the official ruleset.
0xFF69B4 · 4 years ago
European versions have this rule [1]. I wasn't aware that the US version allowed adjacent ship placement until I bought a commercial version for my kid last Christmas and started looking into strategies.

1: https://de.wikipedia.org/wiki/Schiffe_versenken#Vorbereitung

efitz · 4 years ago
There was no “no adjacency” rule in the official board game. This jumped out at me when I read the article; it is a significant change.

Also, the board game had a different ship length distribution; the board game is biased towards fewer, longer ships:

1x Len 5

1x Len 4

2x Len 3

1x Len 2

The length one ships in the article are weird, especially with the no adjacency rule they quickly rule out large sections of the board.

wst_ · 4 years ago
It's not weird. I played article version my whole life and never knew different ones existed. It could help you if you're lucky enough to hit it. But it also can help you if this is your last ship on the board, which happens quite often actually.
NaturalPhallacy · 4 years ago
I don't know why it would be a rule but the one time I tried it, I got absolutely rekt and never did it again.

May have been because I put ALL my ships in one big blob, but typically people will fire at adjacent hits until they don't get any, so I think it's a terrible strategy anyway.

Gare · 4 years ago
MB version appears to allow it, and I recall playing it like you did.
WalterBright · 4 years ago
Stratego is another simple, deterministic game, but picking a successful strategy is far from simple.

I played it a lot as a kid, and came up with a strategy that beat everyone I played against 100%. I never let on what it was, to their frustration :-)

Risk was good, but I disliked the randomness of it. There wasn't a whole lot of strategy to it, being way too much dependent on the roll of the dice.

HideousKojima · 4 years ago
Hiding the flag near the frontlines is my Stratego strategy, no one ever suspects it
ghaff · 4 years ago
Not the first time maybe. But if you play with the same people they obviously learn it and it’s probably not a great location for a variety of other reasons.
nosefrog · 4 years ago
What's your strategy? :-)
WalterBright · 4 years ago
I'm not that easy!
cochleari_major · 4 years ago
Reminds me of a fun video about speedrunning a battleship minigame in some Zelda title:

https://www.youtube.com/watch?v=1hs451PfFzQ

NaturalPhallacy · 4 years ago
This was way more interesting than the OP lol

Thanks!

dmurray · 4 years ago
> With this heatmap, the center 4 squares are the best place for your first shot

Surely the right strategy is some kind of mixed strategy. If you always go for the centre squares on your first shot, your opponent can exploit this by not placing ships there.

Carbocarde · 4 years ago
Definitely in a real game against a human you would want to adjust the weighting based on historical game data. When I'm playing games against my friends, I treat the solver like an advisor. So sometimes I ignore what the solver says and instead choose from only edge squares.
WalterBright · 4 years ago
I had good success by firing at the places the opponent's ships weren't at in the last round.

I'd also place my ships in the same places as the previous round.

Deleted Comment

Imnimo · 4 years ago
>Information gain can be combined with the Naive Strategy in order to calculate both the probability of a hit, along with the value that hit would provide (how many possible positions it would eliminate).

Isn't this missing the other half? It seems to me that the information you expect to gain depends on both the information you would gain from a hit AND the information you would gain from a miss, weighted by the likelihood of those outcomes.