[FINAL RESULTS]
[progcomp2012.git] / agents / vixen / vixen.py
index 975f6a7..cebe8dd 100755 (executable)
 from basic_python import *
 from path import *
 
+import random
 
 
 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)
                
                
@@ -33,7 +33,28 @@ class Vixen(BasicAI):
                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}
 
 
-
+       def Setup(self):
+               """ Implements Setup part of protocol. Always uses the same setup. Override to create custom setups """
+               #sys.stderr.write("BasicAI Setup here...\n");
+               setup = sys.stdin.readline().split(' ')
+               if len(setup) != 4:
+                       sys.stderr.write("BasicAI setup fails, expected 4 tokens, got " + str(len(setup)) + " "+str(setup) + "\n")
+               self.colour = setup[0]
+               self.opponentName = setup[1]
+               self.width = int(setup[2])
+               self.height = int(setup[3])
+               for x in range(0, self.width):
+                       self.board.append([])
+                       for y in range(0, self.height):         
+                               self.board[x].append(None)
+
+               #flagPosition = random.choice((
+               #fakeFlag = random.choice((
+               if self.colour == "RED":
+                       print "FB8sB479B8\nBB31555583\n6724898974\n967B669999"
+               elif self.colour == "BLUE":
+                       print "967B669999\n6724898974\nBB31555583\nFB8sB479B8"
+               return True
                        
 
        def MakeMove(self):
@@ -45,23 +66,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 +114,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

UCC git Repository :: git.ucc.asn.au