How to Create a Computer Opponent in a Turn Google Based Game
My current android app uses google play services as a turn based game. It published and worked fine, however I would like to add the ability of the players to play against a "computer" opponent, since his is a "real" person. Is it possible? Is this "legal"? From the search for documents and programs of Google Play services, this is not possible. Is anyone else dying?
source to share
Sorry if my answer is too simple, but if you want your users to play against the computer, you shouldn't use Google Play Services for that.
Your game logic does not need to know about Google Play services, but about opponents and their actions. So it won't be affected if these steps originated from Google Play Services or were generated on the client.
source to share
I'm going to answer a more general question about adding a computer player to a match with one or more human players. Basically, it doesn't matter if there is only one person or more than one person. Play Games imposes a limitation that all matches must have at least 2 (human) players. I will come back to this issue later.
Yes it is possible. You need to have a clear separation between your game logic and the Play games API. Your code should be structured in such a way that you can easily create an alternative interface without affecting the core game classes (for example, imagine creating a command line interface for your game, it should be easy). It's also important to adjust your thinking. The player in your game does not need to be matched one-to-one with a member of the Play Games service. The twist in your game doesn't have to be a one-to-one relationship with the twist in Play Games.
For the layer it interacts with the games API for games, only care about human players. Every time you call takeTurn()
, you must give it the player's member ID. According to Play Play, there will never be a computer. Also remember that it is legal to turn and set the next participant ID back to the same player who just took the move (this is useful in several situations).
Obviously, the computer takes turns in your game, so how can you come to terms with the fact that it never changes according to Play Games? Realizing that the two concepts of turns are separate concepts. Here's an example:
The human player creates the game, and that in turn (according to your game state and according to the Play Games). Each time they perform a sub-action in turn, you invoke takeTurn()
and specify the id of the player's participation in the person. Once their turn in the game is over, you call again takeTurn()
, but you need to provide the next player's participant ID. If the next player is human, just provide your ID. If the next player is a computer, enter the player ID again. Then immediately turn on the device that is playing the computer. Note that Play Games thinks this is a human turn, but your game thinks that the computer is turned. After completion, you need to call againtakeTurn()
... Just like last time, if the next player is human, use your ID. If the next player is another computer, use the last player ID (the human player who signed up to the device that includes computers on their behalf).
In other words, the human device is responsible for the human turn, as well as for all the turns of all computer players that come after them (until another person reaches). In games with one person and one or more computers, he always turns into a person according to Play Games. According to your game logic, the turns are rotated as usual (it doesn't matter if some players are controlled by the computer).
Now back to the Play Games issue requiring at least two players. You can avoid the problem by adding an answering machine. Since you've never set the next member ID null
(which is what you use for the player's auto-negotiation member ID), no other people will actually join. I'm sure you can completely end the match without forcing them to join the answering machines (you'll have to experiment). This may or may not be allowed, you will have to investigate this as well. Even if it doesn't, at least you can have computer controlled players playing games with at least two people.
source to share