From 9e4bc3c0b49f5e2796a62c8fa91fe0ec78d96af2 Mon Sep 17 00:00:00 2001
From: Sam Moore <matches@ucc.asn.au>
Date: Fri, 2 Mar 2012 23:47:24 +0800
Subject: [PATCH] Fixed bug in simulate.py + hacky fix for bug in vixen

simulate.py wasn't setting the "gameID" variable correctly,
meaning all games were logged to "red.vs.blue.1.1"

Bug in vixen found by [SLX]; it attempts to move outside the board.
Usually when losing.

Path finding algorithm (path.py) shouldn't move outside the board.
But somehow it is.

Hacky fix at the moment by checking for moves outside the board in
vixen's score calculation, and allocating -100 to these moves.
---
 agents/vixen/vixen.py       | 5 +++--
 judge/simulator/simulate.py | 7 +++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/agents/vixen/vixen.py b/agents/vixen/vixen.py
index 975f6a7..a4010b1 100755
--- a/agents/vixen/vixen.py
+++ b/agents/vixen/vixen.py
@@ -61,7 +61,7 @@ class Vixen(BasicAI):
 			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 +86,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 -100.0
 
 		total = 0.0
 		count = 0.0
diff --git a/judge/simulator/simulate.py b/judge/simulator/simulate.py
index 5daafb7..7235624 100755
--- a/judge/simulator/simulate.py
+++ b/judge/simulator/simulate.py
@@ -221,13 +221,16 @@ for roundNumber in range(totalRounds, totalRounds + nRounds):
 		for blue in agents: #against each other agent, playing as blue
 			if red == blue:
 				continue #Exclude battles against self
-			gameNumber += 1
-			gameID = str(roundNumber) + "." + str(gameNumber)
+			
+			
 			for i in range(1, nGames/2 + 1):
+				gameNumber += 1
+				gameID = str(roundNumber) + "." + str(gameNumber)
 				#Play a game and read the result. Note the game is logged to a file based on the agent's names
 				if verbose:
 					sys.stdout.write("Agents: \""+red["name"]+"\" and \""+blue["name"]+"\" playing game (ID: " + gameID + ") ... ")
 				logFile = logDirectory + "round"+str(roundNumber) + "/"+red["name"]+".vs."+blue["name"]+"."+str(gameID)
+				errorLog = [logDirectory + "error/" + red["name"] + "."+str(gameID), logDirectory + "error/" + blue["name"] + "."+str(gameID)]
 				outline = os.popen(managerPath + " -o " + logFile + " -T " + str(timeoutValue) + " " + red["path"] + " " + blue["path"], "r").read()
 				results = outline.split(' ')
 			
-- 
GitLab