mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Try putting AI players in league ladders
This commit is contained in:
parent
2a1b464d5a
commit
67f14c7928
3 changed files with 45 additions and 9 deletions
|
@ -30,7 +30,7 @@
|
||||||
if level.get('type', true) == 'hero-ladder'
|
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.hero-portrait-cell(style="background-image: url(/file/db/thang.type/#{(session.get('heroConfig') || {}).thangType || '529ffbf1cf1818f2be000001'}/portrait.png)")
|
||||||
td.rank-cell= rank + 1
|
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(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.age-cell= moment(session.get('submitDate')).fromNow().replace('a few ', '')
|
||||||
td.fight-cell
|
td.fight-cell
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
if level.get('type', true) == 'hero-ladder'
|
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.hero-portrait-cell(style="background-image: url(/file/db/thang.type/#{(session.get('heroConfig') || {}).thangType || '529ffbf1cf1818f2be000001'}/portrait.png)")
|
||||||
td.rank-cell= session.rank
|
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(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.age-cell= moment(session.get('submitDate')).fromNow().replace('a few ', '')
|
||||||
td.fight-cell
|
td.fight-cell
|
||||||
|
|
|
@ -280,7 +280,10 @@ module.exports = class LadderTabView extends CocoView
|
||||||
consolidateFriends: ->
|
consolidateFriends: ->
|
||||||
allFriendSessions = (@facebookFriendSessions or []).concat(@gplusFriendSessions or [])
|
allFriendSessions = (@facebookFriendSessions or []).concat(@gplusFriendSessions or [])
|
||||||
sessions = _.uniq allFriendSessions, false, (session) -> session._id
|
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.reverse()
|
||||||
sessions
|
sessions
|
||||||
|
|
||||||
|
|
|
@ -237,11 +237,8 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
|
|
||||||
getLeaderboard: (req, res, id) ->
|
getLeaderboard: (req, res, id) ->
|
||||||
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)
|
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)
|
||||||
|
sortParameters = totalScore: req.query.order
|
||||||
sortParameters =
|
selectProperties = ['totalScore', 'creatorName', 'creator', 'submittedCodeLanguage', 'heroConfig', 'leagues.leagueID', 'leagues.stats.totalScore', 'submitDate', 'team']
|
||||||
'totalScore': req.query.order
|
|
||||||
selectProperties = ['totalScore', 'creatorName', 'creator', 'submittedCodeLanguage', 'heroConfig', 'leagues.leagueID', 'leagues.stats.totalScore', 'submitDate']
|
|
||||||
|
|
||||||
query = Session
|
query = Session
|
||||||
.find(sessionsQueryParameters)
|
.find(sessionsQueryParameters)
|
||||||
.limit(req.query.limit)
|
.limit(req.query.limit)
|
||||||
|
@ -252,7 +249,13 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
query.exec (err, resultSessions) =>
|
query.exec (err, resultSessions) =>
|
||||||
return @sendDatabaseError(res, err) if err
|
return @sendDatabaseError(res, err) if err
|
||||||
resultSessions ?= []
|
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) ->
|
getMyLeaderboardRank: (req, res, id) ->
|
||||||
req.query.order = 1
|
req.query.order = 1
|
||||||
|
@ -283,6 +286,36 @@ LevelHandler = class LevelHandler extends Handler
|
||||||
req.query.team ?= 'humans'
|
req.query.team ?= 'humans'
|
||||||
req.query.limit = parseInt(req.query.limit) ? 20
|
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')
|
getLeaderboardFacebookFriends: (req, res, id) -> @getLeaderboardFriends(req, res, id, 'facebookID')
|
||||||
getLeaderboardGPlusFriends: (req, res, id) -> @getLeaderboardFriends(req, res, id, 'gplusID')
|
getLeaderboardGPlusFriends: (req, res, id) -> @getLeaderboardFriends(req, res, id, 'gplusID')
|
||||||
getLeaderboardFriends: (req, res, id, serviceProperty) ->
|
getLeaderboardFriends: (req, res, id, serviceProperty) ->
|
||||||
|
|
Loading…
Reference in a new issue