X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=agents%2Fvixen%2Fvixen.py;h=669df8362057e136c6ff239991de6c432233d9d7;hp=a4010b1d12665b80a0f37cd2cd514bc446babd0e;hb=36bffb1754deb18b223a3206daa2478568675909;hpb=9e4bc3c0b49f5e2796a62c8fa91fe0ec78d96af2 diff --git a/agents/vixen/vixen.py b/agents/vixen/vixen.py index a4010b1..669df83 100755 --- a/agents/vixen/vixen.py +++ b/agents/vixen/vixen.py @@ -22,7 +22,6 @@ from path import * class Vixen(BasicAI): " Python based AI, improves upon Asmodeus by taking into account probabilities, and common paths " def __init__(self): - #sys.stderr.write("Vixen initialised...\n") BasicAI.__init__(self) @@ -45,20 +44,27 @@ class Vixen(BasicAI): if unit.mobile() == False: continue - scores = {"LEFT":0, "RIGHT":0, "UP":0, "DOWN":0} + scores = {"LEFT":None, "RIGHT":None, "UP":None, "DOWN":None} - for target in self.enemyUnits: if target == unit: continue path = PathFinder().pathFind((unit.x, unit.y), (target.x, target.y), self.board) if path == False or len(path) == 0: continue - #moveList.append({"unit":unit, "direction":path[0], "score":self.CalculateScore(unit, target, path)}) + if scores[path[0]] == None: + scores[path[0]] = 0 + scores[path[0]] += self.CalculateScore(unit, target, path) - bestScore = sorted(scores.items(), key = lambda e : e[1], reverse=True)[0] - moveList.append({"unit":unit, "direction":bestScore[0], "score":bestScore[1]}) + for d in scores.keys(): + if scores[d] == None: + del scores[d] + + if len(scores.items()) > 0: + bestScore = sorted(scores.items(), key = lambda e : e[1], reverse=True)[0] + moveList.append({"unit":unit, "direction":bestScore[0], "score":bestScore[1]}) + if len(moveList) <= 0: @@ -87,7 +93,7 @@ class Vixen(BasicAI): def CalculateScore(self, attacker, defender, path): p = move(attacker.x, attacker.y, path[0], 1) if p[0] < 0 or p[0] >= len(self.board) or p[1] < 0 or p[1] >= len(self.board[p[0]]): - return -100.0 + return -1000.0 total = 0.0 count = 0.0