quantum-chess

git clone git://git.codymlewis.com/quantum-chess.git
Log | Files | Refs | LICENSE

commit 1250fb50f598e0c42a66fd64ab42bb6c4f5d2759
parent 2cd12146bc392382bf9ba4b3674e4235e75e71ab
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Mon,  6 Aug 2018 22:30:13 +1000

Some more ui improvements and precursors to the backend

Diffstat:
Msrc/WebApp/Board.py | 25++++++++++++++++---------
Msrc/WebApp/Main.py | 16+++++++++-------
Msrc/WebApp/Piece.py | 39+++++++++++++++++++--------------------
Msrc/WebApp/__pycache__/Board.cpython-36.pyc | 0
Msrc/WebApp/__pycache__/Main.cpython-36.pyc | 0
Msrc/WebApp/__pycache__/Piece.cpython-36.pyc | 0
Msrc/WebApp/__pycache__/__init__.cpython-36.pyc | 0
Msrc/WebApp/static/scripts/chess.js | 18+++++++++++++++---
Msrc/WebApp/templates/base.html | 5+----
Msrc/WebApp/templates/index.html | 12++++++++++--
10 files changed, 70 insertions(+), 45 deletions(-)

diff --git a/src/WebApp/Board.py b/src/WebApp/Board.py @@ -1,6 +1,6 @@ import re # regex -import Piece -from Functions import Direction +from . import Piece +from . import Functions class Board: def __init__(self): self.playBoard = dict() @@ -30,19 +30,19 @@ class Board: self.playBoard[index] = '0' def addMovement(self, i, move): # add an atomic movement unit to the index - if(move == Direction.UP): + if(move == Functions.Direction.UP): i = chr(ord(i[0:1])-1) + str(int(i[1:])) - elif(move == Direction.DOWN): + elif(move == Functions.Direction.DOWN): i = chr(ord(i[0:1])+1) + str(int(i[1:])) - elif(move == Direction.RIGHT): + elif(move == Functions.Direction.RIGHT): i = i[0:1] + str(int(i[1:])-1) - elif(move == Direction.LEFT): + elif(move == Functions.Direction.LEFT): i = i[0:1] + str(int(i[1:])+1) - elif(move == Direction.UPRIGHT): + elif(move == Functions.Direction.UPRIGHT): i = chr(ord(i[0:1])-1) + str(int(i[1:])-1) - elif(move == Direction.DOWNRIGHT): + elif(move == Functions.Direction.DOWNRIGHT): i = chr(ord(i[0:1])+1) + str(int(i[1:])-1) - elif(move == Direction.DOWNLEFT): + elif(move == Functions.Direction.DOWNLEFT): i = chr(ord(i[0:1])+1) + str(int(i[1:])+1) else: i = chr(ord(i[0:1])-1) + str(int(i[1:])+1) @@ -258,3 +258,9 @@ class Board: if(i < 98+self.rows): # put a pipe at the end of the line string = string + '|\n' return string + +INSTANCEBOARD = Board() +def play(start, end, colour, sp): + if INSTANCEBOARD.play(start, end, colour, sp): + return INSTANCEBOARD.toString() + return False+ \ No newline at end of file diff --git a/src/WebApp/Main.py b/src/WebApp/Main.py @@ -1,5 +1,5 @@ -# import Board -# from qiskit import QuantumProgram +from . import Board +from bleach import clean from flask import ( Blueprint, render_template, url_for, redirect, current_app, g, session, request, flash ) @@ -9,9 +9,12 @@ bp = Blueprint("Main", __name__, url_prefix="/") def index(): return redirect(url_for("Main.home")) -@bp.route("/home") +@bp.route("/home", methods=["GET", "POST"]) def home(): + if request.method == "POST": + sp = True if request.form["sp"] == "checked" else False + colour = clean(request.form["colour"]) + start = clean(request.form["start"]) + end = clean(request.form["end"]) + Board.play(start, end, colour, sp) return render_template("index.html") - -# def create_board(): -# return Board.Board()- \ No newline at end of file diff --git a/src/WebApp/Piece.py b/src/WebApp/Piece.py @@ -1,5 +1,4 @@ -import Functions -from Functions import Direction +from . import Functions class Piece: def __init__(self, superposNum, frstSuperPos, col, idT): self.superposNo = superposNum @@ -52,9 +51,9 @@ class Pawn(Piece): moveNum = 1 if(len(moveArr) <= moveNum): if(self.colour == 'W'): - direction = Direction.UP + direction = Functions.Direction.UP else: - direction = Direction.DOWN + direction = Functions.Direction.DOWN for i in range(len(moveArr)): if(not moveArr[i] == direction): return False @@ -64,11 +63,11 @@ class Pawn(Piece): def canAttack(self, movement): moveArr = Functions.splitMovement(movement) if(self.colour == 'W'): - dir1 = Direction.UPLEFT - dir2 = Direction.UPRIGHT + dir1 = Functions.Direction.UPLEFT + dir2 = Functions.Direction.UPRIGHT else: - dir1 = Direction.DOWNLEFT - dir2 = Direction.DOWNRIGHT + dir1 = Functions.Direction.DOWNLEFT + dir2 = Functions.Direction.DOWNRIGHT if(len(moveArr) == 1 and (moveArr[0] == dir1 or moveArr[0] == dir2)): return True else: @@ -82,7 +81,7 @@ class Bishop(Piece): def canMove(self,movement): moveArr = Functions.splitMovement(movement) direction = moveArr[0] - if direction in [Direction.UPLEFT, Direction.UPRIGHT, Direction.DOWNLEFT, Direction.DOWNRIGHT]: + if direction in [Functions.Direction.UPLEFT, Functions.Direction.UPRIGHT, Functions.Direction.DOWNLEFT, Functions.Direction.DOWNRIGHT]: for i in range(1, len(moveArr)): if(direction != moveArr[i]): return False @@ -98,7 +97,7 @@ class King(Piece): moveArr = Functions.splitMovement(movement) direction = moveArr[0] if(len(moveArr) == 1): - if direction in [Direction.DOWN, Direction.UP, Direction.RIGHT, Direction.LEFT, Direction.DOWNRIGHT, Direction.DOWNLEFT, Direction.UPRIGHT, Direction.UPLEFT]: + if direction in [Functions.Direction.DOWN, Functions.Direction.UP, Functions.Direction.RIGHT, Functions.Direction.LEFT, Functions.Direction.DOWNRIGHT, Functions.Direction.DOWNLEFT, Functions.Direction.UPRIGHT, Functions.Direction.UPLEFT]: return True return False @@ -115,17 +114,17 @@ class Knight(Piece): return False def __isL(self, moveArr): - if(moveArr[0] == Direction.UP): - if(moveArr[1] == Direction.UPLEFT or moveArr[1] == Direction.UPRIGHT): + if(moveArr[0] == Functions.Direction.UP): + if(moveArr[1] == Functions.Direction.UPLEFT or moveArr[1] == Functions.Direction.UPRIGHT): return True - elif(moveArr[0] == Direction.DOWN): - if(moveArr[1] == Direction.DOWNLEFT or moveArr[1] == Direction.DOWNRIGHT): + elif(moveArr[0] == Functions.Direction.DOWN): + if(moveArr[1] == Functions.Direction.DOWNLEFT or moveArr[1] == Functions.Direction.DOWNRIGHT): return True - elif(moveArr[0] == Direction.LEFT): - if(moveArr[1] == Direction.UPLEFT or moveArr[1] == Direction.DOWNLEFT): + elif(moveArr[0] == Functions.Direction.LEFT): + if(moveArr[1] == Functions.Direction.UPLEFT or moveArr[1] == Functions.Direction.DOWNLEFT): return True - elif(moveArr[0] == Direction.RIGHT): - if(moveArr[1] == Direction.UPRIGHT or moveArr[1] == Direction.DOWNRIGHT): + elif(moveArr[0] == Functions.Direction.RIGHT): + if(moveArr[1] == Functions.Direction.UPRIGHT or moveArr[1] == Functions.Direction.DOWNRIGHT): return True else: return False @@ -138,7 +137,7 @@ class Queen(Piece): def canMove(self, movement): moveArr = Functions.splitMovement(movement) direction = moveArr[0] - if direction in [Direction.DOWN, Direction.UP, Direction.RIGHT, Direction.LEFT, Direction.DOWNRIGHT, Direction.DOWNLEFT, Direction.UPRIGHT, Direction.UPLEFT]: + if direction in [Functions.Direction.DOWN, Functions.Direction.UP, Functions.Direction.RIGHT, Functions.Direction.LEFT, Functions.Direction.DOWNRIGHT, Functions.Direction.DOWNLEFT, Functions.Direction.UPRIGHT, Functions.Direction.UPLEFT]: for i in range(1, len(moveArr)): if(direction != moveArr[i]): return False @@ -153,7 +152,7 @@ class Rook(Piece): def canMove(self, movement): moveArr = Functions.splitMovement(movement) direction = moveArr[0] - if direction in [Direction.UP, Direction.DOWN, Direction.LEFT, Direction.RIGHT]: + if direction in [Functions.Direction.UP, Functions.Direction.DOWN, Functions.Direction.LEFT, Functions.Direction.RIGHT]: for i in range(1, len(moveArr)): if direction != moveArr[i]: return False diff --git a/src/WebApp/__pycache__/Board.cpython-36.pyc b/src/WebApp/__pycache__/Board.cpython-36.pyc Binary files differ. diff --git a/src/WebApp/__pycache__/Main.cpython-36.pyc b/src/WebApp/__pycache__/Main.cpython-36.pyc Binary files differ. diff --git a/src/WebApp/__pycache__/Piece.cpython-36.pyc b/src/WebApp/__pycache__/Piece.cpython-36.pyc Binary files differ. diff --git a/src/WebApp/__pycache__/__init__.cpython-36.pyc b/src/WebApp/__pycache__/__init__.cpython-36.pyc Binary files differ. diff --git a/src/WebApp/static/scripts/chess.js b/src/WebApp/static/scripts/chess.js @@ -1,3 +1,15 @@ $(document).ready(function() { - var board = ChessBoard("board", "start"); -});- \ No newline at end of file + var squares = $(".square"); + for(var i = 0; i < squares.length; i++) { + if(squares[i].id == "") { + continue; + } + // add click event for each piece + } +}); + +function movement(classes) { + // determine movement spaces based on piece classes +} + +// post plays to backend, then change board based on response+ \ No newline at end of file diff --git a/src/WebApp/templates/base.html b/src/WebApp/templates/base.html @@ -30,10 +30,7 @@ <nav class="navbar navbar-expand-sm bg-dark navbar-dark sticky-top"> <ul class="navbar-nav"> <li class="nav-item"> - <a class="nav-link selected" href="/home/">Home</a> - </li> - <li class="nav-item"> - <a class="nav-link">Other</a> + <a class="nav-link selected" href="/home">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="https://github.com/luxdosugi">Git</a> diff --git a/src/WebApp/templates/index.html b/src/WebApp/templates/index.html @@ -3,17 +3,20 @@ {% block title %}Home{% endblock %} {% block scripts %} + <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"> + <script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script> <script src={{ url_for("static", filename="scripts/chess.js") }}></script> {% endblock %} {% block contents %} <div class="container-fluid bg-light"> + <h1 class="display-1 text-center">Quantum Chess</h1> <br /> <div class="container"> <div class="container" id="board"> {% for i in range(0, 8) %} <div class="row"> - <div class="col-sm-2"></div> + <div class="col-sm-2 text-right"></div> {% for j in range(0, 8) %} <div class="col-1 {% if ((j % 2) == (i % 2)) %} @@ -37,7 +40,7 @@ fa-chess-king {% endif %} {% else %} - fa-chess-pawn + fa-chess-pawn first-move {% endif %} {% if i in [0, 1] %} pc-black @@ -51,6 +54,11 @@ <div class="col-sm-2"></div> </div> {% endfor %} + <br /> + <div class="col-sm-4 mx-auto checkbox"> + <label class="" for="sp">Super-position</label> + <input type="checkbox" data-toggle="toggle" data-onstyle="success" data-offstyle="danger" class="" name="sp" id="sp" value="checked"> + </div> </div> </div> </div>