How would you have players matched up in games?

I want to make a game.

This game would involve people getting into 1 on 1 multiplayer matches with eachother.

Heres the problem: I don’t know how to do that!

How would you do that? I don’t want to have to make a server for each game (Though if that what you gotta do I’ll do it)

Anyways, how do you do it? Any ideas?

Sorry if this isn’t concise enough, feel free to ask questions.

Rule #3 of concurrency: You don’t need it, that’s an iterative problem.


class Match {
    Player p1, p2;

    public void tick(...) {...}

}

...

//in Server

public void tick(...) {
    for(Match match : currentMatches) {
        match.tick(...);
    }
}

Each Match is like a Entity in the classical single-player game loop, but of course has it’s own actual Entities inside.

Thats what I was thinking. Thanks so much man! :point: :point: :point:

Note that if the server is doing heavy lifting, then you might actually want each Match in it’s own thread. (assuming matches are independent of each other)

So, you saying each match class should have its own thread? and then it would run the tick loop?

Well you could do it two ways:

  • Each Match is a Runnable with it’s own game loop. This is the simple, recommended way.
  • Have a thread pool (ExecutorService) run a small number of threads, each running a portion of total matches, as in my earlier post, say you have X threads (number of cores on the machine perhaps), then each thread runs currentMatches.size() / X matches.

Thanks man!

I’d like to stress the importance of rule #3 of concurrency, especially for the OP.

Besides, I interpreted the topic title as refering to match-making and/or networking in general. Getting players to find eachother and play a game usually requires quite an effort, whereas organising classes to handle multiple matches serverside is almost trivial. Writing a multiplayer game is at least an order of magnitude harder than writing a singleplayer game.

I’d go as far as advising the OP to postpone multiplayer entirely, to get more experience with writing, finishing and publishing a game in the first place.