Round Robin tournament mode added to the game.#46
Conversation
…ased tourney seed
… of players in the end of the tourney. New UID handeling.
|
For the spawn of the red team, see #38, it is not because of your code. |
There was a problem hiding this comment.
That's a great start, but I understand why you have bugs.
Please try to refactor your code as follows:
- Create a
Game.javaclass which takes two players and make them fight against each other. - Create a
RoundRobinTourney.javaclass which is only busy with the tourney, and rely on Game to run the matches. - Since a new Game instance is created for each matchup, you don't need to reset the Battlefield and view, etc.
- The
Serverclass should be used to wait the players (in the beginning), and launch either a single Game, or the RoundRobinTourney.
Also, because a client can play several games, you will need to modify Client.java as well. Because for now, it only plays a single game and then exits.
…ishing the tourney, when all the matches were done.
pitbaum
left a comment
There was a problem hiding this comment.
The game.java file was added and i made some changes such that the client will be waiting until the server sends over the final scores of the tourney.
To implement the game.java and update and renew the battlefield/arena, i needed to make some small adjusments to the ui and the battlefieldViewer. In which i suppose i have not understood how the tiles are specifically updated, thus the server will throw an Error between the first and second round, about some old tiles not being updated. This error does not cuase any noticable problem, the program will still run as expected.
A bigger issue is that the server now throws a null pointer exception when the tourney is over and doesnt get to the sending of the scores to the users.
In the end, the current version runs all the matches necessary and then the server throws an exception, keeping the clients wait forever for some feedback of the final results.
ptal
left a comment
There was a problem hiding this comment.
Overall, that's an awesome contribution, congratz!
There are some comments because there are a lot of code.
I'm not sure we need to send the results to the clients, just send them an UID > 2 to force them terminating (since it is your condition). The null pointer exception might be because of the dummy player (as explained below).
I'd expect the server to display the result table of the players.
| sprites = new Sprites(); | ||
| } | ||
|
|
||
| public void generateNewBattlefieldView(Battlefield battlefield) { |
There was a problem hiding this comment.
Instead of having this method, wouldn't it be more convenient to just recreate the object BattlefieldView each time we start a new game? That might solve your first issue as well.
| private void roundOrganizer(Player playerGroup1, Player playerGroup2) throws IOException { | ||
| Player bluePlayer = playerGroup1; | ||
| Player redPlayer = playerGroup2; | ||
| bluePlayer.setRoundUID(0); |
There was a problem hiding this comment.
Use Nexus.BLUE/RED instead of 0/1 constant please (occur in several places in the code).
You can also use an array of players (of only two elements), to avoid repeating the code. For instance it would allow you to write updateScores(players[winner]) instead of having a conditional.
| public void registrationPhase() throws IOException { | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("Enter the number of participants for the tourney/match: "); | ||
| int expectedParticipants = scanner.nextInt(); |
There was a problem hiding this comment.
Optional modification: It would be better if the number of players were passed an argument to the program, e.g., retrieved in args of the main function. This will simplify the automation of the tournament.
| // Now the turn-based game starts until the game is over. | ||
| arena.startGamePhase(); | ||
| gameLoop(); | ||
| while(1 == 1) { |
There was a problem hiding this comment.
Write while(true) instead.
It would be better to have a "real" condition, such as while(teamID < 2)
Alternatively, you can write while(receiveUIDOrStop()) where this method is just receiveUID which returns teamID < 2.
| turn.send(socket); | ||
| System.out.println("sent"); | ||
| allChampionSelection(); | ||
| System.out.println("allCham"); |
There was a problem hiding this comment.
Please, remove the debugging messages (sent, allCham) for me :-) (I forgot to do that).
| } | ||
| } | ||
|
|
||
| private void updateEnvironment() { |
There was a problem hiding this comment.
Rename prepareEnvironment. Also since you have this method here, you can remove the code in the main which does the same.
| arena.applyTurn(turn); | ||
| ui.update(); | ||
| broadcast(turn); | ||
| wait(2000); |
There was a problem hiding this comment.
I'm not sure we want to wait that long if it's a tourney, depending on the numbers of AI how much time a single tourney can take?
| System.out.println("LOSER: " + nexus); | ||
| } | ||
| if(group2.size() < group1.size()) { | ||
| group2.add(null); //add dummy player. |
There was a problem hiding this comment.
That's risky to add null, it could lead to NullPointerException of not dealt with care. Couldn't we just check the group size instead of checking the null in the remaining of the code?
| //Dummy player round is skipped. | ||
| int set = 0; | ||
| int round = 0; | ||
| while(set < (int)((double)((group1.size()+group2.size())/2)*((group1.size()+group2.size())-1))) { |
There was a problem hiding this comment.
Add some messages on the terminal to write who is fighting against who, and the result.
Here my commit for the tournament mode. To execute the program, enter after having started the server the amount of clients you want to connect. If there are more then 2 clients connected, the tournament mode will be opened.
Known Bugs:
Currently the program will quit the execution of the program for the clients that have played a round in the tourney against each other.
Also sometimes the spawn of the red team doesnt work, i am not sure why it just sometimes happens.