Home » Android » Android Play Games: Custom Room Configuration with flexible amount of players

Android Play Games: Custom Room Configuration with flexible amount of players

Posted by: admin May 14, 2020 Leave a comment


I am developing a real time multiplayer game. The game itself is working fine. I am struggling with the Room Configuration. I use google play games as a framework. The game concept is managing an amount of players from 2 up to 7 for a single room. The game is in fashion of a board game. Therefore it is better if many players are connected. Otherwise the game will be boring. I have the possibility to use googles AutoMatchCriteria for a matchmaking:

Bundle autoMatchCriteria = RoomConfig
    .createAutoMatchCriteria(MIN_OPPONENTS, MAX_OPPONENTS, 0);
RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);

If I set MIN_OPPONENTS = 1 and MAX_OPPONENTS = 6 the game will start in most cases with 2 players. In a SO-Thread, a google developer mentioned:

The automatching algorithm doesn’t try very hard to maximize the number of players in the match…

I have the possibility to use MIN_OPPONENTS = 6 and MAX_OPPONENTS = 6 too. With this setup, the game will start only if 7 players are connected to a room. My game provides many game variants and plenty difficulty levels. Therefore I assume that not always 7 players will be available. I need a flexible solution where a game start is always guaranteed.

The same google guy describes a solution using timers: SO-Thread

I do not know where to start with this concept. Where should I start the timer?
Has anyone successfully implemented this concept? It would be very nice if this person can share some code snippet or provide some further explanation with me. Other suggestions are welcome too.

Update 2019: Still looking for a improvement. Pls give hints.

My gradle file contains:

implementation 'com.google.android.gms:play-services-appstate:6.5.87'
implementation 'com.google.android.gms:play-services-games:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-ads:16.0.0'

That’s how I start a multiplayer game:

    void startQuickGame() {
    final int MAX_OPPONENTS = 6;
    int min_opponents = 1;
    Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(min_opponents,
            MAX_OPPONENTS, 0);
    RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);

    Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build());

One hint I found here: Forcefully starting the game after successfully room-creation using Google Play game Service android
They mention some custom timer.

How to&Answers: