mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-20 18:10:44 -04:00
Simulator handles when there are no Greed matches to randomly simulate.
This commit is contained in:
parent
802d43651e
commit
58bf85d234
2 changed files with 10 additions and 0 deletions
|
@ -37,6 +37,10 @@ module.exports = class Simulator extends CocoClass
|
|||
console.warn "There was an error fetching two games! #{JSON.stringify errorData}"
|
||||
success: (taskData) =>
|
||||
return if @destroyed
|
||||
unless taskData
|
||||
@trigger 'statusUpdate', "No games to simulate. Trying another game in #{@retryDelayInSeconds} seconds."
|
||||
@simulateAnotherTaskAfterDelay()
|
||||
return
|
||||
@trigger 'statusUpdate', 'Setting up simulation...'
|
||||
#refactor this
|
||||
@task = new SimulationTask(taskData)
|
||||
|
|
|
@ -138,6 +138,9 @@ module.exports.getTwoGames = (req, res) ->
|
|||
selection = "team totalScore transpiledCode submittedCodeLanguage teamSpells levelID creatorName creator submitDate"
|
||||
LevelSession.count queryParams, (err, numberOfHumans) =>
|
||||
if err? then return errors.serverError(res, "Couldn't get the number of human games")
|
||||
unless numberOfHumans
|
||||
res.send(204, "No games to score.")
|
||||
return res.end()
|
||||
humanSkipCount = Math.floor(Math.random() * numberOfHumans)
|
||||
ogreCountParams =
|
||||
"levelID": "greed"
|
||||
|
@ -145,6 +148,9 @@ module.exports.getTwoGames = (req, res) ->
|
|||
"team":"ogres"
|
||||
LevelSession.count ogreCountParams, (err, numberOfOgres) =>
|
||||
if err? then return errors.serverError(res, "Couldnt' get the number of ogre games")
|
||||
unless numberOfOgres
|
||||
res.send(204, "No games to score.")
|
||||
return res.end()
|
||||
ogresSkipCount = Math.floor(Math.random() * numberOfOgres)
|
||||
|
||||
query = LevelSession
|
||||
|
|
Loading…
Reference in a new issue