Reputation: 5664
My current android application uses Google play games services as a turn based game. It's published and working OK, however I would like to add the ability for players to play against a "computer" opponent as apposed to a "real" person. Is this possible? Is this "legal"? From searching the Google play services docs and code it doesn't appear to be possible. Dies any one know different?
Upvotes: 3
Views: 960
Reputation: 10327
I'm going to answer the more general question of adding a computer player to a match with one or more human players. Fundamentally, it doesn't matter if there's only one human player or more than one. Play Games does impose the restriction that there must be at least 2 (human) players in all matches. I'll come back to this problem later.
Yes, it is possible. You need to have a clean separation between your game logic and the Play Games API. Your code should be structured such that you could easily create an alternative UI without touching your core game classes (for example, imagine creating a command line interface to your game; it should be easy). It's also important to adjust your thinking. A player in your game doesn't have to map one-to-one with a participant in the Play Games service. A turn in your game doesn't have to map one-to-one with a turn in the Play Games service.
For the layer the does interact with the Play Games API, only concern yourself with the human players. Every time you call takeTurn()
, you should be giving it the participant ID of a human player. It will never be the computer's turn according to Play Games. Also remember that it's legal to take a turn and set the next participant ID back to the same player that just took the turn (this is useful in several situations).
Obviously, the computer gets to take turns in your game, so how do you reconcile that with the fact that it's never their turn according to Play Games? By realizing that the two notions of turns are separate concepts. Here's an example:
The human player creates a game and it's their turn (according to your game state and according to Play Games). Every time they perform a sub-action within their turn, you call takeTurn()
and provide the human player's participation ID. Once their turn in the game is complete, you call takeTurn()
again, but need to provide the participant ID of the next player. If the next player is a human, just provide their ID. If the next player is a computer, provide the human player's ID again. Then immediately have the device play the computer player's turn. Notice that Play Games thinks it's the human's turn, but your game thinks it's the computer's turn. Once finished, you need to call takeTurn()
again. Just like last time, if the next player is a human, use their ID. If the next player is another computer, use the last human player's ID (the human player that's signed into the device that's taking the computers' turns on their behalf).
Put another way, the human's device is responsible for the human's turn as well as all the turns of all the computer players that come after them (until another human player is reached). In games with one human and one or more computers, it's always the human's turn according to Play Games. According to your game logic, the turns alternate like normal (it doesn't matter that some players are computer controlled).
Now, back to the problem of Play Games requiring at least two players. You may be able to sidestep the problem by adding an auto-match player. Because you never actually set the next participant ID to null
(which is what you use for the auto-match player's participant ID), no other humans will actually join. I'm pretty sure you can completely finish a match without ever causing the auto-match players to join (you'll have to experiment). This may or may not be allowed, you'll have to research that as well. Even if it's not, at least you can have computer controlled players in games with at least two humans.
Upvotes: 1
Reputation: 2427
Apologies if my answer is too simple, but if you want your users to play against the computer you should not use Google Play Services for that.
Your game logic should not know about Google Play Services, but about opponents and their moves. That way it would not make a difference if these moves came from Google Play Services or were generated on the client.
Upvotes: 3