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)
16 self.types_revealed = [True, False] # Whether the types are known (by default the first type is always known at game start)
20 self.last_state = None
21 self.move_pattern = None
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
32 self.types_revealed = c.types_revealed[:]
34 self.last_state = None
35 self.move_pattern = None
39 # Make a string for the piece (used for debug)
41 return str(self.current_type) + " " + str(self.types) + " at " + str(self.x) + ","+str(self.y)
43 # Draw the piece in a pygame surface
44 def draw(self, window, grid_sz = [80,80]):
46 # First draw the image corresponding to self.current_type
47 img = images[self.colour][self.current_type]
49 offset = [-rect.width/2,-3*rect.height/4]
50 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]))
53 # Draw the two possible types underneath the current_type image
54 for i in range(len(self.types)):
55 if self.types_revealed[i] == True:
56 img = small_images[self.colour][self.types[i]]
58 img = small_images[self.colour]["unknown"] # If the type hasn't been revealed, show a placeholder
62 offset = [-rect.width/2,-rect.height/2]
65 target = (self.x * grid_sz[0] + grid_sz[0]/5 + offset[0], self.y * grid_sz[1] + 3*grid_sz[1]/4 + offset[1])
67 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])
69 window.blit(img, target) # Blit shit
71 # Collapses the wave function!
73 if self.current_type == "unknown":
74 self.choice = random.randint(0,1)
75 self.current_type = self.types[self.choice]
76 self.types_revealed[self.choice] = True
79 # Uncollapses (?) the wave function!
81 #print "Deselect called"
82 if (self.x + self.y) % 2 != 0:
83 if (self.types[0] != self.types[1]) or (self.types_revealed[0] == False or self.types_revealed[1] == False):
84 self.current_type = "unknown"
87 self.choice = 0 # Both the two types are the same
89 # The sad moment when you realise that you do not understand anything about a subject you studied for 4 years...