Permalink
Browse files

Second commit

  • Loading branch information...
1 parent 0ff02df commit def26efd755b71dee0fbb82318325ac59a468f37 Roger Braun committed Sep 13, 2010
Showing with 149,170 additions and 1 deletion.
  1. +74 −0 MyBot.py
  2. +217 −0 PlanetWars.py
  3. +21 −0 README.txt
  4. BIN TCP.class
  5. +108 −0 TCP.java
  6. BIN example_bots/BullyBot.jar
  7. +65 −0 example_bots/BullyBot.java
  8. BIN example_bots/DualBot.jar
  9. +86 −0 example_bots/DualBot.java
  10. +65 −0 example_bots/ExpandBot.java
  11. +92 −0 example_bots/Fleet.java
  12. +77 −0 example_bots/Planet.java
  13. +319 −0 example_bots/PlanetWars.java
  14. BIN example_bots/ProspectorBot.jar
  15. +65 −0 example_bots/ProspectorBot.java
  16. BIN example_bots/RageBot.jar
  17. +52 −0 example_bots/RageBot.java
  18. BIN example_bots/RandomBot.jar
  19. +58 −0 example_bots/RandomBot.java
  20. +115,450 −0 fleet.log
  21. +1 −0 log.txt
  22. +23 −0 maps/map1.txt
  23. +23 −0 maps/map10.txt
  24. +23 −0 maps/map100.txt
  25. +23 −0 maps/map11.txt
  26. +23 −0 maps/map12.txt
  27. +23 −0 maps/map13.txt
  28. +23 −0 maps/map14.txt
  29. +23 −0 maps/map15.txt
  30. +23 −0 maps/map16.txt
  31. +23 −0 maps/map17.txt
  32. +23 −0 maps/map18.txt
  33. +23 −0 maps/map19.txt
  34. +23 −0 maps/map2.txt
  35. +23 −0 maps/map20.txt
  36. +23 −0 maps/map21.txt
  37. +23 −0 maps/map22.txt
  38. +23 −0 maps/map23.txt
  39. +23 −0 maps/map24.txt
  40. +23 −0 maps/map25.txt
  41. +23 −0 maps/map26.txt
  42. +23 −0 maps/map27.txt
  43. +23 −0 maps/map28.txt
  44. +23 −0 maps/map29.txt
  45. +23 −0 maps/map3.txt
  46. +23 −0 maps/map30.txt
  47. +23 −0 maps/map31.txt
  48. +23 −0 maps/map32.txt
  49. +23 −0 maps/map33.txt
  50. +23 −0 maps/map34.txt
  51. +23 −0 maps/map35.txt
  52. +23 −0 maps/map36.txt
  53. +23 −0 maps/map37.txt
  54. +23 −0 maps/map38.txt
  55. +23 −0 maps/map39.txt
  56. +23 −0 maps/map4.txt
  57. +23 −0 maps/map40.txt
  58. +23 −0 maps/map41.txt
  59. +23 −0 maps/map42.txt
  60. +23 −0 maps/map43.txt
  61. +23 −0 maps/map44.txt
  62. +23 −0 maps/map45.txt
  63. +23 −0 maps/map46.txt
  64. +23 −0 maps/map47.txt
  65. +23 −0 maps/map48.txt
  66. +23 −0 maps/map49.txt
  67. +23 −0 maps/map5.txt
  68. +23 −0 maps/map50.txt
  69. +23 −0 maps/map51.txt
  70. +23 −0 maps/map52.txt
  71. +23 −0 maps/map53.txt
  72. +23 −0 maps/map54.txt
  73. +23 −0 maps/map55.txt
  74. +23 −0 maps/map56.txt
  75. +23 −0 maps/map57.txt
  76. +23 −0 maps/map58.txt
  77. +23 −0 maps/map59.txt
  78. +23 −0 maps/map6.txt
  79. +23 −0 maps/map60.txt
  80. +23 −0 maps/map61.txt
  81. +23 −0 maps/map62.txt
  82. +23 −0 maps/map63.txt
  83. +23 −0 maps/map64.txt
  84. +23 −0 maps/map65.txt
  85. +23 −0 maps/map66.txt
  86. +23 −0 maps/map67.txt
  87. +23 −0 maps/map68.txt
  88. +23 −0 maps/map69.txt
  89. +23 −0 maps/map7.txt
  90. +23 −0 maps/map70.txt
  91. +23 −0 maps/map71.txt
  92. +23 −0 maps/map72.txt
  93. +23 −0 maps/map73.txt
  94. +23 −0 maps/map74.txt
  95. +23 −0 maps/map75.txt
  96. +23 −0 maps/map76.txt
  97. +23 −0 maps/map77.txt
  98. +23 −0 maps/map78.txt
  99. +23 −0 maps/map79.txt
  100. +23 −0 maps/map8.txt
  101. +23 −0 maps/map80.txt
  102. +23 −0 maps/map81.txt
  103. +23 −0 maps/map82.txt
  104. +23 −0 maps/map83.txt
  105. +23 −0 maps/map84.txt
  106. +23 −0 maps/map85.txt
  107. +23 −0 maps/map86.txt
  108. +23 −0 maps/map87.txt
  109. +23 −0 maps/map88.txt
  110. +23 −0 maps/map89.txt
  111. +23 −0 maps/map9.txt
  112. +23 −0 maps/map90.txt
  113. +23 −0 maps/map91.txt
  114. +23 −0 maps/map92.txt
  115. +23 −0 maps/map93.txt
  116. +23 −0 maps/map94.txt
  117. +23 −0 maps/map95.txt
  118. +23 −0 maps/map96.txt
  119. +23 −0 maps/map97.txt
  120. +23 −0 maps/map98.txt
  121. +23 −0 maps/map99.txt
  122. +1 −1 mybot2.rb
  123. +2 −0 mybot2.sh
  124. +53 −0 mybot3.rb
  125. +2 −0 mybot3.sh
  126. +93 −0 mybot4.rb
  127. +2 −0 mybot4.sh
  128. +153 −0 mybot5.rb
  129. +2 −0 mybot5.sh
  130. +29,566 −0 orders.log
  131. 0 rubyerr.log
  132. BIN tcp
  133. +222 −0 tcp.c
  134. 0 test.haml
  135. +24 −0 test.sh
  136. BIN tools/PlayGame.jar
  137. BIN tools/ShowGame.jar
