From 87681496dec0b1bdadaf0733137010615997fb05 Mon Sep 17 00:00:00 2001 From: judge Date: Wed, 19 Jun 2013 18:26:43 +0800 Subject: [PATCH] Commit Qwebchess before fucking with it Thanks [BG3] --- qchess/qchess.cgi | 14 ++- web/index.html | 125 ++++++++++++--------------- web/qwebchess/index.html | 26 ++++++ web/qwebchess/js.js | 180 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 272 insertions(+), 73 deletions(-) create mode 100644 web/qwebchess/index.html create mode 100644 web/qwebchess/js.js diff --git a/qchess/qchess.cgi b/qchess/qchess.cgi index 752fabf..4b8e34c 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 9c04fe9..a313225 100644 --- a/web/index.html +++ b/web/index.html @@ -1,70 +1,55 @@ - - - - - UCC::Progcomp 2013 - - - - -

Quantum Chess

- -

Competition: Write an AI to play Quantum Chess. You can enter in any language that supports reading/writing from standard input/output.

- -

Quantum chess is a variant of chess in which the type of a piece changes during play.

-

The game was invented by Selim Akl, and first implemented by Alice Wismath. - You can see their original website here.

- - -
- -

Rules

- -

The rules are basically the same as the original rules.

- -

Differences / Clarifications

- - -
- -

Getting Started

- -
    -
  1. Join the mailing list
  2. - -
  3. Join the #progcomp channel on IRC
  4. -
  5. Obtain a copy of the qchess program
  6. -
  7. Using the qchess program
  8. -
  9. Writing an agent for the qchess program
  10. -
  11. Entering the competition
  12. -
- -
- -

Important Links

- - - - - - - - -
git http://git.ucc.asn.au
IRC #progcomp
Mailing List progcomp at ucc
Dates subject to change
Results will appear here
Contact matches or wheel at ucc
- -
- -

Page last updated 2013-03-29 by matches

- -

The UCC Website

-

UCC::Progcomp Website

- - - - + + + UCC::Progcomp 2013 + + + +

Quantum Chess

+ +

Competition: Write an AI to play Quantum Chess. You can enter in any language that supports reading/writing from standard input/output.

+ +

Quantum chess is a variant of chess in which the type of a piece changes during play.

+ +

The game was invented by Selim Akl, and first implemented by Alice Wismath. You can see their original website here. +

+ +

Rules

The rules are basically the same as the original rules.

+ +

Differences / Clarifications

+ + +

Getting Started

+
    +
  1. Join the mailing list
  2. + +
  3. Join the #progcomp channel on IRC
  4. +
  5. Obtain a copy of the qchess program
  6. +
  7. Using the qchess program
  8. +
  9. Writing an agent for the qchess program
  10. +
  11. Entering the competition
  12. +
+ +

Important Links

+ + + + + + + +
git http://git.ucc.asn.au
IRC #progcomp
Mailing List progcomp at ucc
Dates subject to change
Results will appear here
Contact matches or wheel at ucc
+ +

Page last updated 2013-03-29 by matches

+ +

The UCC Website

+ +

UCC::Progcomp Website

+ + + diff --git a/web/qwebchess/index.html b/web/qwebchess/index.html new file mode 100644 index 0000000..cdfd063 --- /dev/null +++ b/web/qwebchess/index.html @@ -0,0 +1,26 @@ + + + QChess Web UI + + + + + + +
+ + + + + + + + + +
+
+
+Made By Sam Moore [SZM] and Mitchell Pomery [BG3] +
+ + \ No newline at end of file diff --git a/web/qwebchess/js.js b/web/qwebchess/js.js new file mode 100644 index 0000000..732ec4e --- /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
p ? ?"; + white.innerHTML = "W
p ? ?"; + + 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
" + piece + " ? ?"; + white.innerHTML = "W
" + piece + " ? ?"; + } + + 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
p ? ?"; + 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 -- 2.20.1