Permalink
Browse files

85 bestplanets(15,40) - added files

  • Loading branch information...
1 parent 85d92c8 commit 0091192e924ebf7c38cfd46e8cae2d57cdcb26fa @apinkin committed Sep 28, 2010
Showing with 1,131 additions and 0 deletions.
  1. +317 −0 MyBot_82.py
  2. +318 −0 MyBot_83.py
  3. +322 −0 MyBot_85.py
  4. +51 −0 batch.sh
  5. +51 −0 best_batch.sh
  6. +63 −0 parse_game_state_url.py
  7. +3 −0 prev.sh
  8. +6 −0 replay.sh
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,51 @@
+#!/bin/bash
+ for file in example_bots/*.jar
+
+ do
+ player_1_counter=0
+ player_1_turn_counter=0
+
+ player_2_counter=0
+ player_2_turn_counter=0
+
+ draw_counter=0
+
+ maps_played=0
+
+ echo "Bot: $file"
+ for i in {1..100}
+ do
+ RES=`java -jar tools/PlayGame.jar maps/map$i.txt 1000 200 log.txt "java -jar $file" "python MyBot.py" 2>&1 | tail -n 3 | grep "Turn\|Player"`
+
+ TURN=`echo $RES | grep -i turn | sed 's/.*urn \([0-9]*\).*/\1/'`
+
+ RES2=`echo $RES | grep -i player | sed 's/.*ayer \([0-9]*\).*/\1/'`
+
+ if [ "$RES2" = "1" ] ; then
+ player_1_counter=`expr $player_1_counter + 1`
+ player_1_turn_counter=`expr $player_1_turn_counter + $TURN`
+ else
+ if [ "$RES2" = "2" ] ; then
+ player_2_counter=`expr $player_2_counter + 1`
+ player_2_turn_counter=`expr $player_2_turn_counter + $TURN`
+ else
+ draw_counter=`expr $draw_counter + 1`
+ fi
+ fi
+
+ maps_played=`expr $maps_played + 1`
+ #echo "map: $i - Winner: $RES2 - Turns: $TURN"
+ #sleep 1
+ done
+ if [ "$player_2_counter" != "0" ] ; then
+ avg_player_2_turn_counter=`expr $player_2_turn_counter / $player_2_counter`
+ fi
+ if [ "$player_1_counter" != "0" ] ; then
+ avg_player_1_turn_counter=`expr $player_1_turn_counter / $player_1_counter`
+ fi
+
+
+ echo "won against $file : $player_2_counter/$maps_played, avg turns: $avg_player_2_turn_counter"
+ echo "lost against $file : $player_1_counter/$maps_played, avg turns: $avg_player_1_turn_counter"
+ echo "tied against $file : $draw_counter/$maps_played"
+ done
View
@@ -0,0 +1,51 @@
+#!/bin/bash
+ for file in MyBot_85_*.py
+
+ do
+ player_1_counter=0
+ player_1_turn_counter=0
+
+ player_2_counter=0
+ player_2_turn_counter=0
+
+ draw_counter=0
+
+ maps_played=0
+
+ echo "Bot: $file"
+ for i in {1..100}
+ do
+ RES=`java -jar tools/PlayGame.jar maps/map$i.txt 10000 200 log.txt "python MyBot_82.py" "python $file" 2>&1 | tail -n 3 | grep "Turn\|Player"`
+
+ TURN=`echo $RES | grep -i turn | sed 's/.*urn \([0-9]*\).*/\1/'`
+
+ RES2=`echo $RES | grep -i player | sed 's/.*ayer \([0-9]*\).*/\1/'`
+
+ if [ "$RES2" = "1" ] ; then
+ player_1_counter=`expr $player_1_counter + 1`
+ player_1_turn_counter=`expr $player_1_turn_counter + $TURN`
+ else
+ if [ "$RES2" = "2" ] ; then
+ player_2_counter=`expr $player_2_counter + 1`
+ player_2_turn_counter=`expr $player_2_turn_counter + $TURN`
+ else
+ draw_counter=`expr $draw_counter + 1`
+ fi
+ fi
+
+ maps_played=`expr $maps_played + 1`
+ #echo "map: $i - Winner: $RES2 - Turns: $TURN"
+ sleep 1
+ done
+ if [ "$player_2_counter" != "0" ] ; then
+ avg_player_2_turn_counter=`expr $player_2_turn_counter / $player_2_counter`
+ fi
+ if [ "$player_1_counter" != "0" ] ; then
+ avg_player_1_turn_counter=`expr $player_1_turn_counter / $player_1_counter`
+ fi
+
+
+ echo "won against $file : $player_2_counter/$maps_played, avg turns: $avg_player_2_turn_counter"
+ echo "lost against $file : $player_1_counter/$maps_played, avg turns: $avg_player_1_turn_counter"
+ echo "tied against $file : $draw_counter/$maps_played"
+ done
View
@@ -0,0 +1,63 @@
+import sys
+import urllib2
+
+"""Code, with no error checking, to parse a PlanetWars game into
+ a replayable code file. Argument is game page URL."""
+def main(argv):
+ input_url = argv[0]
+ req = urllib2.Request(input_url)
+ response = urllib2.urlopen(req)
+ s = response.read()
+ PLAYBACK_START = "playback_string="
+ PLAYBACK_END = "\\n"
+ start_index = s.find(PLAYBACK_START) + len(PLAYBACK_START)
+ end_index = s.find(PLAYBACK_END, start_index)
+ if end_index == -1:
+ end_index = s.find('"', start_index)
+ s = s[start_index:end_index]
+ planets, moves = s.split("|")
+
+ data = []
+ for p in planets.split(":"):
+ line = p.split(",")
+ if len(line) != 5:
+ print "bad line: %s" % p
+ x,y,o,n,r = line
+ data.append(line)
+
+ np = len(data)
+
+ moves = moves.split(":")
+
+ print("# turn 1")
+ for i in xrange(np):
+ x,y,o,n,r = data[i]
+ print("P %s %s %s %s %s" % (x,y,o,n,r))
+ print("go\n")
+
+ for (turn,f) in enumerate(moves):
+ print("# turn: %d" % (turn + 2))
+ xs = f.split(",")
+ for i in xrange(np):
+ x,y,o,n,r = data[i]
+ tmp = xs[i].strip().split(".")
+ if len(tmp) < 2:
+ print "error here: ", xs[i]
+ break
+ o,n = tmp
+ print("P %s %s %s %s %s" % (x,y,o,n,r))
+ for j in xrange(np,len(xs)):
+ u = xs[j].split(".")
+ if len(u) != 6:
+ #print "er: ", xs[j]
+ continue
+ o,n,s,d,t,r = u
+ print("F %s %s %s %s %s %s" % (o,n,s,d,t,r))
+ print("go\n")
+
+if __name__ == "__main__":
+ argv = sys.argv[1:]
+ main(argv)
+
+
+
View
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+java -jar tools/PlayGame.jar maps/map$1.txt 10000 200 log.txt "python MyBot_82.py --log old.log" "python MyBot.py --log current.log" | python visualizer/visualize_localy.py
View
@@ -0,0 +1,6 @@
+#!/bin/bash
+# Re-playes the game by parsing it from a web page such as http://ai-contest.com/visualizer.php?game_id=4607884
+# pass game URL as a parameter to this script
+
+python parse_game_state_url.py $1 | python MyBot.py --log MyBot.log
+

0 comments on commit 0091192

Please sign in to comment.