Commit Qwebchess before fucking with it
authorjudge <[email protected]>
Wed, 19 Jun 2013 10:26:43 +0000 (18:26 +0800)
committerjudge <[email protected]>
Wed, 19 Jun 2013 10:26:43 +0000 (18:26 +0800)
Thanks [BG3]

qchess/qchess.cgi
web/index.html
web/qwebchess/index.html [new file with mode: 0644]
web/qwebchess/js.js [new file with mode: 0644]

index 752fabf..4b8e34c 100755 (executable)
@@ -71,6 +71,10 @@ def open_fifo(name, mode, timeout=None):
                        raise w.exception
                return w.result
 
+def force_quit():
+       os.remove(path+client+".in")
+       os.remove(path+client+".out")
+
 def quit():
        
        if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
@@ -105,7 +109,7 @@ def quit():
 
 
 def main(argv):
-       print "Content-Type: text/plain\r\n\r\n"
+       print "Content-Type: text/plain\r\n" #Removed the second new line. Makes parsing everything easier ~BG3
        
        global client
        form = cgi.FieldStorage()
@@ -137,7 +141,11 @@ def main(argv):
                x = int(form["x"].value)
                y = int(form["y"].value)
        except:
-               
+               if request == "force_quit":
+                       force_quit()
+                       quit()
+                       return 0
+
                if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
                        if request == "quit":
                                print "Quit."
@@ -150,7 +158,7 @@ def main(argv):
                        print "New game."
                        args = path+"qchess.py --no-graphics"
                        if mode == None or mode == "bishop":
-                               args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop"
+                               args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop --log=../qchess-cgi-data/"+client+".log"
                        if mode == "random":
                                args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentRandom"
                        elif mode == "eigengame":
