diff --git a/qchess/qchess.cgi b/qchess/qchess.cgi index 752fabf61432bea877e665493456d0ba82bcdc87..4b8e34c779d30b648100cdb9cfd6c075aa96dcde 100755 --- a/qchess/qchess.cgi +++ b/qchess/qchess.cgi @@ -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": diff --git a/web/index.html b/web/index.html index 9c04fe979a04f9c6f957320bff4bc86857c4c27f..a313225232ef0a9bf0495d4066daccdf45328b10 100644 --- a/web/index.html +++ b/web/index.html @@ -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> +<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="/web/20130509192429/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="/web/20130509192429/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="/web/20130509192429/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="/web/20130509192429/http://www.ucc.asn.au/services/irc.ucc"/>Join the #progcomp channel on IRC</a> </li> + <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/get.html"/>Obtain a copy of the qchess program</a> </li> + <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/using.html"/>Using the qchess program</a> </li> + <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/agent.html"/>Writing an agent for the qchess program</a> </li> + <li> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/enter.html"/>Entering the competition</a> </li> +</ol> + +<hr><h2> Important Links </h2> +<table border="1"> + <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> + <tr> <th> IRC </th> <td> <a href="/web/20130509192429/irc://irc.ucc.asn.au/progcomp"/>#progcomp</a> </td> </tr> + <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> + <th> Dates </th> <td> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/dates.txt"/>subject to change</a> </td> </tr> + <tr> <th> Results </th> <td> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/2013/web/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="/web/20130509192429/http://www.ucc.asn.au/">The UCC Website</a> </p> + +<p> <a href="/web/20130509192429/http://progcomp.ucc.asn.au/">UCC::Progcomp Website</a> </p> + +</body> +</html> diff --git a/web/qwebchess/index.html b/web/qwebchess/index.html new file mode 100644 index 0000000000000000000000000000000000000000..cdfd0631c2fb97fd2833b08ede2b0bd09788d2c5 --- /dev/null +++ b/web/qwebchess/index.html @@ -0,0 +1,26 @@ +<html> +<head> + <title>QChess Web UI</title> + <!--<link rel="stylesheet" href="css.css" />--> + <script type="text/javascript" src="js.js"></script> +</head> + +<body onload="javascript:boardLoad();" style="width: 100%"> + +<div> +<table style="margin-left: auto; margin-right: auto; font-size: 20" width=600px height=600px> +<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> +<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> +<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> +<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> +<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> +<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> +<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> +<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> +</table> +<br /> +<br /> +<small>Made By Sam Moore [SZM] and Mitchell Pomery [BG3]</small> +</div> +</body> +</html> \ No newline at end of file diff --git a/web/qwebchess/js.js b/web/qwebchess/js.js new file mode 100644 index 0000000000000000000000000000000000000000..732ec4eb7c0ea9f0d90c6c286d916564f3910ca2 --- /dev/null +++ b/web/qwebchess/js.js @@ -0,0 +1,180 @@ +//progcomp.ucc.asn.au/cgi-bin/qchess.cgi?r=start +//progcomp.ucc.asn.au/cgi-bin/qchess.cgi?r=quit +//progcomp.ucc.asn.au/cgi-bin/qchess.cgi?x=X&y=Y (0 indexed) + +pieceSelected = ""; +piece = ""; + +function selectPiece(loc) { + x = (""+loc).charAt(1); + y = (""+loc).charAt(0); + //alert(loc); + if (pieceSelected == "") { + if (document.getElementById(loc).innerHTML.charAt(0) == "W") { + console.log("Piece Selected: " + loc); + pieceSelected = loc; + ajaxUpdate("x=" + x + "&y=" + y); + } + } + else { + //alert("pieceMoved"); + if (validMove(pieceSelected, piece, loc)) { + ajaxUpdate("x=" + x + "&y=" + y); + doMove(pieceSelected, loc); + pieceSelected = ""; + } + else { + console.log("Invalid Move"); + } + } +} + +function validMove(start, piece, end) { + return true; +} + +function doMove(start, end) { + begin = document.getElementById(start); + end = document.getElementById(end); + htmlToMove = begin.innerHTML; + end.innerHTML = htmlToMove; + begin.innerHTML = ""; + //console.log("Piece Moved"); +} + +function boardLoad() { + ajaxUpdate("r=force_quit"); + + + + for (i = 0; i < 8; i++) { + for (j = 0; j < 8; j++) { + e = i + "" + j; + elem = document.getElementById(e) + if ((i + j) % 2 == 0) + elem.style.background="#FFF"; + else + elem.style.background="#DDD"; + } + } + + //Place pieces on the board + //Pawns + for (i = 0; i < 8; i++) { + black = document.getElementById("1" + i); + white = document.getElementById("6" + i); + black.innerHTML = "B<br /><small>p</small> <bold>?</bold> <small>?</small></span>"; + white.innerHTML = "W<br /><small>p</small> <bold>?</bold> <small>?</small></span>"; + + black = document.getElementById("0" + i); + white = document.getElementById("7" + i); + piece = "p"; + if (i == 0 || i == 7) + piece = "r"; + if (i == 1 || i == 6) + piece = "h"; + if (i == 2 || i == 5) + piece = "b"; + if (i == 3) + piece = "k"; + if (i == 4) + piece = "q"; + + black.innerHTML = "B<br /><small>" + piece + "</small> <bold>?</bold> <small>?</small>"; + white.innerHTML = "W<br /><small>" + piece + "</small> <bold>?</bold> <small>?</small>"; + } + + setTimeout(function(){ajaxUpdate("r=start");}, 1000); +} + +//AJAX Stuff +function ajaxUpdate(queryString) { + var ajaxRequest; // The variable that makes Ajax possible! + + try { + // Opera 8.0+, Firefox, Safari + ajaxRequest = new XMLHttpRequest(); + } catch (e) { + // Internet Explorer Browsers + try { + ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); + } catch (e) { + try { + ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); + } catch (e) { + // Something went wrong + alert("Your Browser is not Ajax Compatible, Please Upgrade to Google Chrome."); + return false; + } + } + } + + //alert(queryString); + + // Create a function that will receive data sent from the server + ajaxRequest.onreadystatechange = function () { + //alert("RS" + ajaxRequest.readyState); + if (ajaxRequest.readyState == 4) { + console.log("AJAX Response: " + ajaxRequest.responseText); + ret = ""+ajaxRequest.responseText; + if (ret.charAt(4) == "-" && ret.charAt(5) == ">") { + //Piece has been moved + //console.log("Moving other piece"); + lines = ret.split("\n"); + //if (lines[3] != "SELECT?") { + if (lines[2] != "SELECT?") { + x1 = lines[2].charAt(0); + y1 = lines[2].charAt(2); + x2 = lines[2].charAt(7); + y2 = lines[2].charAt(9); + console.log("Black Move: " + x1 + "" + y1 + " -> " + x2 + "" + y2); + doMove(y1 + "" + x1, y2 + "" + x2); + } + else { + console.log("Black Unable to move"); + } + } + else { + lines = ret.split("\n"); + if (lines[1] == "MOVE?") { + //We selected a piece + //console.log("choose where to move our piece"); + piece = lines[0].charAt(6); + //console.log("Piece: " + piece); + content = document.getElementById(pieceSelected); + contentHTML = content.innerHTML; + //contentHTML = contentHTML.replace("?", piece); + //"W<br /><small>p</small> <bold>?</bold> <small>?</small></span>"; + if (lines[0].charAt(4) == "1") { + //console.log("changing quantum piece"); + contentHTML = replaceAt(contentHTML, 44, piece); + } + contentHTML = replaceAt(contentHTML, 28, piece); + //console.log(contentHTML); + //contentHTML = "CHANGED" + contentHTML; + content.innerHTML = contentHTML; + } + } + + //alert(ret); + } + } + + //ar = "http://progcomp.ucc.asn.au/cgi-bin/qchess.cgi?" + queryString; + ar = "/../../../cgi-bin/qchess.cgi?" + queryString; + + console.log("AJAX Request: " + ar); + + ajaxRequest.open("GET", ar, true); + ajaxRequest.send(); +} + + + + + + +function replaceAt(s, n, t) { + //console.log(s.substring(0, n) + "\n" + t + "\n" + s.substring(n + 1) + "\n"); + return (s.substring(0, n) + t + s.substring(n + 1)); +} \ No newline at end of file