codecombat/scripts/simulate.coffee

23 lines
808 B
CoffeeScript
Raw Normal View History

2014-05-18 23:06:38 -04:00
spawn = require("child_process").spawn
[sessionOne, sessionTwo] = [process.argv[2],process.argv[3]]
2014-05-19 13:40:20 -04:00
homeDirectory = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
2014-05-18 23:06:38 -04:00
unless sessionOne and sessionTwo and sessionOne.length is 24 and sessionTwo.length is 24
console.log "Not enough games to continue!"
process.exit(1)
run = (cb) ->
2014-05-19 13:40:20 -04:00
command = spawn("coffee",["headless_client.coffee","one-game",sessionOne,sessionTwo],{cwd: homeDirectory + "/codecombat/"})
2014-05-18 23:06:38 -04:00
result = ""
command.stdout.on 'data', (data) ->
result += data.toString()
command.stdout.on 'close', ->
return cb(result)
run (result) ->
2014-05-19 13:11:20 -04:00
lines = result.split("\n")
for line in lines
if line.slice(0, 10) is "GAMERESULT"
process.stdout.write line.slice(11)
process.exit(0)
2014-05-18 23:06:38 -04:00
process.exit(0)