// s = 1 if I win, 0 if they win, 0.5 if we tie.
// returns an array with new values
// for myR, myRD, theirR, theirRD
function glickoRatingUpdate(myR, myRD, theirR, theirRD, s) {
    var pi2 = Math.PI * Math.PI
    var q = Math.log(10) / 400
    var q2 = q * q
    
    function helper(myR, myRD, theirR, theirRD, s) {
        var myRD2 = myRD * myRD
        var theirRD2 = theirRD * theirRD
        var g = 1 / Math.sqrt(1 + 3 * q2 * theirRD2 / pi2)
        var g2 = g * g
        var E = 1 / (1 + Math.pow(
            10, g * (myR - theirR) / -400))
        var d2 = 1 / (q2 * g2 * E * (1 - E))
        var temp = 1 / (1 / myRD2 + 1 / d2)
        return [
            myR + q * temp * g * (s - E),
            Math.sqrt(temp)
        ]
    }
    var a = helper(myR, myRD, theirR, theirRD, s)
    var b = helper(theirR, theirRD, myR, myRD, 1 - s)
    return a.concat(b)
}