Try putting AI players in league ladders

This commit is contained in:
Nick Winter 2015-11-24 13:18:38 -08:00
parent 2a1b464d5a
commit 67f14c7928
3 changed files with 45 additions and 9 deletions

View file

@ -30,7 +30,7 @@
if level.get('type', true) == 'hero-ladder'
td.hero-portrait-cell(style="background-image: url(/file/db/thang.type/#{(session.get('heroConfig') || {}).thangType || '529ffbf1cf1818f2be000001'}/portrait.png)")
td.rank-cell= rank + 1
td.score-cell= Math.round(sessionStats.totalScore * 100)
td.score-cell= Math.round((sessionStats.totalScore || session.get('totalScore') / 2) * 100)
td(class='name-col-cell' + ((new RegExp('(Simple|Shaman|Brawler|Chieftain|Thoktar) AI')).test(session.get('creatorName')) ? ' ai' : ''))= session.get('creatorName') || "Anonymous"
td.age-cell= moment(session.get('submitDate')).fromNow().replace('a few ', '')
td.fight-cell
@ -50,7 +50,7 @@
if level.get('type', true) == 'hero-ladder'
td.hero-portrait-cell(style="background-image: url(/file/db/thang.type/#{(session.get('heroConfig') || {}).thangType || '529ffbf1cf1818f2be000001'}/portrait.png)")
td.rank-cell= session.rank
td.score-cell= Math.round(sessionStats.totalScore * 100)
td.score-cell= Math.round((sessionStats.totalScore || session.get('totalScore') / 2) * 100)
td(class='name-col-cell' + ((new RegExp('(Simple|Shaman|Brawler|Chieftain|Thoktar) AI')).test(session.get('creatorName')) ? ' ai' : ''))= session.get('creatorName') || "Anonymous"
td.age-cell= moment(session.get('submitDate')).fromNow().replace('a few ', '')
td.fight-cell

View file

@ -280,7 +280,10 @@ module.exports = class LadderTabView extends CocoView
consolidateFriends: ->
allFriendSessions = (@facebookFriendSessions or []).concat(@gplusFriendSessions or [])
sessions = _.uniq allFriendSessions, false, (session) -> session._id
sessions = _.sortBy sessions, 'totalScore'
if @options.league
sessions = _.sortBy sessions, (session) -> _.find(session.leagues, leagueID: @options.league.id)?.stats.totalScore ? (session.totalScore / 2)
else
sessions = _.sortBy sessions, 'totalScore'
sessions.reverse()
sessions

View file

@ -237,11 +237,8 @@ LevelHandler = class LevelHandler extends Handler
getLeaderboard: (req, res, id) ->
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)
sortParameters =
'totalScore': req.query.order
selectProperties = ['totalScore', 'creatorName', 'creator', 'submittedCodeLanguage', 'heroConfig', 'leagues.leagueID', 'leagues.stats.totalScore', 'submitDate']
sortParameters = totalScore: req.query.order
selectProperties = ['totalScore', 'creatorName', 'creator', 'submittedCodeLanguage', 'heroConfig', 'leagues.leagueID', 'leagues.stats.totalScore', 'submitDate', 'team']
query = Session
.find(sessionsQueryParameters)
.limit(req.query.limit)
@ -252,7 +249,13 @@ LevelHandler = class LevelHandler extends Handler
query.exec (err, resultSessions) =>
return @sendDatabaseError(res, err) if err
resultSessions ?= []
@sendSuccess res, resultSessions
leaderboardOptions = find: sessionsQueryParameters, limit: req.query.limit, sort: sortParameters, select: selectProperties
@interleaveAILeaderboardSessions leaderboardOptions, resultSessions, (err, resultSessions) =>
return @sendDatabaseError(res, err) if err
if league = req.query['leagues.leagueID']
resultSessions = _.sortBy resultSessions, (session) -> _.find(session.get('leagues'), leagueID: league)?.stats.totalScore ? session.get('totalScore') / 2
resultSessions.reverse() if sortParameters.totalScore is -1
@sendSuccess res, resultSessions
getMyLeaderboardRank: (req, res, id) ->
req.query.order = 1
@ -283,6 +286,36 @@ LevelHandler = class LevelHandler extends Handler
req.query.team ?= 'humans'
req.query.limit = parseInt(req.query.limit) ? 20
ladderBenchmarkAIs: [
'564ba6cea33967be1312ae59'
'564ba830a33967be1312ae61'
'564ba91aa33967be1312ae65'
'564ba95ca33967be1312ae69'
'564ba9b7a33967be1312ae6d'
]
interleaveAILeaderboardSessions: (leaderboardOptions, sessions, cb) ->
return cb null, sessions unless leaderboardOptions.find['leagues.leagueID']
return cb null, sessions if leaderboardOptions.limit < 10 # Don't put them in when we're fetching sessions around another session
# Get our list of benchmark AI sessions
benchmarkSessions = Session
.find(level: leaderboardOptions.find.level, creator: {$in: @ladderBenchmarkAIs})
.sort(leaderboardOptions.sort)
.select(leaderboardOptions.select.join ' ')
.cache() # TODO: How long does this cache? We will probably want these to be pretty long.
.exec (err, aiSessions) ->
return cb err if err
matchingAISessions = _.filter aiSessions, (aiSession) ->
return false unless aiSession.get('team') is leaderboardOptions.find.team
return false if $gt = leaderboardOptions.find.totalScore.$gt and aiSession.get('totalScore') <= $gt
return false if $lt = leaderboardOptions.find.totalScore.$lt and aiSession.get('totalScore') >= $lt
true
# TODO: these aren't real league scores for AIs, but rather the general leaderboard scores, which will make most AI scores artificially high. So we divide by 2 for AI scores not part of the league. Pretty weak, I know. Eventually we'd want them to actually play league matches as if they were in all leagues, but without having infinite space requirements or something? Or change the UI to take them out of the main league table and into their separate area.
sessions = _.sortBy sessions.concat(matchingAISessions), (session) -> _.find(session.get('leagues'), leagueID: leaderboardOptions.find['leagues.leagueID'])?.stats.totalScore ? session.get('totalScore') / 2
sessions.reverse() if leaderboardOptions.sort.totalScore is -1
sessions = sessions.slice 0, leaderboardOptions.limit
return cb null, sessions
getLeaderboardFacebookFriends: (req, res, id) -> @getLeaderboardFriends(req, res, id, 'facebookID')
getLeaderboardGPlusFriends: (req, res, id) -> @getLeaderboardFriends(req, res, id, 'gplusID')
getLeaderboardFriends: (req, res, id, serviceProperty) ->