X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=progcomp%2Fagents%2Fbasic_python%2Fbasic_python.py;h=9b427c73a23d9475f7890adedf2921c6b75db921;hp=024ae551a69231dfa62452e1e111a47f0fea4db6;hb=cf19b39b4fbc4ae5fd134cfe6c76f7718cc3097f;hpb=baf69b8ddea3e2749f114a1e82bc1253ef062bc0 diff --git a/progcomp/agents/basic_python/basic_python.py b/progcomp/agents/basic_python/basic_python.py index 024ae55..9b427c7 100755 --- a/progcomp/agents/basic_python/basic_python.py +++ b/progcomp/agents/basic_python/basic_python.py @@ -20,16 +20,24 @@ import random ranks = ['B','1','2','3','4','5','6','7','8','9','s','F', '?', '+'] -def move(x, y, direction): +def is_integer(s): + """ Using exceptions for this feels... wrong...""" + try: + int(s) + return True + except ValueError: + return False + +def move(x, y, direction, multiplier): """ Moves point (x,y) in direction, returns a pair """ if direction == "UP": - return (x,y-1) + return (x,y-multiplier) elif direction == "DOWN": - return (x,y+1) + return (x,y+multiplier) elif direction == "LEFT": - return (x-1, y) + return (x-multiplier, y) elif direction == "RIGHT": - return (x+1, y) + return (x+multiplier, y) return (x,y) @@ -203,9 +211,16 @@ class BasicAI: #sys.stderr.write(" Board position " + str(x) + " " + str(y) + " is OK!\n") direction = result[2].strip() + + multiplier = 1 outcome = result[3].strip() + outIndex = 3 + if is_integer(outcome): + multiplier = int(outcome) + outcome = result[4].strip() + outIndex = 4 - p = move(x,y,direction) + p = move(x,y,direction, multiplier) @@ -229,7 +244,7 @@ class BasicAI: self.board[p[0]][p[1]] = self.board[x][y] - self.board[x][y].rank = result[4].strip() + self.board[x][y].rank = result[outIndex+1].strip() self.board[x][y] = None @@ -242,7 +257,7 @@ class BasicAI: elif self.board[x][y].colour == oppositeColour(self.colour): self.enemyUnits.remove(self.board[x][y]) - self.board[p[0]][p[1]].rank = result[5].strip() + self.board[p[0]][p[1]].rank = result[outIndex+2].strip() self.board[x][y] = None elif outcome == "BOTHDIE": if self.board[p[0]][p[1]] == None: