Thread: PK Ladder System - A better alternative for PK Points

Page 1 of 4 123 ... LastLast
Results 1 to 10 of 38
  1. #1 PK Ladder System - A better alternative for PK Points 
    Registered Member

    Join Date
    Sep 2007
    Age
    32
    Posts
    2,396
    Thanks given
    5
    Thanks received
    436
    Rep Power
    902
    Quick Note: Implementing this has no downside and the sooner its implemented the better the results will be.

    Hi All,

    So firstly we all know that for the past like 6 years servers have been using kill to death ratios and pk points as a means for measuring a players skill at pking. This is plain stupid, as servers have grown a better solution should have been implemented long ago and this is what this tutorial will cover.

    If you look at games like starcraft 2, league of legends (dota?), you'll notice they have a built in ladder ranking system to determine what players are better than others. This system is quite scalable compared to the classic kill to death ratio as it allows the server to differentiate between a grandmaster and a player that just kill noobs all day long. The system this tutorial is going to implement is the ELO ranking system currently used to rank chess masters up to grandmasters aswell as used in the game league of legends. For more information on this ranking system and the maths behind it see this wiki page:

    Elo rating system - Wikipedia, the free encyclopedia

    This quote is a good description of how the ELO system works:

    A player's Elo rating is represented by a number, which increases or decreases based upon the outcome of games between rated players. After every game, the winning player takes points from the losing one. The total number of points gained or lost after a game is determined by the difference between the ratings of the winner and loser. In a series of games between a high-rated player and a low-rated player, the high-rated player is expected to score more wins. If the high-rated player wins, only a few rating points will be taken from the low-rated player. However, if the lower rated player scores an upset win, many rating points will be transferred. The lower rated player will also gain a few points from the higher rated player in the event of a draw. This makes the rating system self-correcting. A player whose rating is too low should, in the long run, do better than the rating system predicts, and thus gain rating points until the rating reflects the true playing strength.
    Now implementing this kind of a system into any game is quite simple. In this tutorial we will have 1 class which will handle all the maths, and then call for a players rating to be updated every time they kill a player.

    EloRatingSystem.java
    Package: server.util;
    Source: https://code.google.com/p/gae-ogre/s...stem.java?r=25
    Author: Garrett Lehman (gman)
    Comments: I removed a load of unnecessary code that will not apply to RSPS.

    Code:
    package server.util;
    
    
    /*
     * JOGRE (Java Online Gaming Real-time Engine) - API
     * Copyright (C) 2004  Bob Marks ([email protected])
     * http://jogre.sourceforge.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * as published by the Free Software Foundation; either version 2
     * of the License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     */
    
    
    
    
    /**
     * JOGRE's implementation of the ELO rating system.  The following is an
     * example of how to use the Elo Rating System.
     * <code>
     *         int userRating = 1600;
     *         int opponentRating = 1650; 
     *         int newUserRating = getNewRating(userRating, opponentRating, WIN);
     *         int newOpponentRating = getNewRating(opponentRating, userRating, LOSS);
     * </code>
     * 
     * @author Garrett Lehman (gman)
     */
    public class EloRatingSystem {
        
        
        // Score constants
        private final static double GWIN = 1.0;
        private final static double GDRAW = 0.5;
        private final static double GLOSS = 0.0;
    
    
    
    
        /** Default ELO starting rating for new users. */ 
        public static final int DEFAULT_ELO_START_RATING = 1200; 
        
        /** Default ELO k factor. */
        public static final double DEFAULT_ELO_K_FACTOR = 24.0;
        
        /** Player wins a game. */
        public static final int WIN = 1;
    
    
        /** Player losses a game. */
        public static final int LOSE = 2;
    
    
        /** Player draws with another player. */
        public static final int DRAW = 3;     
        
        /**
         * Convience overloaded version of getNewRating (int, int, double)
         * which takes a result type and 
         * 
         * @param rating
         * @param opponentRating
         * @param resultType
         * @return
         */
        public static int getNewRating (int rating, int opponentRating, int resultType) {
            switch (resultType) {
                case WIN:
                    return getNewRating (rating, opponentRating, GWIN);
                case LOSE:
                    return getNewRating (rating, opponentRating, GLOSS);
                case DRAW:
                    return getNewRating (rating, opponentRating, GDRAW);                
            }
            return -1;        // no score this time.
        }
        
        /**
         * Get new rating.
         * 
         * @param rating
         *            Rating of either the current player or the average of the
         *            current team.
         * @param opponentRating
         *            Rating of either the opponent player or the average of the
         *            opponent team or teams.
         * @param score
         *            Score: 0=Loss 0.5=Draw 1.0=Win
         * @return the new rating
         */
        public static int getNewRating(int rating, int opponentRating, double score) {
            double kFactor       = getKFactor(rating);
            double expectedScore = getExpectedScore(rating, opponentRating);
            int    newRating     = calculateNewRating(rating, score, expectedScore, kFactor);
            
            return newRating;
        }    
        
        /**
         * Calculate the new rating based on the ELO standard formula.
         * newRating = oldRating + constant * (score - expectedScore)
         * 
         * @param oldRating     Old Rating
         * @param score            Score
         * @param expectedScore    Expected Score
         * @param constant        Constant
         * @return                the new rating of the player
         */
        private static int calculateNewRating(int oldRating, double score, double expectedScore, double kFactor) {
            return oldRating + (int) (kFactor * (score - expectedScore));
        }
        
        /**
         * This is the standard chess constant.  This constant can differ
         * based on different games.  The higher the constant the faster
         * the rating will grow.  That is why for this standard chess method,
         * the constant is higher for weaker players and lower for stronger
         * players.
         *  
         * @param rating        Rating
         * @return                Constant
         */
        private static double getKFactor (int rating) {
            // Return the correct k factor.
            return DEFAULT_ELO_K_FACTOR;
        }
        
        /**
         * Get expected score based on two players.  If more than two players
         * are competing, then opponentRating will be the average of all other
         * opponent's ratings.  If there is two teams against each other, rating
         * and opponentRating will be the average of those players.
         * 
         * @param rating            Rating
         * @param opponentRating    Opponent(s) rating
         * @return                    the expected score
         */
        private static double getExpectedScore (int rating, int opponentRating) {
            return 1.0 / (1.0 + Math.pow(10.0, ((double) (opponentRating - rating) / 400.0)));
        }
        
    }
    Add this variable to Player.java to remember what the eloRating for every player will be.

    Code:
    public int eloRating = EloRatingSystem.DEFAULT_ELO_START_RATING;
    This will require the import:

    Code:
    import server.util.EloRatingSystem;
    Updating the eloRating when a player gets a kill:
    The method that is called when a player is killed is located in PlayerAssisant.java
    search for:
    public void applyDead()
    Scroll down in the method until you see:
    Code:
    o.sendMessage("You have received a point, you now have "+o.pkPoints+" pk points.");
    below it add:
    Code:
    o.eloRating = EloRatingSystem.getNewRating(o.eloRating, c.eloRating, EloRatingSystem.WIN);
    c.eloRating = EloRatingSystem.getNewRating(c.eloRating, o.eloRating, EloRatingSystem.LOSE);
    You also need to add an import to that class:

    Code:
    import server.util.EloRatingSystem;
    Nearly done!
    The last stage of this tutorial is saving the variable so it does not reset the next time the player logs in.
    Open server.model.players.PlayerSave.java

    We now need to modify the save and load methods. search for:
    Code:
    } else if (line.startsWith("KC")) {
    ABOVE IT add
    Code:
    } else if (line.startsWith("eloRating")) {
    p.eloRating = Integer.parseInt(token2);
    Now search for:
    Code:
    characterfile.write("KC = ", 0, 4);
    ABOVE IT add

    Code:
    characterfile.write("eloRating = ", 0, 4);characterfile.write(Integer.toString(p.eloRating), 0, Integer.toString(p.eloRating).length());
    characterfile.newLine();
    And that's it!!!

    The next stage in this tutorial will be linked to other tutorial like ingame highscore lists which replace the ELO System value over the kill to death ratio and the pk points value!

    Any questions leave below, I hope in not too long we will see some better PK ladders out there on large servers!
    Hyperion V2 Martin's Updates.

    Scar says:
    i hate it when it hits your face
    Reply With Quote  
     


  2. #2  
    Registered Member
    Join Date
    Dec 2011
    Posts
    281
    Thanks given
    2
    Thanks received
    4
    Rep Power
    15
    Thanks for this
    Reply With Quote  
     

  3. #3  
    « Pokémon Master »
    Ash Ketchum's Avatar
    Join Date
    Jun 2011
    Age
    29
    Posts
    1,423
    Thanks given
    275
    Thanks received
    153
    Rep Power
    39
    Hmm this would be cool to use for Wins\Losses on minigames and make highscores from that.. thanks for this.
    Attached image
    Spoiler for Galkon:

    Spoiler for Great Quotes:
    Quote Originally Posted by i am prod View Post
    **** YOU this just erased everyones passwords and no one can log in!!!
    Quote Originally Posted by blade2 View Post
    did i ****ing say it was a ****ing virus u dip shit i said virus scan dont scan java files i didn't say its a virus... l2****ingreadkid
    Spoiler for (╯°□°)╯︵┻━┻:
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Jul 2007
    Age
    32
    Posts
    466
    Thanks given
    90
    Thanks received
    52
    Rep Power
    87
    Are u kidding me I yesterday start coding this for my project and it is now relased xD Thanks Martin.
    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Banned

    Join Date
    Nov 2010
    Age
    14
    Posts
    2,639
    Thanks given
    158
    Thanks received
    280
    Rep Power
    0
    Thanks for sharing, Martin.
    Reply With Quote  
     

  7. #6  
    Registered Member

    Join Date
    Sep 2007
    Age
    32
    Posts
    2,396
    Thanks given
    5
    Thanks received
    436
    Rep Power
    902
    Just so everyone knows this can be implemented for any equal team based minigame, castle wars, dueling and as long its not 1 person against 3!
    Hyperion V2 Martin's Updates.

    Scar says:
    i hate it when it hits your face
    Reply With Quote  
     

  8. #7  
    Member PK Ladder System - A better alternative for PK Points Market Banned

    Join Date
    May 2011
    Age
    29
    Posts
    414
    Thanks given
    16
    Thanks received
    44
    Rep Power
    56
    Very Nice Martin. Great work!
    Reply With Quote  
     

  9. #8  
    Super Donator

    Jack Daniels's Avatar
    Join Date
    Oct 2010
    Posts
    1,842
    Thanks given
    787
    Thanks received
    507
    Rep Power
    412
    I like it, very much
    Reply With Quote  
     

  10. #9  
    Banned

    Join Date
    Jan 2010
    Posts
    3,664
    Thanks given
    533
    Thanks received
    918
    Rep Power
    0
    very cool idea, great release Martin.
    Reply With Quote  
     

  11. #10  
    Registered Member

    Join Date
    Mar 2011
    Posts
    1,226
    Thanks given
    245
    Thanks received
    475
    Rep Power
    294
    What an awesome idea!
    Reply With Quote  
     

Page 1 of 4 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [667-718] - Looking for PK point system!!
    By berke203 in forum Help
    Replies: 1
    Last Post: 06-26-2013, 08:43 PM
  2. Replies: 43
    Last Post: 02-11-2010, 03:10 AM
  3. Needing hoster for pk server
    By ragean in forum Hosting
    Replies: 0
    Last Post: 05-05-2009, 12:56 PM
  4. making a good pk reward system
    By Arvid in forum Tutorials
    Replies: 19
    Last Post: 02-29-2008, 07:58 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •