Trying to fix bug with fifo and network players
authorjudge <[email protected]>
Fri, 21 Jun 2013 11:10:27 +0000 (19:10 +0800)
committerjudge <[email protected]>
Fri, 21 Jun 2013 11:10:27 +0000 (19:10 +0800)
qchess/qchess.cgi
qchess/qchess.py
qchess/src/player.py
web/qwebchess/js.js

index 4b8e34c..035dce0 100755 (executable)
@@ -157,13 +157,17 @@ def main(argv):
                elif request == "start":
                        print "New game."
                        args = path+"qchess.py --no-graphics"
-                       if mode == None or mode == "bishop":
-                               args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop --log=../qchess-cgi-data/"+client+".log"
-                       if mode == "random":
+                       if mode == "black":
+                               args += " @internal:AgentBishop @fifo:../qchess-cgi-data/"+client
+                       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"
                        elif mode == "eigengame":
                                args += " --server=progcomp.ucc.asn.au @fifo:../qchess-cgi-data/"+client
 
+                       args += " --log=@../qchess-cgi-data/"+client+".log";
+
                        os.system("echo '"+args+"' | at now")
 
                #       subprocess.Popen(args)
index da4cab7..1dd8691 100755 (executable)
@@ -722,7 +722,15 @@ class FifoPlayer(Player):
                Player.__init__(self, name, colour)
                os.mkfifo(self.name+".in")
                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__":
                
 
 # --- 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
index fffa738..37cca67 100644 (file)
@@ -97,7 +97,15 @@ class FifoPlayer(Player):
                Player.__init__(self, name, colour)
                os.mkfifo(self.name+".in")
                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()
+
                
                
                
index 53e9288..8099802 100644 (file)
@@ -6,7 +6,7 @@
  */\r
 \r
 pieceSelected = ""; // currently selected piece\r
-playerColour = "W"; // colour of this player\r
+playerColour = ""; // colour of this player\r
 \r
 // Unicode representations of chess pieces\r
 pieceChar = {"W" : { "p" : "\u2659", "h" : "\u2658", "b" : "\u2657", "r" : "\u2656", "q" : "\u2655", "k" : "\u2654", "?" : "?"},\r
@@ -32,9 +32,9 @@ $(document).ready(function()
                        $("#status").html("white SELECT?");\r
                        $("#start").html("Quit Game");\r
                        pieceSelected = "";\r
-                       canClick = true;\r
+                       canClick = false;\r
                        $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "force_quit"}, success : function() {}});\r
-                       $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "start"}}).done(function(data) {$(this).update(data)});\r
+                       $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "start", m : "black"}}).done(function(data) {$(this).update(data)});\r
                \r
                                \r
                }\r
@@ -44,6 +44,7 @@ $(document).ready(function()
                        $("#welcome").show();\r
                        $("#status").html("Game over");\r
                        $("#start").html("New Game");\r
+                       canClick = false;\r
                        $.ajax({url : "/cgi-bin/qchess.cgi", data : {r : "quit"}, success : function() {console.log("Quit game");}});\r
                }\r
        });\r
@@ -283,12 +284,25 @@ $(document).ready(function()
                        }\r
                        else switch (lines[i])\r
                        {\r
+       \r
                                case "SELECT?":\r
                                        pieceSelected = "";\r
                                case "MOVE?":\r
                                case "":\r
                                case "New game.":\r
                                        break;\r
+                               case "START white":\r
+                                       if (playerColour == "")\r
+                                       {\r
+                                               playerColour = "W";\r
+                                               break;\r
+                                       }\r
+                               case "START black":\r
+                                       if (playerColour == "")\r
+                                       {\r
+                                               playerColour = "B";\r
+                                               break;\r
+                                       }\r
                                default:\r
                                        alert("Game ends: " + lines[i]);\r
                                        gameStarted = false;\r

UCC git Repository :: git.ucc.asn.au