quantum-chess

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

commit bccc84d9076ee64fd251872e896aa390149e7a8c
parent 0ca7e990a5743f3dc3cd9e1110e5607ca8eb537b
Author: Cody Lewis <luxdotsugi@gmail.com>
Date:   Fri,  4 May 2018 20:31:38 +1000

Added some more comments and removed the unnecessary power function

Diffstat:
Msrc/board.py | 23++++++++++++-----------
Msrc/functions.py | 12+++---------
2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/src/board.py b/src/board.py @@ -1,12 +1,12 @@ # board.py - QuantumChess # Author: Cody Lewis # Date: 26-FEB-2018 -# Mod.: 12-APR-2018 +# Mod.: 04-MAY-2018 # Description: # The board for the Quantum Chess # the board is indexed with a birds eye view with the white pieces on the bottom -import re -import pawn +import re # regex +import pawn # the various pieces import rook import bishop import knight @@ -24,7 +24,7 @@ class Board: colour = 'W' for j in range(1,self.columns+1): # numbers for rows, with 1 at the left and 8 at the right index = str(chr(i)) + str(j) - if(i == 97 or i==97+self.rows): + if(i == 97 or i==97+self.rows): # essentially a factory method if(j == 1 or j == 8): self.playBoard[index] = rook.Rook(0,True,colour,j) elif(j == 2 or j == 7): @@ -39,7 +39,8 @@ class Board: self.playBoard[index] = pawn.Pawn(0,True,colour,j) else: self.playBoard[index] = '0' - def addMovement(self,i,move): + + def addMovement(self,i,move): # add an atomic movement unit to the index if(move == 'u'): i = chr(ord(i[0:1])-1) + str(int(i[1:])) elif(move == 'd'): @@ -107,7 +108,7 @@ class Board: return False return False - def checkPoint(self,p): + def checkPoint(self,p): # check whether a point is on the board charNum = ord(p[0:1]) if(charNum > 96 and charNum < 98+self.rows): num = int(p[1:]) @@ -213,9 +214,10 @@ class Board: for i in range(abs(dx)): string = string + 'h' return string + def findAndDestroyParent(self,point): # search board for all matching pieces and destroy them - ident = self.playBoard[point].getId() + ident = self.playBoard[point].getId() # identifier num = int(ident[len(ident)-1:len(ident)]) parent = ident[0:len(ident)-1] + '.' for i in range(97,98+self.rows): @@ -228,7 +230,7 @@ class Board: if(otherNum >= num): self.playBoard[index] = '0' - def win(self): + def win(self): # find if one of the players have no kings left blackWin = True bkPat = 'BKi.*' whiteWin = True @@ -249,10 +251,9 @@ class Board: else: return '0' - def toString(self): string = '' - for i in range(97,99+self.rows): + for i in range(97,99+self.rows): # iterate through the letter part of the index if(i < 98+self.rows): string = string + chr(i) string = string + ' ' @@ -265,6 +266,6 @@ class Board: else: idTag = self.playBoard[index].getId()[:3] string = string + '|' + idTag - if(i < 98+self.rows): + if(i < 98+self.rows): # put a pipe at the end of the line string = string + '|\n' return string diff --git a/src/functions.py b/src/functions.py @@ -1,10 +1,10 @@ # functions.py - QuantumChess # Author: Cody Lewis # Date: 23-FEB-2018 -# Mod.: 25-FEB-2018 +# Mod.: 04-MAY-2018 # Description: # defines misc. functions for the Quantum Chess program -def evalQubit(qrNo): +def evalQubit(qrNo): # check if the most occurring qubit is all ones from qiskit import QuantumProgram qp = QuantumProgram() try: @@ -29,7 +29,7 @@ def getGreatestCount(qrNo,counts): # increment throught dict, find greatest value, return index greatestCount = '' gc = 0 - perms = pow(2,qrNo) + perms = 2**qrNo for i in range(0,perms): index = bin(i)[2:] if(len(index) < qrNo): @@ -40,12 +40,6 @@ def getGreatestCount(qrNo,counts): gc = counts[index] return greatestCount -def pow(n,i): - if(i == 0 or i == 1): - return n - else: - return n*pow(n,i-1) - def splitMovement(movement): # split the string movement into individual characters and store them in the returned array # movement key: f = up dia left, u = up, q = up dia right, r = right, l = left, h = down dia left, d = down, g = down dia right