cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

All possible combinations of 6 player games

I have a game where players enter a queue/lobby and wait to be matched into a game. Each game must have 6 players in total, the gender balance has to be even, 3 males, 3 females.

I have a graph of nodes of type "Player" where the nodes are players and each player has a relationship to other nodes who fit their interests.

The relationship between Player nodes is called "IsCompatibleWith". This relationship only exists if player's preferred genders are mutual, i.e. if a male player prefers males, and there's another male player who prefers males, their two nodes would have the relationship.

Each Player node has a property "Gender" and "PreferredGender" which denotes each players own gender and the gender they want to play with.

I am trying to figure out a cypher that will return all possible combinations of 3 males and 3 females where their preferred genders match (i.e. 3 males seeking 3 females and vice-versa). The output values of each combination can be the Player IDs of each player, e.g. [[1,2,3, 4, 5, 6], [1, 2, 3, 8, 9, 10]], etc.

e.g. return all combinations of 3 males and 3 females where the males' preferredGender is female and the females' preferred gender is male.

There can be upwards of hundreds of players waiting to be matched into a game, so the more performant the better, although i do suspect calculating all possible combinations of potentially hundreds of entities can be very slow.

Any help is appreciated here. Let me know if this is feasible with Cypher or if a graph is even the best data structure/solution for this kind of application/problem.

4 REPLIES 4

To clarify, I want all possible combinations because of particular use case/some specific logic I want to perform down the line my application code which is irrelevant to this post. Just wanted to mention that in case folks were wondering.

Hello @nmaanfish 😊

First, be aware that this is very expensive to compute. Second, very hard to do it in pure CYPHER.

So that's why, you should have a look at APOC function apoc.coll.combinations().

Regards,
Cobra

Hi Cobra,

Thanks for taking the time to reply. 

Yeah I had a feeling this wouldn't be most efficient thing to compute.

Thanks for the suggestion! I am aware of the apoc functions but I just started trying out neo4j and cyphers 2 days ago so I am not so proficient at it yet - so I am not sure how to achieve what I described.

I have a few years of experience with CYPHER now and you should use the APOC function to achieve what you try to do:)