Add simulate script foundation

This commit is contained in:
Michael Schmatz 2014-05-18 20:06:38 -07:00
parent 2cc344c4f0
commit cb1c21e80a
2 changed files with 27 additions and 0 deletions

View file

@ -1,6 +1,13 @@
###
This file will simulate games on node.js by emulating the browser environment.
###
if process.argv[2] is "one-game"
#calculate result of one game here
if Math.random() > 0.5
process.stdout.write "ogres"
else
process.stdout.write "humans"
process.exit(0)
bowerComponentsPath = "./bower_components/"
headlessClientPath = "./headless_client/"

20
scripts/simulate.coffee Normal file
View file

@ -0,0 +1,20 @@
spawn = require("child_process").spawn
[sessionOne, sessionTwo] = [process.argv[2],process.argv[3]]
unless sessionOne and sessionTwo and sessionOne.length is 24 and sessionTwo.length is 24
console.log "Not enough games to continue!"
process.exit(1)
command = "coffee ../headless_client.coffee one-game"
run = (cb) ->
command = spawn("coffee",["headless_client.coffee","one-game"],{cwd:"/Users/schmatz/codecombat/"})
result = ""
command.stdout.on 'data', (data) ->
result += data.toString()
command.stdout.on 'close', ->
return cb(result)
run (result) ->
process.stdout.write result
process.exit(0)