3 # I know using non-abreviated strings is inefficient, but this is python, who cares?
4 # Oh, yeah, this stores the number of pieces of each type in a normal chess game
5 piece_types = {"pawn" : 8, "bishop" : 2, "knight" : 2, "rook" : 2, "queen" : 1, "king" : 1, "unknown" : 0}
7 # Class to represent a quantum chess piece
9 def __init__(self, colour, x, y, types):
10 self.colour = colour # Colour (string) either "white" or "black"
11 self.x = x # x coordinate (0 - 8), none of this fancy 'a', 'b' shit here
12 self.y = y # y coordinate (0 - 8)
13 self.types = types # List of possible types the piece can be (should just be two)
14 self.current_type = "unknown" # Current type
15 self.choice = -1 # Index of the current type in self.types (-1 = unknown type)
18 self.last_state = None
20 self.move_pattern = None
22 self.possible_moves = {}
25 def init_from_copy(self, c):
26 self.colour = c.colour
29 self.types = c.types[:]
30 self.current_type = c.current_type
31 self.choice = c.choice
33 self.last_state = None
34 self.move_pattern = None
38 # Make a string for the piece (used for debug)
40 return str(self.colour) + " " + str(self.current_type) + " " + str(self.types) + " at " + str(self.x) + ","+str(self.y)
42 # Draw the piece in a pygame surface
43 def draw(self, window, grid_sz = [80,80], style="quantum"):
45 # First draw the image corresponding to self.current_type
46 img = images[self.colour][self.current_type]
48 if style == "classical":
49 offset = [-rect.width/2, -rect.height/2]
51 offset = [-rect.width/2,-3*rect.height/4]
52 window.blit(img, (self.x * grid_sz[0] + grid_sz[0]/2 + offset[0], self.y * grid_sz[1] + grid_sz[1]/2 + offset[1]))
55 if style == "classical":
58 # Draw the two possible types underneath the current_type image
59 for i in range(len(self.types)):
60 if always_reveal_states == True or self.types[i][0] != '?':
61 if self.types[i][0] == '?':
62 img = small_images[self.colour][self.types[i][1:]]
64 img = small_images[self.colour][self.types[i]]
66 img = small_images[self.colour]["unknown"] # If the type hasn't been revealed, show a placeholder
70 offset = [-rect.width/2,-rect.height/2]
73 target = (self.x * grid_sz[0] + grid_sz[0]/5 + offset[0], self.y * grid_sz[1] + 3*grid_sz[1]/4 + offset[1])
75 target = (self.x * grid_sz[0] + 4*grid_sz[0]/5 + offset[0], self.y * grid_sz[1] + 3*grid_sz[1]/4 + offset[1])
77 window.blit(img, target) # Blit shit
79 # Collapses the wave function!
81 if self.current_type == "unknown" or not self.choice in [0,1]:
82 self.choice = random.randint(0,1)
83 if self.types[self.choice][0] == '?':
84 self.types[self.choice] = self.types[self.choice][1:]
85 self.current_type = self.types[self.choice]
88 # Uncollapses (?) the wave function!
90 #print "Deselect called"
91 if (self.x + self.y) % 2 != 0:
92 if (self.types[0] != self.types[1]) or (self.types[0][0] == '?' or self.types[1][0] == '?'):
93 self.current_type = "unknown"
96 self.choice = 0 # Both the two types are the same
98 # The sad moment when you realise that you do not understand anything about a subject you studied for 4 years...