quantum-chess

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

piece.py (1134B)


      1 # piece.py - QuantumChess
      2 # Author: Cody Lewis
      3 # Date: 21-FEB-2018
      4 # Description: Defines the super class of a piece in Quantum Chess
      5 import functions
      6 class Piece:
      7     def __init__(self, superposNum, frstSuperPos, col, idT):
      8         self.superposNo = superposNum
      9         self.firstSuperPos = frstSuperPos
     10         self.colour = col
     11         self.idTag = self.colour + idT
     12 
     13     def getId(self):
     14         return self.idTag
     15 
     16     def getSuperPosNum(self):
     17         return self.superposNo
     18 
     19     def superposition(self):
     20         self.superposNo += 1
     21         self.idTag = self.idTag + str(self.superposNo)
     22         if self.firstSuperPos:
     23             self.firstSuperPos = False
     24 
     25     def attack(self, enemy, movement):
     26         if self.canAttack(movement):
     27             return enemy.die()
     28         else:
     29             return False, False
     30 
     31     def canAttack(self, movement):
     32         return self.canMove(movement)
     33 
     34     def die(self):
     35         if self.superposNo > 0:
     36             return True, self.observe()
     37         return True, False
     38 
     39     def observe(self):
     40         # check the Qubit stored in this piece
     41         return functions.evalQubit(self.superposNo)