X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=agents%2Fvixen%2Fvixen.py;h=669df8362057e136c6ff239991de6c432233d9d7;hp=7c44aa33f46b67c70397f0545fa7b0266baf3ddb;hb=36bffb1754deb18b223a3206daa2478568675909;hpb=4d45373e18e4d5dc84adb373cdc9000f83dfe38a diff --git a/agents/vixen/vixen.py b/agents/vixen/vixen.py index 7c44aa3..669df83 100755 --- a/agents/vixen/vixen.py +++ b/agents/vixen/vixen.py @@ -22,15 +22,14 @@ 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) #self.bombScores = {'1' : -0.9 , '2' : -0.8 , '3' : -0.5 , '4' : 0.1, '5' : 0.1, '6' : 0.3, '7' : 0.7, '8' : 1 , '9' : 0.6, 's' : 0} #self.bombScores = {'1' : -0.9 , '2' : -0.8 , '3' : -0.5 , '4' : -0.5, '5' : -0.4, '6' : -0.5, '7' : -0.2, '8' : 1.0 , '9' : -0.1, 's' : -0.2} - self.suicideScores = {'1' : -0.5 , '2' : -0.4 , '3' : -0.35, '4' : -0.25, '5' : -0.2, '6' : 0.0, '7' : 0.1, '8' : -1.0 , '9' : 0.0, 's' : -0.4} + self.suicideScores = {'1' : -0.8 , '2' : -0.6 , '3' : -0.5, '4' : -0.25, '5' : -0.2, '6' : 0.0, '7' : 0.1, '8' : -1.0 , '9' : 0.0, 's' : -0.4} self.killScores = {'1' : 1.0 , '2' : 0.9 , '3' : 0.9 , '4' : 0.8, '5' : 0.8, '6' : 0.8, '7' : 0.8, '8' : 0.9 , '9' : 0.7, 's' : 1.0} - self.riskScores = {'1' : 0.0, '2' : 0.1, '3' : 0.2, '4': 0.4, '5': 0.6, '6': 0.7, '7':0.8, '8': 0.0, '9' : 1.0, 's' : 0.1} + self.riskScores = {'1' : -0.3, '2' : -0.3, '3' : 0.0, '4': 0.4, '5': 0.6, '6': 0.7, '7':0.8, '8': 0.0, '9' : 1.0, 's' : 0.1} @@ -45,23 +44,30 @@ 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: + if len(moveList) <= 0: print "NO_MOVE" return True @@ -86,7 +92,8 @@ 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 -1000.0 total = 0.0 count = 0.0 @@ -132,7 +139,7 @@ class Vixen(BasicAI): if attackerRank == '8': return 1.0 else: - return 0.0 + return self.suicideScore(attackerRank) def suicideScore(self, attackerRank): return self.suicideScores[attackerRank]