 
 Game = require('./game')
 
+start = (robot, game) ->
+  game.init robot.brain.data
+  robot.hearspond new RegExp("cah (submit|play)( [1-" + game.db.handsize + "])+$", "i"), game.submit.bind game
+
 module.exports = (robot) ->
 
-  game = new Game(robot)
+  global.game = new Game(robot)
 
   robot.error (err, res) ->
     if res?


  robot.hearspond /cah db$/i, (res) ->
    res.reply JSON.stringify game.db
    
  robot.hearspond /cah help$/i, (res) ->
    res.send helpSummary


    robot.logger.error JSON.stringify(robot.brain.data.cah, null, '\t')

  robot.brain.on "loaded", =>
    start(robot, game)
  
  # combo hear and respond, prepends ^ to hear regex
  # good for allowing same commands in room and DM