View
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+#
+
+"""
+// The DoTurn function is where your code goes. The PlanetWars object contains
+// the state of the game, including information about all planets and fleets
+// that currently exist. Inside this function, you issue orders using the
+// pw.IssueOrder() function. For example, to send 10 ships from planet 3 to
+// planet 8, you would say pw.IssueOrder(3, 8, 10).
+//
+// There is already a basic strategy in place here. You can use it as a
+// starting point, or you can throw it out entirely and replace it with your
+// own. Check out the tutorials and articles on the contest website at
+// http://www.ai-contest.com/resources.
+"""
+
+from PlanetWars import PlanetWars
+
+def DoTurn(pw):
+ # (1) If we currently have a fleet in flight, just do nothing.
+ if len(pw.MyFleets()) >= 1:
+ return
+ # (2) Find my strongest planet.
+ source = -1
+ source_score = -999999.0
+ source_num_ships = 0
+ my_planets = pw.MyPlanets()
+ for p in my_planets:
+ score = float(p.NumShips())
+ if score > source_score:
+ source_score = score
+ source = p.PlanetID()
+ source_num_ships = p.NumShips()
+
+ # (3) Find the weakest enemy or neutral planet.
+ dest = -1
+ dest_score = -999999.0
+ not_my_planets = pw.NotMyPlanets()
+ for p in not_my_planets:
+ score = 1.0 / (1 + p.NumShips())
+ if score > dest_score:
+ dest_score = score
+ dest = p.PlanetID()
+
+ # (4) Send half the ships from my strongest planet to the weakest
+ # planet that I do not own.
+ if source >= 0 and dest >= 0:
+ num_ships = source_num_ships / 2
+ pw.IssueOrder(source, dest, num_ships)
+
+
+def main():
+ map_data = ''
+ while(True):
+ current_line = raw_input()
+ if len(current_line) >= 2 and current_line.startswith("go"):
+ pw = PlanetWars(map_data)
+ DoTurn(pw)
+ pw.FinishTurn()
+ map_data = ''
+ else:
+ map_data += current_line + '\n'
+
+
+if __name__ == '__main__':
+ try:
+ import psyco
+ psyco.full()
+ except ImportError:
+ pass
+ try:
+ main()
+ except KeyboardInterrupt:
+ print 'ctrl-c, leaving ...'
View
@@ -0,0 +1,217 @@
+#!/usr/bin/env python
+#
+
+from math import ceil, sqrt
+from sys import stdout
+
+
+class Fleet:
+ def __init__(self, owner, num_ships, source_planet, destination_planet, \
+ total_trip_length, turns_remaining):
+ self._owner = owner
+ self._num_ships = num_ships
+ self._source_planet = source_planet
+ self._destination_planet = destination_planet
+ self._total_trip_length = total_trip_length
+ self._turns_remaining = turns_remaining
+
+ def Owner(self):
+ return self._owner
+
+ def NumShips(self):
+ return self._num_ships
+
+ def SourcePlanet(self):
+ return self._source_planet
+
+ def DestinationPlanet(self):
+ return self._destination_planet
+
+ def TotalTripLength(self):
+ return self._total_trip_length
+
+ def TurnsRemaining(self):
+ return self._turns_remaining
+
+
+class Planet:
+ def __init__(self, planet_id, owner, num_ships, growth_rate, x, y):
+ self._planet_id = planet_id
+ self._owner = owner
+ self._num_ships = num_ships
+ self._growth_rate = growth_rate
+ self._x = x
+ self._y = y
+
+ def PlanetID(self):
+ return self._planet_id
+
+ def Owner(self, new_owner=None):
+ if new_owner == None:
+ return self._owner
+ self._owner = new_owner
+
+ def NumShips(self, new_num_ships=None):
+ if new_num_ships == None:
+ return self._num_ships
+ self._num_ships = new_num_ships
+
+ def GrowthRate(self):
+ return self._growth_rate
+
+ def X(self):
+ return self._x
+
+ def Y(self):
+ return self._y
+
+ def AddShips(self, amount):
+ self._num_ships += amount
+
+ def RemoveShips(self, amount):
+ self._num_ships -= amount
+
+
+class PlanetWars:
+ def __init__(self, gameState):
+ self._planets = []
+ self._fleets = []
+ self.ParseGameState(gameState)
+
+ def NumPlanets(self):
+ return len(self._planets)
+
+ def GetPlanet(self, planet_id):
+ return self._planets[planet_id]
+
+ def NumFleets(self):
+ return len(self._fleets)
+
+ def GetFleet(self, fleet_id):
+ return self._fleets[fleet_id]
+
+ def Planets(self):
+ return self._planets
+
+ def MyPlanets(self):
+ r = []
+ for p in self._planets:
+ if p.Owner() != 1:
+ continue
+ r.append(p)
+ return r
+
+ def NeutralPlanets(self):
+ r = []
+ for p in self._planets:
+ if p.Owner() != 0:
+ continue
+ r.append(p)
+ return r
+
+ def EnemyPlanets(self):
+ r = []
+ for p in self._planets:
+ if p.Owner() <= 1:
+ continue
+ r.append(p)
+ return r
+
+ def NotMyPlanets(self):
+ r = []
+ for p in self._planets:
+ if p.Owner() == 1:
+ continue
+ r.append(p)
+ return r
+
+ def Fleets(self):
+ return self._fleets
+
+ def MyFleets(self):
+ r = []
+ for f in self._fleets:
+ if f.Owner() != 1:
+ continue
+ r.append(f)
+ return r
+
+ def EnemyFleets(self):
+ r = []
+ for f in self._fleets:
+ if f.Owner() <= 1:
+ continue
+ r.append(f)
+ return r
+
+ def ToString(self):
+ s = ''
+ for p in self._planets:
+ s += "P %f %f %d %d %d\n" % \
+ (p.X(), p.Y(), p.Owner(), p.NumShips(), p.GrowthRate())
+ for f in self._fleets:
+ s += "F %d %d %d %d %d %d\n" % \
+ (f.Owner(), f.NumShips(), f.SourcePlanet(), f.DestinationPlanet(), \
+ f.TotalTripLength(), f.TurnsRemaining())
+ return s
+
+ def Distance(self, source_planet, destination_planet):
+ source = self._planets[source_planet]
+ destination = self._planets[destination_planet]
+ dx = source.X() - destination.X()
+ dy = source.Y() - destination.Y()
+ return int(ceil(sqrt(dx * dx + dy * dy)))
+
+ def IssueOrder(self, source_planet, destination_planet, num_ships):
+ stdout.write("%d %d %d\n" % \
+ (source_planet, destination_planet, num_ships))
+ stdout.flush()
+
+ def IsAlive(self, player_id):
+ for p in self._planets:
+ if p.Owner() == player_id:
+ return True
+ for f in self._fleets:
+ if f.Owner() == player_id:
+ return True
+ return False
+
+ def ParseGameState(self, s):
+ self._planets = []
+ self._fleets = []
+ lines = s.split("\n")
+ planet_id = 0
+
+ for line in lines:
+ line = line.split("#")[0] # remove comments
+ tokens = line.split(" ")
+ if len(tokens) == 1:
+ continue
+ if tokens[0] == "P":
+ if len(tokens) != 6:
+ return 0
+ p = Planet(planet_id, # The ID of this planet
+ int(tokens[3]), # Owner
+ int(tokens[4]), # Num ships
+ int(tokens[5]), # Growth rate
+ float(tokens[1]), # X
+ float(tokens[2])) # Y
+ planet_id += 1
+ self._planets.append(p)
+ elif tokens[0] == "F":
+ if len(tokens) != 7:
+ return 0
+ f = Fleet(int(tokens[1]), # Owner
+ int(tokens[2]), # Num ships
+ int(tokens[3]), # Source
+ int(tokens[4]), # Destination
+ int(tokens[5]), # Total trip length
+ int(tokens[6])) # Turns remaining
+ self._fleets.append(f)
+ else:
+ return 0
+ return 1
+
+ def FinishTurn(self):
+ stdout.write("go\n")
+ stdout.flush()
View
@@ -0,0 +1,21 @@
+The files in this package are part of a starter package from the Google AI
+Challenge. The Google AI Challenge is an Artificial Intelligence programming
+contest. You can get more information by visiting www.ai-contest.com.
+
+The entire contents of this starter package are released under the Apache
+license as is all code related to the Google AI Challenge. See
+code.google.com/p/ai-contest/ for more details.
+
+There are a bunch of tutorials on the ai-contest.com website that tell you
+what to do with the contents of this starter package. For the impatient, here
+is a brief summary.
+ * In the root directory, there are a bunch of code files. These are a simple
+ working contest entry that employs a basic strategy. These are meant to be
+ used as a starting point for you to start writing your own entry.
+ Alternatively, you can just package up the starter package as-is and submit
+ it on the website.
+ * The tools directory contains a game engine and visualizer. This is meant
+ to be used to test your bot. See the relevant tutorials on the website for
+ information about how to use the tools.
+ * The example_bots directory contains some sample bots for you to test your
+ own bot against.
View
Binary file not shown.
Oops, something went wrong.

0 comments on commit def26ef

Please sign in to comment.