git.ucc.asn.au
/
progcomp2012.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Whoops
[progcomp2012.git]
/
progcomp
/
agents
/
basic_python
/
basic_python.py
diff --git
a/progcomp/agents/basic_python/basic_python.py
b/progcomp/agents/basic_python/basic_python.py
index
024ae55
..
9b427c7
100755
(executable)
--- 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', '?', '+']
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":
""" Moves point (x,y) in direction, returns a pair """
if direction == "UP":
- return (x,y-
1
)
+ return (x,y-
multiplier
)
elif direction == "DOWN":
elif direction == "DOWN":
- return (x,y+
1
)
+ return (x,y+
multiplier
)
elif direction == "LEFT":
elif direction == "LEFT":
- return (x-
1
, y)
+ return (x-
multiplier
, y)
elif direction == "RIGHT":
elif direction == "RIGHT":
- return (x+
1
, y)
+ return (x+
multiplier
, y)
return (x,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()
#sys.stderr.write(" Board position " + str(x) + " " + str(y) + " is OK!\n")
direction = result[2].strip()
+
+ multiplier = 1
outcome = result[3].strip()
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[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
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])
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:
self.board[x][y] = None
elif outcome == "BOTHDIE":
if self.board[p[0]][p[1]] == None:
UCC
git Repository :: git.ucc.asn.au