Permalink
Browse files

add chooser for builtin strategies to the web interface

  • Loading branch information...
1 parent 4a99504 commit 94495ab2a507c1e3d2f9d46dfbac05c3227220ed @rspeer committed Sep 10, 2011
Showing with 62 additions and 34 deletions.
  1. +1 −0 .gitignore
  2. +1 −0 Makefile
  3. +13 −0 compileStrategies.coffee
  4. 0 playWeb.coffee
  5. +10 −0 web/dominiate.css
  6. +8 −0 web/dominiate.less
  7. +29 −34 web/index.html
View
@@ -8,3 +8,4 @@ geronimoo
.idea
web/playWeb.js
web/multiLog.js
+web/strategies.js
View
@@ -3,6 +3,7 @@ all: css web-coffee
web-coffee:
coffee -c -j web/playWeb.js playWeb.coffee basicAI.coffee cards.coffee gameState.coffee
coffee -c web/multiLog.coffee
+ coffee compileStrategies.coffee
css:
lessc web/dominiate.less web/dominiate.css
View
@@ -0,0 +1,13 @@
+#!/usr/bin/env coffee
+fs = require 'fs'
+files = fs.readdirSync './strategies'
+strategies = {}
+for filename in files
+ suffixPos = filename.length - 7
+ if filename[suffixPos...] == '.coffee'
+ code = fs.readFileSync('./strategies/'+filename, 'utf-8')
+ strategies[filename[...suffixPos]] = code
+
+definition = "strategies = "+JSON.stringify(strategies)+'\n'
+fs.writeFileSync('web/strategies.js', definition)
+
View
0 playWeb.coffee 100755 → 100644
No changes.
View
@@ -32,6 +32,11 @@ body {
left: 5%;
color: #990000;
}
+#p1 select {
+ position: absolute;
+ top: 50px;
+ right: 52%;
+}
#p1 .status {
position: absolute;
top: 57px;
@@ -43,6 +48,11 @@ body {
left: 50%;
color: #000099;
}
+#p2 select {
+ position: absolute;
+ top: 50px;
+ right: 7%;
+}
#p2 .status {
position: absolute;
top: 57px;
View
@@ -55,6 +55,10 @@ body {
left: 5%;
color: @darkred;
}
+ select {
+ .level1;
+ right: 52%;
+ }
.status {
.level1a;
left: 15%;
@@ -66,6 +70,10 @@ body {
left: 50%;
color: @darkblue;
}
+ select {
+ .level1;
+ right: 7%;
+ }
.status {
.level1a;
left: 60%;
View
@@ -16,47 +16,22 @@ <h2 class="tagline">A simulator for Dominion strategies.</h2>
<div id="p1">
<h2>Player 1</h2>
+<select name="loadStrategy1" id="loadStrategy1">
+</select>
<div class="status" id="status1"></div>
-<pre id="editor-left"># A pure money strategy.
-{
- name: 'BigMoney'
- gainPriority: (state) -&gt; [
- "Colony" if state.current.countInDeck("Platinum") &gt; 0
- "Province" if state.countInSupply("Colony") &lt;= 6 \
- or state.countInSupply("Province") &lt;= 6
- "Duchy" if 0 &lt; state.gainsToEndGame() &lt;= 5
- "Estate" if 0 &lt; state.gainsToEndGame() &lt;= 2
- "Platinum"
- "Gold"
- "Silver"
- "Copper" if state.gainsToEndGame() &lt;= 3
- null
- ]
-}
+<pre id="editor-left">
</pre>
</div>
<div id="p2">
<h2>Player 2</h2>
+<select name="loadStrategy2" id="loadStrategy2">
+</select>
<div class="status" id="status2"></div>
-<pre id="editor-right"># Buys random cards (of the highest cost available) like a noob.
-{
- name: 'SillyAI'
- gainPriority: (state) -&gt;
- cards = []
- for card, count of state.supply
- if state.cardInfo[card].cost &gt; 0
- cards.push(card)
- effectiveCost = (card) -&gt;
- [coins, potions] = state.cardInfo[card].getCost(state)
- coins + potions*2 + Math.random()
-
- cards.sort( (c1, c2) -&gt;
- effectiveCost(c2) - effectiveCost(c1)
- )
- cards
-}</pre>
+<pre id="editor-right">
+</pre>
</div>
+
<div id="layoutSeparator"></div>
<form id="gameControls">
<ul class="inputs-list">
@@ -107,7 +82,8 @@ <h2 class="tagline">A simulator for Dominion strategies.</h2>
<script src="libs/jquery-1.6.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="libs/zeroTimeout.js" type="text/javascript" charset="utf-8"></script>
<script src="playWeb.js" type="text/javascript" charset="utf-8"></script>
-<script src ="multiLog.js" type="text/javascript"></script>
+<script src="multiLog.js" type="text/javascript"></script>
+<script src="strategies.js" type="text/javascript"></script>
<script type="text/coffeescript">
$ = jQuery
@@ -156,6 +132,25 @@ <h2 class="tagline">A simulator for Dominion strategies.</h2>
}
compileAndPlay(scripts, singleGameResult, errorHandlers, options)
+ strategyElements = ['<option></option>']
+ for name of strategies
+ strategyElements.push("<option>#{name}</option>")
+ strategyElements.sort()
+
+ $('#loadStrategy1').html(strategyElements.join(''))
+ $('#loadStrategy2').html(strategyElements.join(''))
+ $('#loadStrategy1').change =>
+ choice = $('#loadStrategy1 option:selected').text()
+ strategy = strategies[choice] ? ''
+ leftEd.setValue(strategy)
+ $('#loadStrategy2').change =>
+ choice = $('#loadStrategy2 option:selected').text()
+ strategy = strategies[choice] ? ''
+ rightEd.setValue(strategy)
+
+ $('#loadStrategy1').val('BigMoney').change()
+ $('#loadStrategy2').val('SillyAI').change()
+
</script>
</body>

0 comments on commit 94495ab

Please sign in to comment.