def compare(args): def compare_elo(ratings): value1 = ratings[0].value.value value2 = ratings[1].value.value if value1 != value2: winning_player = args.player1 if value1 > value2 else args.player2 print "\tPlayer %s will (probably) win." % winning_player print "\tRank player %s: %d" % (args.player1, value1) print "\tRank player %s: %d" % (args.player2, value2) print "\tPlayer %s is %d points better." % (winning_player, abs(value1 - value2)) else: print "Both players have the same elo rank (%d)" % value1 def compare_glicko(ratings): exp = glicko.expectation(ratings[0].rating.value, ratings[1].rating.value, ratings[1].rd.value) print "The result is %f.\n" % exp if 0.45 <= exp <= 0.55: print "They will probably draw." elif exp > 0.55: print "Player %s will (probably) win." % args.player1 else: print "Player %s will (probably) win." % args.player2 """ Compares the rating of two given players. :param args: A list with arguments from the argument parser :type args: namespace """ if args.player1 is args.player2: print "You cannot compare player %s with himself" % args.player1 return print "Comparing the rating of two players in %s with %s:" % ( args.game, args.algorithm) ratings = utils.get_rating(args) if ratings is None: print "Both players are not known!" return if (ratings[0] == None): print "Player with nickname %s not known." % args.player1 return if (ratings[1] == None): print "Player with nickname %s not known." % args.player2 return compare_funcs = {'elo': compare_elo, 'glicko': compare_glicko} compare_funcs[args.algorithm](ratings)
def compare(args): def compare_elo(ratings): value1 = ratings[0].value.value value2 = ratings[1].value.value if value1 != value2: winning_player = args.player1 if value1 > value2 else args.player2 print "\tPlayer %s will (probably) win." % winning_player print "\tRank player %s: %d" % (args.player1, value1) print "\tRank player %s: %d" % (args.player2, value2) print "\tPlayer %s is %d points better." % (winning_player, abs(value1 - value2)) else: print "Both players have the same elo rank (%d)" % value1 def compare_glicko(ratings): exp = glicko.expectation(ratings[0].rating.value, ratings[1].rating.value, ratings[1].rd.value) print "The result is %f.\n" % exp if 0.45 <= exp <= 0.55: print "They will probably draw." elif exp > 0.55: print "Player %s will (probably) win." % args.player1 else: print "Player %s will (probably) win." % args.player2 """ Compares the rating of two given players. :param args: A list with arguments from the argument parser :type args: namespace """ if args.player1 is args.player2: print "You cannot compare player %s with himself" % args.player1 return print "Comparing the rating of two players in %s with %s:" % (args.game, args.algorithm) ratings = utils.get_rating(args) if ratings is None: print "Both players are not known!" return if (ratings[0] == None): print "Player with nickname %s not known." % args.player1 return if (ratings[1] == None): print "Player with nickname %s not known." % args.player2 return compare_funcs = {'elo': compare_elo, 'glicko': compare_glicko} compare_funcs[args.algorithm](ratings)
def match(args): def match_elo(rating): ratings = Rank_Elo.query().all() best = None deviation = 99999999 for r in ratings: if (best is None or abs(r.value.value - rating.value.value) < deviation) and r.player_id.value != rating.player_id.value: best = r deviation = abs(r.value.value - rating.value.value) return best def match_glicko(rating): print "Not implemented yet" return None """ Finds the best opponent for a given player. :param args: A list with arguments from the argument parser :type args: namespace """ match_funcs = {'elo': match_elo, 'glicko': match_glicko} rating = utils.get_rating(args) if rating is None: print "Player %s is not known." % args.player return print "Looking for the best opponent for player %s..." % args.player opponent = match_funcs[args.algorithm](rating) if opponent is None: print "No opponent found." return print "Best opponent for player %s with rating %d is:" % ( args.player, rating.value.value) other = Player.query().get(player_id=opponent.player_id.value) print "\tPlayer %s with rating %d." % (other.nickname.value, opponent.value.value)
def match(args): def match_elo(rating): ratings = Rank_Elo.query().all() best = None deviation = 99999999 for r in ratings: if (best is None or abs(r.value.value - rating.value.value) < deviation) and r.player_id.value != rating.player_id.value: best = r deviation = abs(r.value.value - rating.value.value) return best def match_glicko(rating): print "Not implemented yet" return None """ Finds the best opponent for a given player. :param args: A list with arguments from the argument parser :type args: namespace """ match_funcs = {'elo': match_elo, 'glicko': match_glicko} rating = utils.get_rating(args) if rating is None: print "Player %s is not known." % args.player return print "Looking for the best opponent for player %s..." % args.player opponent = match_funcs[args.algorithm](rating) if opponent is None: print "No opponent found." return print "Best opponent for player %s with rating %d is:" % (args.player, rating.value.value) other = Player.query().get(player_id=opponent.player_id.value) print "\tPlayer %s with rating %d." % (other.nickname.value, opponent.value.value)
def rating(args): """ Queries the rating of a given player. :param args: A list with arguments from the argument parser :type args: namespace """ player = utils.get_rating(args) if player is None: print "The rating for player %s in %s using %s is not known." % ( args.player, args.game, args.algorithm) else: if args.algorithm == "elo": print "The rating for player %s in %s using %s is %d." % ( args.player, args.game, args.algorithm, player.value.value) else: print "The rating for player %s in %s using %s is %d " \ "with rating deviation %d" % (args.player, args.game, args.algorithm, player.rating.value, player.rd.value)