index 9c04fe9..a313225 100644 (file)
@@ -1,70 +1,55 @@
-
-<html>
-
-<head>
-<title> UCC::Progcomp 2013 </title>
-</head>
-
-<body bgcolor=white>
-
-<h1> Quantum Chess </h1>
-
-<p> <b> Competition: </b> Write an AI to play Quantum Chess. You can enter in <b>any</b> language that supports reading/writing from standard input/output. </p>
-
-<p> Quantum chess is a variant of chess in which the type of a piece changes during play. </p>
-<p> The game was invented by Selim Akl, and first implemented by Alice Wismath. 
-       You can see their original website <a href="http://research.cs.queensu.ca/Parallel/QuantumChess/QuantumChess.html"/>here</a>. </p>
-
-
-<hr>
-
-<h2> Rules </h2>
-
-<p> The rules are basically the same as <a href="http://research.cs.queensu.ca/Parallel/QuantumChess/QuantumChess.html"/>the original rules</a>. </p>
-
-<h3> Differences / Clarifications </h3>
-<ul>
-       <li> The bottom right and top left squares are white (as in traditional chess), not black. </li>
-       <li> Castling and en passen are <b>not</b> allowed (I'm not sure whether they are in the original version). </li>
-       <li> If a piece in a <b>pawn</b> state ends its move in the opposing back row, that state is <i>always</i> replaced with a <b>queen</b> state. </li>
-       <ul> <li> (because I'm too lazy to give players a choice) </li> </ul>
-       <li> I might shorten the number of moves before a draw is declared, we'll see. </li>
-</ul>
-
-<hr>
-
-<h2> Getting Started </h2>
-
-<ol>
-       <li> <a href="http://lists.ucc.gu.uwa.edu.au/mailman/listinfo/progcomp" target="_blank"/>Join the mailing list</a> </li>
-       <ul> <li> <b> Important: </b> Don't email the mailing list directly; email the competition organiser (matches at ucc dot asn dot au) </li> </ul>
-       <li> <a href="http://www.ucc.asn.au/services/irc.ucc"/>Join the #progcomp channel on IRC</a> </li>
-       <li> <a href="get.html"/>Obtain a copy of the qchess program</a> </li>
-       <li> <a href="using.html"/>Using the qchess program</a> </li>
-       <li> <a href="agent.html"/>Writing an agent for the qchess program</a> </li>
-       <li> <a href="enter.html"/>Entering the competition</a> </li>
-</ol>
-
-<hr>
-
-<h2> Important Links </h2>
-
-<table border="1">
-<tr> <th> git </th> <td> <a href="http://git.ucc.asn.au/?p=progcomp2013.git" target="_blank"/>http://git.ucc.asn.au</a> </td> </tr>
-<tr> <th> IRC </th> <td> <a href="irc://irc.ucc.asn.au/progcomp"/>#progcomp</a> </td> </tr>
-<tr> <th> Mailing List </th> <td> <a href="http://lists.ucc.gu.uwa.edu.au/mailman/listinfo/progcomp" target="_blank"/>progcomp at ucc</a> </td> </tr>
-<tr> <th> Dates </th> <td> <a href="dates.txt"/>subject to change</a> </td> </tr>
-<tr> <th> Results </th> <td> <a href="results"/>will appear here</a> </td> </tr>
-<tr> <th> Contact </th> <td> matches or wheel at ucc </td> </tr> 
-</table>
-
-<hr>
-
-<p> Page last updated 2013-03-29 by matches </p>
-
-<p> <a href="http://www.ucc.asn.au">The UCC Website</a> </p>
-<p> <a href="http://progcomp.ucc.asn.au">UCC::Progcomp Website</a> </p>
-
-</body>
-</html>
-
+<html>\r
+<head>\r
+<title> UCC::Progcomp 2013 </title>\r
+</head>\r
+\r
+<body bgcolor=white>\r
+<h1> Quantum Chess </h1>\r
+\r
+<p> <b>Competition: </b> Write an AI to play Quantum Chess. You can enter in <b>any</b> language that supports reading/writing from standard input/output. </p>\r
+\r
+<p> Quantum chess is a variant of chess in which the type of a piece changes during play. </p>\r
+\r
+<p> The game was invented by Selim Akl, and first implemented by Alice Wismath. You can see their original website <a href="/web/20130509192429/http://research.cs.queensu.ca/Parallel/QuantumChess/QuantumChess.html"/>here</a>. \r
+</p>\r
+\r
+<hr><h2> Rules </h2><p> The rules are basically the same as <a href="/web/20130509192429/http://research.cs.queensu.ca/Parallel/QuantumChess/QuantumChess.html"/>the original rules</a>. </p>\r
+\r
+<h3> Differences / Clarifications </h3> \r
+<ul>\r
+       <li> The bottom right and top left squares are white (as in traditional chess), not black. </li>\r
+       <li> Castling and en passen are <b>not</b> allowed (I'm not sure whether they are in the original version). </li>\r
+       <li> If a piece in a <b>pawn</b> state ends its move in the opposing back row, that state is <i>always</i> replaced with a <b>queen</b> state. </li>\r
+               <ul> <li> (because I'm too lazy to give players a choice) </li> </ul>\r
+       <li> I might shorten the number of moves before a draw is declared, we'll see. </li> \r
+</ul>\r
+\r
+<hr><h2> Getting Started </h2>\r
+<ol>\r
+       <li> <a href="/web/20130509192429/http://lists.ucc.gu.uwa.edu.au/mailman/listinfo/progcomp" target="_blank"/>Join the mailing list</a> </li>\r
+               <ul> <li> <b> Important: </b> Don't email the mailing list directly; email the competition organiser (matches at ucc dot asn dot au) </li> </ul>\r
+       <li> <a href="/web/20130509192429/http://www.ucc.asn.au/services/irc.ucc"/>Join the #progcomp channel on IRC</a> </li>\r
+       <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/get.html"/>Obtain a copy of the qchess program</a> </li>\r
+       <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/using.html"/>Using the qchess program</a> </li>\r
+       <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/agent.html"/>Writing an agent for the qchess program</a> </li>\r
+       <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/enter.html"/>Entering the competition</a> </li>\r
+</ol>\r
+\r
+<hr><h2> Important Links </h2>\r
+<table border="1">\r
+       <tr> <th> git </th> <td> <a href="/web/20130509192429/http://git.ucc.asn.au/?p=progcomp2013.git" target="_blank"/>http://git.ucc.asn.au</a> </td> </tr>\r
+       <tr> <th> IRC </th> <td> <a href="/web/20130509192429/irc://irc.ucc.asn.au/progcomp"/>#progcomp</a> </td> </tr>\r
+       <tr> <th> Mailing List </th> <td> <a href="/web/20130509192429/http://lists.ucc.gu.uwa.edu.au/mailman/listinfo/progcomp" target="_blank"/>progcomp at ucc</a> </td> </tr> <tr>\r
+       <th> Dates </th> <td> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/dates.txt"/>subject to change</a> </td> </tr>\r
+       <tr> <th> Results </th> <td> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/results"/>will appear here</a> </td> </tr>\r
+       <tr> <th> Contact </th> <td> matches or wheel at ucc </td> </tr>\r
+</table>\r
+\r
+<hr><p> Page last updated 2013-03-29 by matches </p>\r
+\r
+<p> <a href="/web/20130509192429/http://www.ucc.asn.au/">The UCC Website</a> </p>\r
+\r
+<p> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/">UCC::Progcomp Website</a> </p>\r
+\r
+</body> \r
+</html>\r
diff --git a/web/qwebchess/index.html b/web/qwebchess/index.html
new file mode 100644 (file)
index 0000000..cdfd063
--- /dev/null
@@ -0,0 +1,26 @@
+<html>\r
+<head>\r
+       <title>QChess Web UI</title>\r
+       <!--<link rel="stylesheet" href="css.css" />-->\r
+       <script type="text/javascript" src="js.js"></script>\r
+</head>\r
+\r
+<body onload="javascript:boardLoad();" style="width: 100%">\r
+\r
+<div>\r
+<table style="margin-left: auto; margin-right: auto; font-size: 20" width=600px height=600px>\r
+<tr><td onclick="javascript:selectPiece('00');" id="00"></td><td onclick="javascript:selectPiece('01');" id="01"></td><td onclick="javascript:selectPiece('02');" id="02"></td><td onclick="javascript:selectPiece('03');" id="03"></td><td onclick="javascript:selectPiece('04');" id="04"></td><td onclick="javascript:selectPiece('05');" id="05"></td><td onclick="javascript:selectPiece('06');" id="06"></td><td onclick="javascript:selectPiece('07');" id="07"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('10');" id="10"></td><td onclick="javascript:selectPiece('11');" id="11"></td><td onclick="javascript:selectPiece('12');" id="12"></td><td onclick="javascript:selectPiece('13');" id="13"></td><td onclick="javascript:selectPiece('14');" id="14"></td><td onclick="javascript:selectPiece('15');" id="15"></td><td onclick="javascript:selectPiece('16');" id="16"></td><td onclick="javascript:selectPiece('17');" id="17"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('20');" id="20"></td><td onclick="javascript:selectPiece('21');" id="21"></td><td onclick="javascript:selectPiece('22');" id="22"></td><td onclick="javascript:selectPiece('23');" id="23"></td><td onclick="javascript:selectPiece('24');" id="24"></td><td onclick="javascript:selectPiece('25');" id="25"></td><td onclick="javascript:selectPiece('26');" id="26"></td><td onclick="javascript:selectPiece('27');" id="27"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('30');" id="30"></td><td onclick="javascript:selectPiece('31');" id="31"></td><td onclick="javascript:selectPiece('32');" id="32"></td><td onclick="javascript:selectPiece('33');" id="33"></td><td onclick="javascript:selectPiece('34');" id="34"></td><td onclick="javascript:selectPiece('35');" id="35"></td><td onclick="javascript:selectPiece('36');" id="36"></td><td onclick="javascript:selectPiece('37');" id="37"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('40');" id="40"></td><td onclick="javascript:selectPiece('41');" id="41"></td><td onclick="javascript:selectPiece('42');" id="42"></td><td onclick="javascript:selectPiece('43');" id="43"></td><td onclick="javascript:selectPiece('44');" id="44"></td><td onclick="javascript:selectPiece('45');" id="45"></td><td onclick="javascript:selectPiece('46');" id="46"></td><td onclick="javascript:selectPiece('47');" id="47"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('50');" id="50"></td><td onclick="javascript:selectPiece('51');" id="51"></td><td onclick="javascript:selectPiece('52');" id="52"></td><td onclick="javascript:selectPiece('53');" id="53"></td><td onclick="javascript:selectPiece('54');" id="54"></td><td onclick="javascript:selectPiece('55');" id="55"></td><td onclick="javascript:selectPiece('56');" id="56"></td><td onclick="javascript:selectPiece('57');" id="57"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('60');" id="60"></td><td onclick="javascript:selectPiece('61');" id="61"></td><td onclick="javascript:selectPiece('62');" id="62"></td><td onclick="javascript:selectPiece('63');" id="63"></td><td onclick="javascript:selectPiece('64');" id="64"></td><td onclick="javascript:selectPiece('65');" id="65"></td><td onclick="javascript:selectPiece('66');" id="66"></td><td onclick="javascript:selectPiece('67');" id="67"></td></tr>\r
+<tr><td onclick="javascript:selectPiece('70');" id="70"></td><td onclick="javascript:selectPiece('71');" id="71"></td><td onclick="javascript:selectPiece('72');" id="72"></td><td onclick="javascript:selectPiece('73');" id="73"></td><td onclick="javascript:selectPiece('74');" id="74"></td><td onclick="javascript:selectPiece('75');" id="75"></td><td onclick="javascript:selectPiece('76');" id="76"></td><td onclick="javascript:selectPiece('77');" id="77"></td></tr>\r
+</table>\r
+<br />\r
+<br />\r
+<small>Made By Sam Moore [SZM] and Mitchell Pomery [BG3]</small>\r
+</div>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/web/qwebchess/js.js b/web/qwebchess/js.js
new file mode 100644 (file)
index 0000000..732ec4e
--- /dev/null
@@ -0,0 +1,180 @@
+//progcomp.ucc.asn.au/cgi-bin/qchess.cgi?r=start\r
+//progcomp.ucc.asn.au/cgi-bin/qchess.cgi?r=quit\r
+//progcomp.ucc.asn.au/cgi-bin/qchess.cgi?x=X&y=Y (0 indexed)\r
+\r
+pieceSelected = "";\r
+piece = "";\r
+\r
+function selectPiece(loc) {\r
+       x = (""+loc).charAt(1);\r
+       y = (""+loc).charAt(0);\r
+       //alert(loc);\r
+       if (pieceSelected == "") {\r
+               if (document.getElementById(loc).innerHTML.charAt(0) == "W") {\r
+                       console.log("Piece Selected: " + loc);\r
+                       pieceSelected = loc;\r
+                       ajaxUpdate("x=" + x + "&y=" + y);\r
+               }\r
+       }\r
+       else {\r
+               //alert("pieceMoved");\r
+               if (validMove(pieceSelected, piece, loc)) {\r
+                       ajaxUpdate("x=" + x + "&y=" + y);\r
+                       doMove(pieceSelected, loc);\r
+                       pieceSelected = "";\r
+               }\r
+               else {\r
+                       console.log("Invalid Move");\r
+               }\r
+       }\r
+}\r
+\r
+function validMove(start, piece, end) {\r
+       return true;\r
+}\r
+\r
+function doMove(start, end) {\r
+       begin = document.getElementById(start);\r
+       end = document.getElementById(end);\r
+       htmlToMove = begin.innerHTML;\r
+       end.innerHTML = htmlToMove;\r
+       begin.innerHTML = "";\r
+       //console.log("Piece Moved");\r
+}\r
+\r
+function boardLoad() {\r
+       ajaxUpdate("r=force_quit");\r
+       \r
+       \r
+       \r
+       for (i = 0; i < 8; i++) {\r
+               for (j = 0; j < 8; j++) {\r
+                       e = i + "" + j;\r
+                       elem = document.getElementById(e)\r
+                       if ((i + j) % 2 == 0)\r
+                               elem.style.background="#FFF";\r
+                       else\r
+                               elem.style.background="#DDD";\r
+               }\r
+       }\r
+       \r
+       //Place pieces on the board\r
+       //Pawns\r
+       for (i = 0; i < 8; i++) {\r
+               black = document.getElementById("1" + i);\r
+               white = document.getElementById("6" + i);\r
+               black.innerHTML = "B<br /><small>p</small> <bold>?</bold> <small>?</small></span>";\r
+               white.innerHTML = "W<br /><small>p</small> <bold>?</bold> <small>?</small></span>";\r
+               \r
+               black = document.getElementById("0" + i);\r
+               white = document.getElementById("7" + i);\r
+               piece = "p";\r
+               if (i == 0 || i == 7)\r
+                       piece = "r";\r
+               if (i == 1 || i == 6)\r
+                       piece = "h";\r
+               if (i == 2 || i == 5)\r
+                       piece = "b";\r
+               if (i == 3)\r
+                       piece = "k";\r
+               if (i == 4)\r
+                       piece = "q";\r
+               \r
+               black.innerHTML = "B<br /><small>" + piece + "</small> <bold>?</bold> <small>?</small>";\r
+               white.innerHTML = "W<br /><small>" + piece + "</small> <bold>?</bold> <small>?</small>";\r
+       }\r
+       \r
+       setTimeout(function(){ajaxUpdate("r=start");}, 1000);\r
+}\r
+\r
+//AJAX Stuff\r
+function ajaxUpdate(queryString) {\r
+       var ajaxRequest;  // The variable that makes Ajax possible!\r
+\r
+       try {\r
+               // Opera 8.0+, Firefox, Safari\r
+               ajaxRequest = new XMLHttpRequest();\r
+       } catch (e) {\r
+               // Internet Explorer Browsers\r
+               try {\r
+                       ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");\r
+               } catch (e) {\r
+                       try {\r
+                               ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");\r
+                       } catch (e) {\r
+                               // Something went wrong\r
+                               alert("Your Browser is not Ajax Compatible, Please Upgrade to Google Chrome.");\r
+                               return false;\r
+                       }\r
+               }\r
+       }\r
+       \r
+       //alert(queryString);\r
+       \r
+       // Create a function that will receive data sent from the server\r
+       ajaxRequest.onreadystatechange = function () {\r
+               //alert("RS" + ajaxRequest.readyState);\r
+               if (ajaxRequest.readyState == 4) {\r
+                       console.log("AJAX Response: " + ajaxRequest.responseText);\r
+                       ret = ""+ajaxRequest.responseText;\r
+                       if (ret.charAt(4) == "-" && ret.charAt(5) == ">") {\r
+                               //Piece has been moved\r
+                               //console.log("Moving other piece");\r
+                               lines = ret.split("\n");\r
+                               //if (lines[3] != "SELECT?") {\r
+                               if (lines[2] != "SELECT?") {\r
+                                       x1 = lines[2].charAt(0);\r
+                                       y1 = lines[2].charAt(2);\r
+                                       x2 = lines[2].charAt(7);\r
+                                       y2 = lines[2].charAt(9);\r
+                                       console.log("Black Move: " + x1 + "" + y1 + " -> " + x2 + "" + y2);\r
+                                       doMove(y1 + "" + x1, y2 + "" + x2);\r
+                               }\r
+                               else {\r
+                                       console.log("Black Unable to move");\r
+                               }\r
+                       }\r
+                       else {\r
+                               lines = ret.split("\n");\r
+                               if (lines[1] == "MOVE?") {\r
+                                       //We selected a piece\r
+                                       //console.log("choose where to move our piece");\r
+                                       piece = lines[0].charAt(6);\r
+                                       //console.log("Piece: " + piece);\r
+                                       content = document.getElementById(pieceSelected);\r
+                                       contentHTML = content.innerHTML;\r
+                                       //contentHTML = contentHTML.replace("?", piece);\r
+                                       //"W<br /><small>p</small> <bold>?</bold> <small>?</small></span>";\r
+                                       if (lines[0].charAt(4) == "1") {\r
+                                               //console.log("changing quantum piece");\r
+                                               contentHTML = replaceAt(contentHTML, 44, piece);\r
+                                       }\r
+                                       contentHTML = replaceAt(contentHTML, 28, piece);\r
+                                       //console.log(contentHTML);\r
+                                       //contentHTML = "CHANGED" + contentHTML;\r
+                                       content.innerHTML = contentHTML;\r
+                               }\r
+                       }\r
+                       \r
+                       //alert(ret);\r
+               }\r
+       }\r
+       \r
+       //ar = "http://progcomp.ucc.asn.au/cgi-bin/qchess.cgi?" + queryString;\r
+       ar = "/../../../cgi-bin/qchess.cgi?" + queryString;\r
+       \r
+       console.log("AJAX Request: " + ar);\r
+       \r
+       ajaxRequest.open("GET", ar, true);\r
+       ajaxRequest.send();\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+function replaceAt(s, n, t) {\r
+       //console.log(s.substring(0, n) + "\n" + t + "\n" + s.substring(n + 1) + "\n");\r
+       return (s.substring(0, n) + t + s.substring(n + 1));\r
+}
\ No newline at end of file

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