Commit 5287b4f8 authored by Sam Moore's avatar Sam Moore

Actually commit stuff from ages ago

- Use regex in ExternalAgent to cope with Fortran agents
- Add "Q" to graphics (although somehow that did get committed?)
- Did something in src/board.py... no idea what
parent 885bbd06
...@@ -294,7 +294,7 @@ class Board(): ...@@ -294,7 +294,7 @@ class Board():
#print "Moving " + str(x) + "," + str(y) + " to " + str(x2) + "," + str(y2) + "; possible_moves are " + str(self.possible_moves(piece)) #print "Moving " + str(x) + "," + str(y) + " to " + str(x2) + "," + str(y2) + "; possible_moves are " + str(self.possible_moves(piece))
if not [x2,y2] in self.possible_moves(piece): if not [x2,y2] in self.possible_moves(piece):
raise Exception("ILLEGAL move") raise Exception("ILLEGAL move " + str(x2)+","+str(y2))
self.grid[x][y] = None self.grid[x][y] = None
taken = self.grid[x2][y2] taken = self.grid[x2][y2]
...@@ -614,7 +614,7 @@ class Board(): ...@@ -614,7 +614,7 @@ class Board():
import subprocess import subprocess
import select import select
import platform import platform
import re
agent_timeout = -1.0 # Timeout in seconds for AI players to make moves agent_timeout = -1.0 # Timeout in seconds for AI players to make moves
# WARNING: Won't work for windows based operating systems # WARNING: Won't work for windows based operating systems
...@@ -666,7 +666,7 @@ class ExternalAgent(Player): ...@@ -666,7 +666,7 @@ class ExternalAgent(Player):
if self.p.stdout in ready: if self.p.stdout in ready:
#sys.stderr.write("Reading from " + str(self.p) + " 's stdout...\n") #sys.stderr.write("Reading from " + str(self.p) + " 's stdout...\n")
try: try:
result = self.p.stdout.readline().strip("\r\n") result = self.p.stdout.readline().strip(" \t\r\n")
#sys.stderr.write("Read \'" + result + "\' from " + str(self.p) + "\n") #sys.stderr.write("Read \'" + result + "\' from " + str(self.p) + "\n")
return result return result
except: # Exception, e: except: # Exception, e:
...@@ -680,7 +680,8 @@ class ExternalAgent(Player): ...@@ -680,7 +680,8 @@ class ExternalAgent(Player):
line = self.get_response() line = self.get_response()
try: try:
result = map(int, line.split(" ")) m = re.match("\s*(\d+)\s+(\d+)\s*", line)
result = map(int, [m.group(1), m.group(2)])
except: except:
raise Exception("GIBBERISH \"" + str(line) + "\"") raise Exception("GIBBERISH \"" + str(line) + "\"")
return result return result
...@@ -696,7 +697,9 @@ class ExternalAgent(Player): ...@@ -696,7 +697,9 @@ class ExternalAgent(Player):
line = self.get_response() line = self.get_response()
try: try:
result = map(int, line.split(" ")) m = re.match("\s*(\d+)\s+(\d+)\s*", line)
result = map(int, [m.group(1), m.group(2)])
except: except:
raise Exception("GIBBERISH \"" + str(line) + "\"") raise Exception("GIBBERISH \"" + str(line) + "\"")
return result return result
...@@ -1898,7 +1901,7 @@ class GraphicsThread(StoppableThread): ...@@ -1898,7 +1901,7 @@ class GraphicsThread(StoppableThread):
#print "Test font" #print "Test font"
pygame.font.Font(os.path.join(os.path.curdir, "data", "DejaVuSans.ttf"), 32).render("Hello", True,(0,0,0)) pygame.font.Font(os.path.join(os.path.curdir, "data", "DejaVuSans.ttf"), 32).render("Hello", True,(0,0,0))
#create_images(grid_sz) #load_images()
create_images(grid_sz) create_images(grid_sz)
""" """
...@@ -1929,7 +1932,7 @@ class GraphicsThread(StoppableThread): ...@@ -1929,7 +1932,7 @@ class GraphicsThread(StoppableThread):
pygame.display.flip() pygame.display.flip()
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_q):
if isinstance(game, GameThread): if isinstance(game, GameThread):
with game.lock: with game.lock:
game.final_result = "" game.final_result = ""
...@@ -2604,4 +2607,4 @@ if __name__ == "__main__": ...@@ -2604,4 +2607,4 @@ if __name__ == "__main__":
sys.exit(102) sys.exit(102)
# --- main.py --- # # --- main.py --- #
# EOF - created from make on Thu Feb 28 23:49:16 WST 2013 # EOF - created from make on Thu Mar 14 22:36:37 WST 2013
...@@ -197,7 +197,7 @@ class Board(): ...@@ -197,7 +197,7 @@ class Board():
#print "Moving " + str(x) + "," + str(y) + " to " + str(x2) + "," + str(y2) + "; possible_moves are " + str(self.possible_moves(piece)) #print "Moving " + str(x) + "," + str(y) + " to " + str(x2) + "," + str(y2) + "; possible_moves are " + str(self.possible_moves(piece))
if not [x2,y2] in self.possible_moves(piece): if not [x2,y2] in self.possible_moves(piece):
raise Exception("ILLEGAL move") raise Exception("ILLEGAL move " + str(x2)+","+str(y2))
self.grid[x][y] = None self.grid[x][y] = None
taken = self.grid[x2][y2] taken = self.grid[x2][y2]
......
...@@ -59,7 +59,7 @@ class GraphicsThread(StoppableThread): ...@@ -59,7 +59,7 @@ class GraphicsThread(StoppableThread):
pygame.display.flip() pygame.display.flip()
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_q):
if isinstance(game, GameThread): if isinstance(game, GameThread):
with game.lock: with game.lock:
game.final_result = "" game.final_result = ""
......
import subprocess import subprocess
import select import select
import platform import platform
import re
agent_timeout = -1.0 # Timeout in seconds for AI players to make moves agent_timeout = -1.0 # Timeout in seconds for AI players to make moves
# WARNING: Won't work for windows based operating systems # WARNING: Won't work for windows based operating systems
...@@ -53,7 +53,7 @@ class ExternalAgent(Player): ...@@ -53,7 +53,7 @@ class ExternalAgent(Player):
if self.p.stdout in ready: if self.p.stdout in ready:
#sys.stderr.write("Reading from " + str(self.p) + " 's stdout...\n") #sys.stderr.write("Reading from " + str(self.p) + " 's stdout...\n")
try: try:
result = self.p.stdout.readline().strip("\r\n") result = self.p.stdout.readline().strip(" \t\r\n")
#sys.stderr.write("Read \'" + result + "\' from " + str(self.p) + "\n") #sys.stderr.write("Read \'" + result + "\' from " + str(self.p) + "\n")
return result return result
except: # Exception, e: except: # Exception, e:
...@@ -67,7 +67,8 @@ class ExternalAgent(Player): ...@@ -67,7 +67,8 @@ class ExternalAgent(Player):
line = self.get_response() line = self.get_response()
try: try:
result = map(int, line.split(" ")) m = re.match("\s*(\d+)\s+(\d+)\s*", line)
result = map(int, [m.group(1), m.group(2)])
except: except:
raise Exception("GIBBERISH \"" + str(line) + "\"") raise Exception("GIBBERISH \"" + str(line) + "\"")
return result return result
...@@ -83,7 +84,9 @@ class ExternalAgent(Player): ...@@ -83,7 +84,9 @@ class ExternalAgent(Player):
line = self.get_response() line = self.get_response()
try: try:
result = map(int, line.split(" ")) m = re.match("\s*(\d+)\s+(\d+)\s*", line)
result = map(int, [m.group(1), m.group(2)])
except: except:
raise Exception("GIBBERISH \"" + str(line) + "\"") raise Exception("GIBBERISH \"" + str(line) + "\"")
return result return result
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment