Sign In Register

How can we help you today?

Start a new topic
Answered

Server-side bots

Hi everyone!


I'm new and I'm creating a simple game with words - quiz. Two users will compete guess the hidden word and allow fewer mistakes. At the initial stage, there is a problem that the game have not an even number of users, for example - 5. It is formed 2 pairs players and one user will not be able to play and can wait for your pair for a long time. 


How to avoid it? Is it possible to create server-side bots? Is there a code examples of this?


Best Answer

Hi Astraport,


Server side bots are certainly doable on the platform, in fact we'd recommend you code them in Cloud Code so that any tweaks that need to be made can happen without you having to re-upload your game to apple or google etc.


Unfortunately though there is no one solution which works for all. To get you started though, I've come up with a few ideas.


Seeing as the challenges require actual accounts to run properly, I'd create an account for only the bot to use. This account can partake in as many challenges as required at the same time so I wouldn't worry about needing more than one. The trick is that you need to know when to match a player with the bot account, if you can't form a pair for example with the challenge set to "PUBLIC" you could use SendRequestAs call JoinChallengeRequest and supply the bot account's id. This will send the request on the bot's behalf and that account will now be a part of the challenge.


Once all players have been matched you can use StartChallenge to force the challenge into a playable state. The tricky part is the "AI" which will govern the bot. While cant I really help you on this part (not my area of expertise) I can tell you where it would be implemented and roughly how to go about accomplishing it.


So when you want a player to take a turn, you use LogChallengeEvent and a custom event you have defined in the Configurator. This is where you usually store what values/score/times a player has achieved to the scriptData of the challengeInstance and execute the logic to govern who has won. This is also the ideal place to store and execute the logic which governs the bot.


You would check if the player who is logging the event is the player who has been matched with the bot, then store said player's scores/words/times, then before calculating who won that round run a separate function to take the bot's turn(calculating what word they would choose etc), again, using SendRequestAs to LogChallengeEvent to store the bot's choice to the challengeInstances scriptData and also taking it's turn and calculating who wins.


Hopefully that sheds some light on this complex question,

Shane


Thanks for the idea Oisin. I guess this works.

I was in the thought of not having custom script data to sync with existing implementation. However, i can do this simple trick to work with single bot name.

Hi Ayyappa,


You could use a single GameSparks account for your bot.

You could then check if the player has been matched with the botAccount and set it's name randomly in the challenge scriptData.
This way the bot's name stays the same for the challenge and looks like many different users across multiple challenges.

No need to rack up an inaccurate an MAU calculation.

Thanks

Oisin.

I was trying for system where if any matching fails, it will create a bot and continue the random match. I want the bot to be unique lets say with diff name and pic every time user creates a random match.

If we create multiple bots accounts on server side, are they considered in calculating MAU per month?


Mainly is the MAU calculated based on user registrations in GameSparks?


Thanks,

Ayyappa.

Adding to that, Another possibility can be


Create a Module in cloud code and name it TakeAITurn. Here is the place where your AI code resides.

When ever you get a request for the turn of AI to play, Call this module from the other response of LogChallengeEvent cloud code to trigger the next action of the AI bot.


I'm not sure on syntax about how to call modules from other cloud script at the moment but this direction should help to decide about the possibilities.

Hi Shane!

Thank you for your ideas. I will think.

Answer

Hi Astraport,


Server side bots are certainly doable on the platform, in fact we'd recommend you code them in Cloud Code so that any tweaks that need to be made can happen without you having to re-upload your game to apple or google etc.


Unfortunately though there is no one solution which works for all. To get you started though, I've come up with a few ideas.


Seeing as the challenges require actual accounts to run properly, I'd create an account for only the bot to use. This account can partake in as many challenges as required at the same time so I wouldn't worry about needing more than one. The trick is that you need to know when to match a player with the bot account, if you can't form a pair for example with the challenge set to "PUBLIC" you could use SendRequestAs call JoinChallengeRequest and supply the bot account's id. This will send the request on the bot's behalf and that account will now be a part of the challenge.


Once all players have been matched you can use StartChallenge to force the challenge into a playable state. The tricky part is the "AI" which will govern the bot. While cant I really help you on this part (not my area of expertise) I can tell you where it would be implemented and roughly how to go about accomplishing it.


So when you want a player to take a turn, you use LogChallengeEvent and a custom event you have defined in the Configurator. This is where you usually store what values/score/times a player has achieved to the scriptData of the challengeInstance and execute the logic to govern who has won. This is also the ideal place to store and execute the logic which governs the bot.


You would check if the player who is logging the event is the player who has been matched with the bot, then store said player's scores/words/times, then before calculating who won that round run a separate function to take the bot's turn(calculating what word they would choose etc), again, using SendRequestAs to LogChallengeEvent to store the bot's choice to the challengeInstances scriptData and also taking it's turn and calculating who wins.


Hopefully that sheds some light on this complex question,

Shane

I still did nothing. Only plan project architecture. And therefore asked.

Can you  present more on your structure once? You are doing this by challenges and cloud code or just events and cloud code?

Login to post a comment