summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2015-08-31 22:42:56 +0200
committerFlorian Jung <flo@windfisch.org>2015-08-31 22:42:56 +0200
commitc13c6ca7f3d2ed069d8b0d9af4a09ea2c952d845 (patch)
tree439cbf436d0b749d6e2af193fcdbca07f061e5ac
parent2371258d8eb6da11a7c9c5669c9f499ba44bf02a (diff)
--nogui flag. closes #14
-rw-r--r--main.py13
-rw-r--r--strategy.py20
2 files changed, 23 insertions, 10 deletions
diff --git a/main.py b/main.py
index d07b6b8..b9fc832 100644
--- a/main.py
+++ b/main.py
@@ -7,12 +7,21 @@ import sys
import math
import time
import random
-import gui
+import nogui as gui # might be overridden later.
import stats
from subscriber import EnhancingSubscriber
from interval_utils import *
from strategy import *
+if "--nogui" in sys.argv:
+ sys.argv.remove("--nogui")
+else:
+ try:
+ import gui
+ except:
+ print("ERROR: could not import gui... running without gui.")
+
+
# global vars
sub = EnhancingSubscriber()
c = client.Client(sub)
@@ -53,7 +62,7 @@ c.player.nick=nick
gui.set_client(c)
# initialize strategy
-strategy = Strategy(c)
+strategy = Strategy(c, gui)
autorespawn_counter = 60
diff --git a/strategy.py b/strategy.py
index 67b3da9..900cf8f 100644
--- a/strategy.py
+++ b/strategy.py
@@ -1,20 +1,24 @@
import math
from interval_utils import *
-import gui
import random
+import nogui
friendly_players=["Windfisch","windfisch","Cyanide","cyanide"] +\
["Midna","Nayru","Farore","Din","Ezelo","Navi","Zelda","Tetra","Link","Ciela","Linebeck","Salia","Epona","Shiek"] +\
["Vaati","Ganon","Ganondorf","Ghirahim","Agahnim"]
class Strategy:
- def __init__(self, c):
+ def __init__(self, c, gui=None):
self.target = (0,0)
self.has_target = False
self.target_cell = None
self.color = (0,0,0)
self.c = c
self.do_approach_friends = True
+ if gui != None:
+ self.gui = gui
+ else:
+ self.gui = nogui
def get_my_smallest(self):
return sorted(self.c.player.own_cells, key = lambda x: x.mass)[0]
@@ -133,14 +137,14 @@ class Strategy:
print("friend too small")
friend_to_feed = None
if friend_to_feed:
- gui.hilight_cell(friend_to_feed, (255,255,255),(255,127,127),30)
+ self.gui.hilight_cell(friend_to_feed, (255,255,255),(255,127,127),30)
self.target_cell = friend_to_feed
self.has_target = True
if self.do_approach_friends:
for c in self.c.player.own_cells:
- gui.hilight_cell(c, (255,255,255), (255,127,127), 20)
+ self.gui.hilight_cell(c, (255,255,255), (255,127,127), 20)
# can this cell feed that cell?
# "False" means "No, definitely not"
@@ -170,7 +174,7 @@ class Strategy:
good_intervals = []
for feedable in possibly_feedable_cells:
- gui.hilight_cell(feedable, (255,192,127), (127,127,255))
+ self.gui.hilight_cell(feedable, (255,192,127), (127,127,255))
if feedable not in friendly_cells:
break
@@ -181,7 +185,7 @@ class Strategy:
success_rate += area / (2*10*math.pi/180) / len(list(self.c.player.own_cells))
- gui.draw_bar(((100,40),(500,24)), success_rate, thresh=.98, color=(0,0,127))
+ self.gui.draw_bar(((100,40),(500,24)), success_rate, thresh=.98, color=(0,0,127))
if success_rate >= 0.98:
self.c.send_shoot()
@@ -237,7 +241,7 @@ class Strategy:
# a bit of debugging information
for i in forbidden_intervals:
- gui.draw_arc(self.c.player.center, self.c.player.total_size+10, i, (255,0,255))
+ self.gui.draw_arc(self.c.player.center, self.c.player.total_size+10, i, (255,0,255))
# if however there's no enemy to avoid, try to feed a friend. or chase food or jizz randomly around
else:
@@ -270,6 +274,6 @@ class Strategy:
# more debugging
- gui.draw_line(self.c.player.center, self.target, self.color)
+ self.gui.draw_line(self.c.player.center, self.target, self.color)
return self.target