@@ -0,0 +1,2079 @@
+#ELO%0A#python 3.4.3%0Aimport math%0A%0Aclass ELOPlayer:%0A    name      = %22%22%0A    place     = 0%0A    eloPre    = 0%0A    eloPost   = 0%0A    eloChange = 0%0A    %0Aclass ELOMatch:%0A    players = %5B%5D%0A    %0A    def addPlayer(self, name, place, elo):%0A        player = ELOPlayer()%0A        %0A        player.name    = name%0A        player.place   = place%0A        player.eloPre  = elo%0A        %0A        self.players.append(player)%0A        %0A    def getELO(self, name):%0A        for p in self.players:%0A            if p.name == name:%0A                return p.eloPost%0A            %0A        return 1500;%0A%0A    def getELOChange(self, name):%0A        for p in self.players:%0A            if p.name == name:%0A                return p.eloChange;%0A                %0A        return 0;%0A %0A    def calculateELOs(self):%0A        n = len(self.players)%0A        K = 32 / (n - 1);%0A        %0A        for i in range(n):%0A            curPlace = self.players%5Bi%5D.place;%0A            curELO   = self.players%5Bi%5D.eloPre;%0A                        %0A            for j in range(n):%0A                if i != j:%0A                    opponentPlace = self.players%5Bj%5D.place%0A                    opponentELO   = self.players%5Bj%5D.eloPre  %0A                    %0A                    #work out S%0A                    if curPlace %3C opponentPlace:%0A                        S = 1.0%0A                    elif curPlace == opponentPlace:%0A                        S = 0.5%0A                    else:%0A                        S = 0.0%0A                    %0A                    #work out EA%0A                    EA = 1 / (1.0 + math.pow(10.0, (opponentELO - curELO) / 400.0))%0A                    %0A                    #calculate ELO change vs this one opponent, add it to our change bucket%0A                    #I currently round at this point, this keeps rounding changes symetrical between EA and EB, but changes K more than it should%0A                    self.players%5Bi%5D.eloChange += round(K * (S - EA))%0A%0A                    #add accumulated change to initial ELO for final ELO   %0A                    %0A            self.players%5Bi%5D.eloPost = self.players%5Bi%5D.eloPre + self.players%5Bi%5D.eloChange

Add Python version