title: Android Play Games: Custom Room Configuration with flexible amount of players
body: <p>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:</p>
  
  <pre><code>final int MIN_OPPONENTS = 1, MAX_OPPONENTS = 6;
  Bundle autoMatchCriteria = RoomConfig
      .createAutoMatchCriteria(MIN_OPPONENTS, MAX_OPPONENTS, 0);
  RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
  ....
  </code></pre>
  
  <p>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: </p>
  
  <blockquote>
    <p>The automatching algorithm doesn't try very hard to maximize the number of players in the match...</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>The same google guy describes a solution using timers: <a href="https://stackoverflow.com/a/16802177/4565322">SO-Thread</a></p>
  
  <p>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. <strong>Other suggestions are welcome too.</strong></p>
  
  <p><strong>Update 2019: Still looking for a improvement. Pls give hints.</strong></p>
  
  <p>My gradle file contains:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>That's how I start a multiplayer game:</p>
  
  <pre><code>    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);
      rtmConfigBuilder.setMessageReceivedListener(this);
      rtmConfigBuilder.setRoomStatusUpdateListener(this);
      rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
      rtmConfigBuilder.setVariant(variant);
      switchToScreen(R.id.mpGamescreen_wait);
      keepScreenOn();
  
      Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build());
      }
  </code></pre>
  
  <p>One hint I found here: <a href="https://stackoverflow.com/questions/16693231/forcefully-starting-the-game-after-successfully-room-creation-using-google-play">Forcefully starting the game after successfully room-creation using Google Play game Service android</a>
  They mention some custom timer.</p>