-
Notifications
You must be signed in to change notification settings - Fork 43
/
play.coffee
executable file
·43 lines (37 loc) · 1018 Bytes
/
play.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env coffee
#
# This is the script that you can run at the command line to see how
# strategies play against each other.
{BasicAI} = require './basicAI'
{State,tableaux} = require './gameState'
fs = require 'fs'
coffee = require 'coffee-script'
loadStrategy = (filename) ->
ai = new BasicAI()
console.log(filename)
changes = eval coffee.compile(
fs.readFileSync(filename, 'utf-8'),
{bare: yes}
)
for key, value of changes
ai[key] = value
ai
playGame = (filenames) ->
ais = (loadStrategy(filename) for filename in filenames)
st = new State().setUpWithOptions(ais, {
colonies: false
randomizeOrder: true
log: console.log
require: []
})
until st.gameIsOver()
st.doPlay()
result = ([player.ai.toString(), player.getVP(st), player.turnsTaken] for player in st.players)
console.log(result)
result
this.playGame = playGame
args = process.argv[2...]
if args.length > 0
playGame(args)
exports.loadStrategy = loadStrategy
exports.playGame = playGame