Donate Share

Java Online Gaming Real-time Engine

Subscribe

How to manage scores?

  1. 2009-09-14 14:55:52 UTC

    Hi everyone, I finished a game, and I want to manage the scores. I know that winner takes two points and loser loses two. isn't? I want to manage that by my own. is that possible? This is my gameOver code for the GameServerControler class :

    public void gameOver (ServerConnectionThread conn, int tableNum, int resultType) {
            System.out.println("GOTCHA");
        // Status is either -1, DRAW or WIN
        int status = GameOver.WIN;
    
     if (getTable(tableNum).getNumOfPlayers() < 4) {
    
            **gameOver (conn, tableNum, conn.getUsername(), status);**
        }
        else {
            // here's to code for 4 players game Over       
    
        }
    }
    

    I think I should change the bold code, but how?

  2. 2009-09-21 17:45:16 UTC

    Iori,

    Sorry about not responding sooner. I wanted to be able to look over the code before answering, but it's been a busy week where I didn't get a chance. But I also don't want to thinking that I'm ignoring you.

    By managing the scores, are you talking about the player ratings? These are the numbers that are displayed next to a player's name in the lobby window and start at 1200 and go up when you win and down when you lose?

    If that is the case, then the short answer appears to currently be no, you can't manage the ELO Ratings on your own.

    When you call one of the system's gameOver() methods, several things are done. One of them is that a history of the game is written into the persistent database. As part of that process, the ratings of the players is adjusted and updated in the database also. You can configure some of the parameters that the ELO rating system uses when updating ratings by specifying them in the server.xml file, but it doesn't appear that you can take over the ELO system entirely.

    Perhaps if you give more detail of what you are trying to accomplish, I can help you achieve what you want.

    -Richard

  3. 2009-09-21 19:26:32 UTC

    Yeah, thank you Richard. That's what I meant in fact. I tried to follow the trace of the GameOver operation and I reached to where the system manage these things called ELO Rating, etc.. this is why I asked.

    What I want to do is : Once a game is finished, every one will get some points that go to the database. you know, for example 10 pts for the winner, maybe this change to 20 if he accomplished an "extra" Win. Same goes for losers.. With this I can for example set a TOP 10 for best players.. etc

  4. 2009-09-22 01:38:58 UTC

    Iori,

    Thanks for the response. So, you do want to manage your own ratings system rather use the ELO system provided by the Jogre system.

    I've had a chance to look at the code some and in order to accomplish that, I think that we need to rearrange how the ratings are currently done. However, I don't think that it will be too bad to do.

    Currently, the module .../server/EloRatingSystem.java keeps a static hashMap of elo ratings systems, using the name of the game as a key. Each entry in this hashMap is an EloRatingSystem that is configured using the entries in the server.xml file to set things like the kFactors. (Actually, the hashMap is built on demand; an entry for a specific game is created the first time that game is needed, but that distinction isn't important for this discussion.) When a game is finished, the database/xml interface module asks the static hashmap to lookup the rating system for that game, provides it the current results and asks it to return the new ratings for the players. Those new ratings are then placed into the database and reported back.

    The reason that you can't easily interrupt this process is because the EloRatingSystem doesn't allow anyone else to add entries to the hashMap.

    To easily allow games to substitute their own ratings systems, I propose the following high-level changes:

    1) Create a new interface, IRatingSystem that defines the things that a rating system does. Currently, this is pretty much just "getNewRatings()".

    2) Make the current EloRatingSystem just an implementation of the IRatingSystem.

    3) Change the ServerDatabase modules addGame() method to take a rating system as a parameter. So, instead of asking the EloRatingSystem for the rating system, one would be provided.

    4) Change ServerController to provide a rating system to addGame() in the gameOver() methods. It would get the rating system via an overridable method, getRatingSystem(). In the standard ServerController this would return an EloRatingSystem so games that want the standard behavior wouldn't change at all. Games that want to provide a custom rating system would override the getRatingSystem() method to return a custom one.

    I'm going to start implementing this, but it will likely take a few days. If anyone has major issues, let me know here.

    -Richard

  5. 2009-09-22 01:49:57 UTC

    You're doing a great work Richard :) I wish I could help you for the documentation and tutorials, but my english is not very helpful. Waiting for your update :)

  6. 2009-09-22 05:37:08 UTC

    I just checked in an update that does this. (It was somewhat easier than I thought it would be.)

    It's basically what I wrote above, except for step 4. Since the ratings system for a game should be static, there's no reason to keep calling getRatingSystem() each time a game ends. So, instead I've added a constructor for the ServerController that takes a parameter which is the rating system to use for the game. The old constructor without the new parameter will create a standard ELO rating system, so games that don't need this functionality don't change at all.

    There are three ways to use this:

    a) In the server directory for your game, create a new file xxxRatingSystem.java that implements IRatingSystem. Then, in your xxxServerController constructor, do this:

    public xxxServerController (String gameKey) {
        super (gameKey, new xxxRatingSystem());
    }
    

    or b) Make the xxxServerController itself implement the IRatingSystem interface, and then in the constructor do this:

    public xxxServerController (String gameKey) {
        super (gameKey);
        gameRatingSystem = this;
    }
    

    or c) create a private class within the xxxServerController that implements the IRatingSystem, and change the constructor to be:

    public xxxServerController (String gameKey) {
       super (gameKey);
       gameRatingSystem = new customRatingSystem();
    }
    

    For cases b & c, you can't use the new constructor because you're not allowed to use "this" or private classes in the call to super(). So, in those cases, you need to set the gameRatingSystem field directly.

    In any case, to use the new rating system, whenever any of the gameOver() methods is called by the server controller, the getNewRatings() of your custom rating system will be called with the array of current ratings and the array of WIN/LOSE statuses. You then need to return the new ratings.

    For example, a simple custom rating system for a two player game might be:

    public int[] getNewRatings(int[] currentRatings, int[] results, Object customData) {
        int [] newRatings = new int [2];
        newRatings[0] = currentRatings[0];
        newRatings[1] = currentRatings[1];
    
        if (results[0] == IGameOver.WIN) {
            // Player 0 wins
            newRatings[0] += 10;
            newRatings[1] -=  5;
        } else if (results[0] == IGameOver.LOSE) {
            // Player 1 wins
            newRatings[1] += 10;
            newRatings[0] -=  5;
        }
        return newRatings;
    }
    

    This will add 10 points to the rating of the winner and subtract 5 points from the rating of the loser.

    The initial rating to give to new users is still defined in the server.xml file within the game using the <elo startRating="x"> field, regardless of rating system. I'm thinking of changing the tag from "elo" to "rating" because it's now a generic rating system, but haven't decided whether to do that or not.

    The customData field of getNewRatings allows a game to provide more data to the rating system than just the results, if you need such functionality.

    I hope this is clear. Let me know if you need any more help with explanations.

    -Richard

  7. 2009-09-23 21:40:43 UTC

    I think there's no IRatingSystem Richard. The EloRatingSystem implements nothing. Should I refactor it, and get an IRatingSystem? where do I have to put it?

  8. 2009-09-24 01:10:25 UTC

    Iori,

    You'll need to update your local files to get the latest source from CVS from sourceforge to get my updates; there's no package with this change yet.

    Once you get it, you should find ...jogre/server/src/org/jogre/server/IRatingSystem.java. If you have that file, then you'll have the other changes to make it work.

    -Richard

< Previous | 1 | Next >

Add a Reply

This forum does not allow anonymous participation.

Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.