-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement Battleship game #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ee4fae9 to
ed9a2b4
Compare
|
This is great, thank you! I willy likely use this game as well :) Maybe I can say something about the last points:
It is not "important", as in the game will work completely fine without it. It would be however useful for algorithms that make use of learning (neural networks).
You can first register it as general sum and "override" the type, like here: https://github.com/deepmind/open_spiel/blob/master/open_spiel/game_transforms/turn_based_simultaneous_game.cc#L267
Observers are a recent addition to the library. Basically we ended up with a bunch of methods like (InformationState|Observation|PublicObservation)(String|Tensor) with respective tensor layouts, etc., and the API for State started to be cluttered. The plan is that these existing methods will become deprecated, once all games implement their own observers. If you do not want to implement tensor observations (which I would recommend however), you can skip it, and just implement the current string variant you already have for a BattleShipObserver. You can check out KuhnObserver / LeducObserver / GoofspielObserver (that one is still a PR, but should be merged soon). The usage of observer allows us to parametrize the observations based on the information revealed, and even use custom observer parameters. Example of leduc poker. |
|
Ah, this is fantastic, thanks for doing this. I have some research that will use this once it's implemented. I was looking into implementing this myself, so thanks for saving me the work! |
|
Wow, thanks so much for the enthusiasm :-) @michalsustr Thanks for the information about observers, I think I see now. I think it is definitely worthwhile to add the tensor-based representations, though at this point it would make a lot of sense to create an observer to get ahead of the deprecation wave for the non-observer-based methods. I think that for this game in particular it is OK for Thanks for pointing out to an example of how to override the game type, I will add something like that. I think it's important to do that type of override just in case some code down the line checks that the game is zero-sum by only looking into the trait object before doing anything, and would therefore fail on Battleship even when the game is actually zero sum. |
lanctot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you generate a playthrough?
|
Very nice implementation. Generally I like the incremental plan for large code changes, so we can even accept this when you're happy with the basic implementation and you can submit more PRs later. Or if it's easier you can just keep adding to this one. Your call. A few follow-ups:
|
|
Filed #382. Currently blocked on that issue. |
I don't mind adding all the low hanging fruits to this implementation, including some tests. Before marking it as ready, I would also like to make sure that this implementation can reproduce some of the results from [1].
Sounds good! It sounds like adding
If I understood correctly how these work from the doc in |
|
I opened #386 and applied the fix locally to this branch. Right now the basic tests pass. |
|
Tests are now green locally 🎉 The only test that was failing was this It looks like several games are on the same boat so for now I've just added |
|
Yep this is ok for now. To be honest, I don't remember.. @michalsustr can you clarify? |
|
I've implemented On second thought, I think that it would make sense for everybody if At this point the only big task that remains is to write some tests and make sure that the games generated by this implementation match the implementation used in [1]. |
I would have to go through the code more carefully, I might take a look tomorrow. I added a few comments though. What was the error message for the failed test?
I believe the test is fine, it's just that those games are indeed not implementing observations correctly. I didn't have the capacity to fix all the games back then. I think the most common case was that information state / observation was spanning States with different MoveNumbers, because it did not distinguish between encoding observations when the requested player was acting, or the opponent(s) were. |
|
@michalsustr this is the error: By default the board is 2 x 2, and each player has exactly one ship of length 2. The action string If you want to poke around with the implementation, you can clone my EDIT Not sure if it's relevant, but the action indices are "reused" in the implementation. So for example action |
What's the best way to do that? I noticed that |
685b2e3 to
240142c
Compare
There is a script to do it automatically: https://github.com/deepmind/open_spiel/blob/master/open_spiel/scripts/generate_new_playthrough.sh. Just run it with the game string as the argument. |
|
Ok I did several updates to the master branch, you can rebase now. Note that I slightly changed the formatting of the doubles to remove unnecessary trailing zeroes (new function in spiel_utils.cc called FormatDouble). |
|
If you have any remaining FIXMEs in the code, can you change them all to TODO? They break the import :) |
|
Travis failed again on |
Do you think it would make sense to check this for games in general in the |
Yeah I think something is wrong, happened in another PR too. Thanks for flagging, I've opened an issue: #396 |
Hmm.. how could you? Also, we didn't strictly disallow it, so it's not really failing to meet the API standard, more of a convention (but maybe we should document it better). |
Get legal action ids from sampled states, call action to string and check that ids have consistently the same strings. But yeah, maybe it's not such a great idea :) Especially if it is not required for games to do right now. |
Oh yeah I definitely do not want to force state-independent string representations. Many games have game-specific move descriptions (e.g. chess, backgammon) and we use State::ActionToString to turn the opaque action ids into something interpretable and meaningful for that state and game. |
|
@gabrfarina @finbarrtimbers is this good to go? I'd like to import it so we can include it in Monday's update. Seems good AFAICT but it's still showing a change requested. |
|
I'll add dimension tests today to validate the table with game sizes in battleship.h. If everything goes well, this will be ready in a few hours :-) |
|
Lgtm! |
This is really easy, you just need to add the shots info to your ToString (but please keep the nice-looking board!) More detail in my response in the issue above. Edit: This property of ToString is also used in a few other places: in the best response code, and as the default implementation of |
|
Thanks @lanctot . Based on the discussion in #399 I've reverted the old implementation of So, I'm now more confident that things are in a good shape. Marking as ready for review again. |
@lanctot The change request was created by you a while ago, but I've since resolved it so I think you can go ahead and remove it if it all looks good to you? :-) |
Oops, yes there has been a lot of turnaround and comments. I'm importing it now. Thanks again, this PR was useful to us in many ways. |
My pleasure, this has been a fun PR, and it was great to see all this enthusiasm :-) I'm happy to stick around to answer any question / request for change. |
|
Hey @gabrfarina, do you have any plans to implement |
|
@finbarrtimbers Thanks for the ping 🙂 I'm a bit swamped with an internal deadline by the end of next week so if you could take a crack at it that would be great, given that I'm also not super familiar with the best practices around that method (will it just be one-hot encoding for each turn? Or something more compact?). If that helps, I'm definitely happy to stick around to help / answer any question you might have! Also, I will cut out a few hours to port over the Sheriff game generator soon... |
This draft pull request tracks progress on the implementation of the Battleship game. One of the goals of this implementation is to be able to exactly match the game generator that was used to generate game instances for some recent papers on extensive-form correlated equilibria. This particular version of the game was introduced in here.
Things done:
TestSerializeDeserializefails on integer parameters that represent doubles (DeserializeGamefails on doubleGameParametersthat represent integer values #382 ) Edit: opened Force a point when serializing a double game param #386ObservationImplementEdit: commentInformationStateTensorToStringto be the currentToPrettyStringInformationStateTensoris important (so far, onlyInformationStateStringis implemented)loss_multiplierparameter is== 1.0. Is this important?The pull request is pretty big, and given that build is green, I think it would make sense to have a preliminary review to see if everything is on the right track. It would also be great if one of the maintainers could help shed some light on my last three things above.
r? @lanctot