Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 54 lines (46 sloc) 1.645 kb
83a4d1f @rspeer layout update for the Web
authored
1 # This is the main entry point for playing strategies against each
2 # other on the Web.
4af5c6e @rspeer made a score counter
authored
3 #
4 # Needs more documentation.
18eb062 @rspeer separate compiling from playing
authored
5
c5656b3 @rspeer add actual error handling
authored
6 compileStrategies = (scripts, errorHandler) ->
838f077 @rspeer IT'S ALIVE. The Web version can now play complete games of Dominion.
authored
7 strategies = []
4af5c6e @rspeer made a score counter
authored
8 usedNames = []
838f077 @rspeer IT'S ALIVE. The Web version can now play complete games of Dominion.
authored
9 for i in [0...scripts.length]
10 try
11 strategy = CoffeeScript.eval(scripts[i], {bare: yes})
4af5c6e @rspeer made a score counter
authored
12 while strategy.name in usedNames
13 strategy.name += "Clone"
14 usedNames.push(strategy.name)
838f077 @rspeer IT'S ALIVE. The Web version can now play complete games of Dominion.
authored
15 strategies.push(strategy)
16 catch e
c5656b3 @rspeer add actual error handling
authored
17 errorHandler(e)
18eb062 @rspeer separate compiling from playing
authored
18 return null
19 return strategies
838f077 @rspeer IT'S ALIVE. The Web version can now play complete games of Dominion.
authored
20
83a4d1f @rspeer layout update for the Web
authored
21 makeStrategy = (changes) ->
22 ai = new BasicAI()
23 for key, value of changes
24 ai[key] = value
25 ai
26
26c3db2 @rspeer paginated game logs
authored
27 playGame = (strategies, options, ret) ->
83a4d1f @rspeer layout update for the Web
authored
28 ais = (makeStrategy(item) for item in strategies)
4af5c6e @rspeer made a score counter
authored
29
30 # Take note of the player names, in order, while they're
31 # still in this order.
5e27cd2 @rspeer made the Web interface show graphs
authored
32 options.tracker.setPlayers(ai.name for ai in ais)
33 options.grapher.setPlayers(ai.name for ai in ais)
4af5c6e @rspeer made a score counter
authored
34
1e69212 @rspeer make the Web page use the new setup function
authored
35 state = new State().setUpWithOptions(ais, options)
26c3db2 @rspeer paginated game logs
authored
36 ret ?= options.log
83a4d1f @rspeer layout update for the Web
authored
37
6f1c227 @rspeer added fast mode
authored
38 until state.gameIsOver()
39 try
40 state.doPlay()
41 if state.phase == 'buy' and (not state.extraturn) and options.grapher?
42 options.grapher.recordMoney(state.current.ai.name, state.current.turnsTaken, state.current.coins)
43 if state.phase == 'cleanup' and (not state.extraturn) and options.grapher?
44 options.grapher.recordVP(state.current.ai.name, state.current.turnsTaken, state.current.getVP(state))
45 catch err
46 errorHandler = options.errorHandler ? (alert ? console.log)
47 errorHandler(err.message)
48 window.donePlaying()
2286cc3 @aiannacc Many new strategies, esp. Rebuild variants; bug fix to Rogue, errors no ...
aiannacc authored
49 throw err
6f1c227 @rspeer added fast mode
authored
50 ret(state)
51
18eb062 @rspeer separate compiling from playing
authored
52 this.compileStrategies = compileStrategies
53 this.playGame = playGame
Something went wrong with that request. Please try again.