Commits

David Jones committed d15ff10

made tcp.py into a looping client

Comments (0)

Files changed (1)

 #!/usr/bin/env python
+import time
+import sys
+import threading
+import re
+import random
 
 from socket import socket, AF_INET, SOCK_STREAM
-import time, sys
-import threading
+
 from engine import BotThread
 from PlanetWars import PlanetWars
 
-import re
+
 
 class FailedToConnect(Exception): pass
 
                       default=None)
     parser.add_option("-v", "--verbose", dest="verbose",
                       action="store_true")
+
+
+    parser.add_option("--num_games", dest="num_games",
+                      type="int",
+                      default=1)
+    parser.add_option("--min_wait", dest="min_wait",
+                      type="int",
+                      default = 15)
+    parser.add_option("--max_wait", dest="max_wait",
+                      type="int",
+                      default = 45)
+    
+
     
     (options, args) = parser.parse_args()
     if len(args) < 4:
     user = args[2]
     command = args[3]
 
-    tcp(ip, port, user, command, options)
+    count = 0
+    max_wait = max(options.min_wait, options.max_wait) + 1
+    min_wait = min(options.min_wait, options.max_wait)
+    while True:
+        tcp(ip, port, user, command, options)
+        count += 1
+        if count >= options.num_games: break
+        wait = random.randrange(min_wait, max_wait)
+        print
+        print "time is now: %s, waiting %d seconds" % (time.asctime(), wait)
+        time.sleep(wait)
+