All problems
Self-Play Opponent Pick
Problem
Pick a self-play opponent by sampling from a softmax over ratings.
weights = exp((rating - max_rating) / temperature); draw u = rng.random() * sum(weights) with rng = random.Random(seed) and return the first index whose cumulative weight exceeds u, falling back to the last index.
Hint
Temperature controls how strongly self-play favors stronger opponents.
Test cases
case 1
in: [[1500,1600,1400],100,42]
expected: 1
case 2
in: [[1,1,1],1,0]
expected: 2
case 3
in: [[100],50,7]
expected: 0
Starter codePython
import math, random
def self_play_opponent_pick(ratings, temperature, seed):
# Your code here
pass3 test cases · run your code against them in the editor