Commit 1da52d4a authored by judge's avatar judge

Trying to fix bug with fifo and network players

parent 0138f6b0
...@@ -157,13 +157,17 @@ def main(argv): ...@@ -157,13 +157,17 @@ def main(argv):
elif request == "start": elif request == "start":
print "New game." print "New game."
args = path+"qchess.py --no-graphics" args = path+"qchess.py --no-graphics"
if mode == None or mode == "bishop": if mode == "black":
args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop --log=../qchess-cgi-data/"+client+".log" args += " @internal:AgentBishop @fifo:../qchess-cgi-data/"+client
if mode == "random": elif mode == None or mode == "bishop":
args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop"
elif mode == "random":
args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentRandom" args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentRandom"
elif mode == "eigengame": elif mode == "eigengame":
args += " --server=progcomp.ucc.asn.au @fifo:../qchess-cgi-data/"+client args += " --server=progcomp.ucc.asn.au @fifo:../qchess-cgi-data/"+client
args += " [email protected]/qchess-cgi-data/"+client+".log";
os.system("echo '"+args+"' | at now") os.system("echo '"+args+"' | at now")
# subprocess.Popen(args) # subprocess.Popen(args)
......
...@@ -722,7 +722,15 @@ class FifoPlayer(Player): ...@@ -722,7 +722,15 @@ class FifoPlayer(Player):
Player.__init__(self, name, colour) Player.__init__(self, name, colour)
os.mkfifo(self.name+".in") os.mkfifo(self.name+".in")
os.mkfifo(self.name+".out") os.mkfifo(self.name+".out")
try:
self.fifo_out = open_fifo(self.name+".out","w", FifoPlayer.timeout)
except:
raise Exception("FIFO_TIMEOUT")
else:
self.fifo_out.write("START "+colour+"\n")
self.fifo_out.close()
...@@ -2995,4 +3003,4 @@ if __name__ == "__main__": ...@@ -2995,4 +3003,4 @@ if __name__ == "__main__":
# --- main.py --- # # --- main.py --- #
# EOF - created from make on Thursday 20 June 18:09:07 WST 2013 # EOF - created from make on Friday 21 June 18:15:14 WST 2013
...@@ -97,7 +97,15 @@ class FifoPlayer(Player): ...@@ -97,7 +97,15 @@ class FifoPlayer(Player):
Player.__init__(self, name, colour) Player.__init__(self, name, colour)
os.mkfifo(self.name+".in") os.mkfifo(self.name+".in")
os.mkfifo(self.name+".out") os.mkfifo(self.name+".out")
try:
self.fifo_out = open_fifo(self.name+".out","w", FifoPlayer.timeout)
except:
raise Exception("FIFO_TIMEOUT")
else:
self.fifo_out.write("START "+colour+"\n")
self.fifo_out.close()
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
*/ */
pieceSelected = ""; // currently selected piece pieceSelected = ""; // currently selected piece
playerColour = "W"; // colour of this player playerColour = ""; // colour of this player
// Unicode representations of chess pieces // Unicode representations of chess pieces
pieceChar = {"W" : { "p" : "\u2659", "h" : "\u2658", "b" : "\u2657", "r" : "\u2656", "q" : "\u2655", "k" : "\u2654", "?" : "?"}, pieceChar = {"W" : { "p" : "\u2659", "h" : "\u2658", "b" : "\u2657", "r" : "\u2656", "q" : "\u2655", "k" : "\u2654", "?" : "?"},
...@@ -32,9 +32,9 @@ $(document).ready(function() ...@@ -32,9 +32,9 @@ $(document).ready(function()
$("#status").html("white SELECT?"); $("#status").html("white SELECT?");
$("#start").html("Quit Game"); $("#start").html("Quit Game");
pieceSelected = ""; pieceSelected = "";
canClick = true; canClick = false;
$.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "force_quit"}, success : function() {}}); $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "force_quit"}, success : function() {}});
$.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "start"}}).done(function(data) {$(this).update(data)}); $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "start", m : "black"}}).done(function(data) {$(this).update(data)});
} }
...@@ -44,6 +44,7 @@ $(document).ready(function() ...@@ -44,6 +44,7 @@ $(document).ready(function()
$("#welcome").show(); $("#welcome").show();
$("#status").html("Game over"); $("#status").html("Game over");
$("#start").html("New Game"); $("#start").html("New Game");
canClick = false;
$.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "quit"}, success : function() {console.log("Quit game");}}); $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "quit"}, success : function() {console.log("Quit game");}});
} }
}); });
...@@ -283,12 +284,25 @@ $(document).ready(function() ...@@ -283,12 +284,25 @@ $(document).ready(function()
} }
else switch (lines[i]) else switch (lines[i])
{ {
case "SELECT?": case "SELECT?":
pieceSelected = ""; pieceSelected = "";
case "MOVE?": case "MOVE?":
case "": case "":
case "New game.": case "New game.":
break; break;
case "START white":
if (playerColour == "")
{
playerColour = "W";
break;
}
case "START black":
if (playerColour == "")
{
playerColour = "B";
break;
}
default: default:
alert("Game ends: " + lines[i]); alert("Game ends: " + lines[i]);
gameStarted = false; gameStarted = false;
......
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