Skip to content

Commit

Permalink
Cleaning up some todos
Browse files Browse the repository at this point in the history
  • Loading branch information
phillc committed May 27, 2014
1 parent a4c4480 commit 879ec17
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
3 changes: 0 additions & 3 deletions bin/ava
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var program = require('commander')

var ran = false;
// TODO: read from package.json
program
.version(require('../package.json').version)

Expand All @@ -13,8 +12,6 @@ program
.option('--debug', 'Show debug log (note: server performance takes a hit)')
.option('--turn-time', 'Time allowed for each action (ms)', parseInt)

// TODO: ava update, looks at a yml file for update dir

program.parse(process.argv)

if(program.server) {
Expand Down
15 changes: 3 additions & 12 deletions lib/arena.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,21 @@ module.exports = class Arena extends EventEmitter
for agent in agents
@removeAgent(agent)

gameClass = @builder.Game
game = @builder.createGame()
availablePositions = @builder.positions()
for agent in und.shuffle(agents)
position = availablePositions.shift()
do (game, gameClass, position, agent) ->
do (game, position, agent) =>
logger.info "wiring up #{agent} to #{position}"

#TODO: clearly, this needs a cleanup
# Tic tac toe
# agent.on "move", (args...) ->
# game.handle ["move", position].join("."), args...
# game.on [position, "turn"].join("."), (data) ->
# agent.send("turn", data)

# Hearts
defaultAgentEvents = ["timeout"]
defaultGameEvents = ["end", "error"]

for agentEvent in defaultAgentEvents.concat(gameClass.AGENT_EVENTS)
for agentEvent in defaultAgentEvents.concat(@builder.agentEvents)
do (agent, agentEvent, position) ->
agent.on agentEvent, (args...) ->
game.handle [agentEvent, position].join("."), args...
for gameEvent in defaultGameEvents.concat(gameClass.EVENTS)
for gameEvent in defaultGameEvents.concat(@builder.events)
do (game, gameEvent, position) ->
game.on [position, gameEvent].join("."), (data) ->
agent.send(gameEvent, data)
Expand Down
15 changes: 8 additions & 7 deletions lib/hearts/builder.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Game = require './game'

#TODO: Remove me
HeartsGame = require './game'

module.exports = class HeartsBuilder
minPlayers: 4
maxPlayers: 4
agentEvents: ["readyForRound", "passCards", "readyForTrick", "playCard", "finishedRound", "finishedGame"]
events: ["roundStarted", "dealt", "received", "turn", "finishedTrick", "roundFinished"]

constructor: (@gameOptions={}) ->
@numberOfPlayers = Game.positions().length
@Game = Game

positions: ->
@Game.positions()
HeartsGame.positions()

createGame: ->
new @Game({heartsMaxPoints: @gameOptions.heartsMaxPoints})
new HeartsGame({heartsMaxPoints: @gameOptions.heartsMaxPoints})

5 changes: 1 addition & 4 deletions lib/hearts/game.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ und = require 'underscore'
Round = require './round'

module.exports = class Game
@AGENT_EVENTS = ["readyForRound", "passCards", "readyForTrick", "playCard", "finishedRound", "finishedGame"]
@EVENTS = ["roundStarted", "dealt", "received", "turn", "finishedTrick", "roundFinished"]
@positions = -> ["north", "east", "south", "west"]

constructor: (options={}) ->
Expand Down Expand Up @@ -187,10 +185,9 @@ Engine = machina.Fsm.extend
if event == "timeout"
logger.error "timeout received", position
@game.abort(position, {type: "timeout", message: "Your action took longer than allowed"})
else if Game.AGENT_EVENTS.indexOf(event) >= 0
@game.abort(position, {type: "outOfSequence", message: "Method call out of sequence"})
else
logger.error "Unexpected event", arguments
@game.abort(position, {type: "outOfSequence", message: "Method call out of sequence"})

initialState: "initialized"

Expand Down

0 comments on commit 879ec17

Please sign in to comment.