I'm developing a multiplayer game via Game Center.
So I have players with different groups (some sort of clans). All matches requires exactly 2 players. How can I do matchmaking only for players with different groups?
E.g.:
Clan 1 + Clan 2 = true;
Clan 5 + Clan 5 = false;
Clan 5 + Clan 6 = true;
I know there is a playerGroup
property, but it performs exactly the opposite thing :(
The playerAttributes
property of the match request should be able to do what you want. It's a 32-bit mask that, when set to a non-zero value, players will only automatch into the game if they complete the mask (OR'd together) to 0xFFFFFFFF. See an example here.
However, the problem is you indicate you have many more clans than players. If you have 6 and define them as:
#define CLAN1 0xFF00000F
#define CLAN2 0xFF0000F0
#define CLAN3 0xFF000F00
#define CLAN4 0xFF00F000
#define CLAN5 0xFF0F0000
#define CLAN6 0xFFF00000
Then the OR'd combination of just two players would never fully reach 0xFFFFFFFF. I think you can do what you want by inverting the masks, though, and using 0's instead of 1's to define the role you want.
#define CLAN1 0xFFFFFFF0
#define CLAN2 0xFFFFFF0F
#define CLAN3 0xFFFFF0FF
#define CLAN4 0xFFFF0FFF
#define CLAN5 0xFFF0FFFF
#define CLAN6 0xFF0FFFFF
Any two of those from different clans OR together as 0xFFFFFFFF. So, game center willing (which is always an iffy proposition), any two players from different clans should match; however, two players from the same clan should not.
Note: I'm probably stating the obvious here, but note that you could have up to 32 different clans if you define them in binary rather than hex, and thus use a single bit for each clan. I only used hex numbers here for readability.