-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pieces.py
711 lines (620 loc) · 24.2 KB
/
Pieces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 24 15:52:28 2020
@author: Robert Soane
"""
import pygame
from spritesheet import SpriteSheet
from chessboard_data import coordconversion as coordcon
from chessboard_data import wbt as wb
import copy
import pymsgbox
TRANS = (63,72,204)
###### Data about initial pieces setup ######
initialSetup = {
"wp1" : ["A","2","pawn"],
"wp2" : ["B","2","pawn"],
"wp3" : ["C","2","pawn"],
"wp4" : ["D","2","pawn"],
"wp5" : ["E","2","pawn"],
"wp6" : ["F","2","pawn"],
"wp7" : ["G","2","pawn"],
"wp8" : ["H","2","pawn"],
"wr1" : ["A","1","rook"],
"wr2" : ["H","1","rook"],
"wn1" : ["B","1","knight"],
"wn2" : ["G","1","knight"],
"wb1" : ["C","1","bishop"],
"wb2" : ["F","1","bishop"],
"wqu" : ["D","1","queen"],
"wki" : ["E","1","king"],
"bp1" : ["A","7","pawn"],
"bp2" : ["B","7","pawn"],
"bp3" : ["C","7","pawn"],
"bp4" : ["D","7","pawn"],
"bp5" : ["E","7","pawn"],
"bp6" : ["F","7","pawn"],
"bp7" : ["G","7","pawn"],
"bp8" : ["H","7","pawn"],
"br1" : ["A","8","rook"],
"br2" : ["H","8","rook"],
"bn1" : ["B","8","knight"],
"bn2" : ["G","8","knight"],
"bb1" : ["C","8","bishop"],
"bb2" : ["F","8","bishop"],
"bqu" : ["D","8","queen"],
"bki" : ["E","8","king"]
}
white_setup_keys = ["wp1","wp2","wp3","wp4","wp5","wp6","wp7","wp8","wr1","wr2","wn1","wn2","wb1","wb2","wqu","wki"]
black_setup_keys = ["bp1","bp2","bp3","bp4","bp5","bp6","bp7","bp8","br1","br2","bn1","bn2","bb1","bb2","bqu","bki"]
### Chesspiece class ###
class Chesspiece(pygame.sprite.Sprite):
def __init__(self, screen, pos, images,pref,whitegroup,blackgroup):
# Declaring self to be a sprite
pygame.sprite.Sprite.__init__(self)
# initialPosition = starting position of piece from initialSetup dict
# self.col = column in chess notation
# self.row = row in chess notation
# self.square = position in chess notation
# self.pref = unique 3-letter piece reference
# self.team = 'w' or 'b'
# self.hasMoved = boolean telling whether piece has moved from initial position
initialPosition = initialSetup[pref]
self.col = initialPosition[0]
self.row = initialPosition[1]
self.square = self.col+self.row
self.pref = pref
self.team = pref[0]
self.hasMoved = False
if self.team == 'w':
self.tgroup = whitegroup
else:
self.tgroup = blackgroup
self.images = images
self.pos = pos
# self.image = image of piece
# self.rect = set-up rect for piece
# self.screen = screen piece is on
imref = pref[0]+"_"+initialPosition[2]
self.image = images[imref]
self.rect = self.image.get_rect()
self.rect.topleft = [pos[self.col],pos[self.row]]
self.screen = screen
# self.squareSize is size of individual square in pixels
# self.grid is the cartesian coords of the chess notation
self.squareSize = pos["size"]
self.grid = pos
self.possibleMoves = []
def display(self):
self.screen.blit(self.image,self.rect)
def select(self,turnCounter):
colour = self.pref[0]
deselectedPosX = self.rect.topleft[0]
deselectedPosY = self.rect.topleft[1]
change = self.squareSize/7
turnCounter.pieceSelection = self.pref
if colour == "w":
self.rect.topleft = [deselectedPosX,deselectedPosY-change]
else:
self.rect.topleft = [deselectedPosX,deselectedPosY+change]
def deselect(self,turnCounter):
colour = self.pref[0]
deselectedPosX = self.rect.topleft[0]
deselectedPosY = self.rect.topleft[1]
change = self.squareSize/7
turnCounter.pieceSelection = "null"
if colour == "w":
self.rect.topleft = [deselectedPosX,deselectedPosY+change]
else:
self.rect.topleft = [deselectedPosX,deselectedPosY-change]
def move(self,target):
moveX = self.grid[target[0]]
moveY = self.grid[target[1]]
self.rect.topleft = [moveX,moveY]
self.square = target
self.col = target[0]
self.row = target[1]
self.hasMoved = True
def taken(self):
self.kill()
def isMoveLegal(self,map,target,sprites):
# Checks whether move is legal or not.
# Checks whether target square is on the list returned from
# legal moves function, then produces a provisional map
# of the board and checks whether king would be left in check
# if target is on the list of possible moves, and king not in check,
# returns True. Else, returns False.
moves = self.legalMoves(map)
inMoves = target in moves
if inMoves == True:
# Setting up potential future map
futureMap = copy.deepcopy(map)
futureMap[target[0]][target[1]] = self.pref
futureMap[self.col][self.row] = 'null'
teamKingCoords = sprites[self.team+'ki'].square
if self.pref[1] == 'k':
check = self.isCheck(futureMap,teamKingCoords,target)
else:
check = self.isCheck(futureMap,teamKingCoords,teamKingCoords)
if check == False:
return True
else:
return False
else:
return False
def isCheck(self,map,currentKingSquare,querySquare):
# Given a map, returns a boolean as to whether the king would be
# in check at the query square. If currentKingSquare = querySquare,
# determines whether king is currently in check
self.isPosInCheck = 1
team = self.team
square = querySquare
# Moving king to square being queried
if currentKingSquare != querySquare:
remap = map
remap[currentKingSquare[0]][currentKingSquare[1]] = 'null'
remap[querySquare[0]][querySquare[1]] = team+'ki'
else:
remap = map
# Directions to check for check in
checkDirectionsNotKnight = [
'north',
'north-east',
'east','south-east',
'south',
'south-west',
'west',
'north-west'
]
checkDirectionsKnights = [
'k1',
'k2',
'k3',
'k4',
'k5',
'k6',
'k7',
'k8'
]
# Running search for check from long range pieces
for direction in checkDirectionsNotKnight:
self.checkSearch(remap,direction,square,True)
# Running search for check from knights
for direction in checkDirectionsKnights:
self.checkSearch(remap,direction,square,False)
# Searching for check from pawns
self.ischeckFromPawn(remap,self.team,square)
if self.isPosInCheck == 1:
return False
elif self.isPosInCheck == 0 :
return True
def checkSearch(self, map, direction, square, recurse):
#Algorith similar to directionalSearch
possibleDirections = {
'north': (0,1),
'north-east': (1,1),
'east': (1,0),
'south-east': (1,-1),
'south': (0, -1),
'south-west': (-1,-1),
'west': (-1, 0),
'north-west': (-1, 1),
'k1': (1,2),
'k2': (2,1),
'k3': (2,-1),
'k4': (1,-2),
'k5': (-1,-2),
'k6': (-2,-1),
'k7': (-1,2),
'k8': (-2,1)
}
possibleThreats = {
'north': ['q','r'],
'north-east': ['q','b'],
'east': ['q','r'],
'south-east': ['q','b'],
'south': ['q','r'],
'south-west': ['q','b'],
'west': ['q','r'],
'north-west': ['q','b'],
'k1': ['n'],
'k2': ['n'],
'k3': ['n'],
'k4': ['n'],
'k5': ['n'],
'k6': ['n'],
'k7': ['n'],
'k8': ['n']
}
x = square[0]
y = square[1]
iterativeVector = possibleDirections[direction]
# Iterating once in given direction
x = coordcon["l2n"][x]
x += iterativeVector[0]
y = int(y)
y += iterativeVector[1]
# Checking still on board
if y < 9 and x < 9 and y > 0 and x > 0:
y = str(y)
x = coordcon["n2l"][str(x)]
testSquare = x+y
# checking square is empty or opposite team
if self.isEmpty(map,testSquare) is True:
if recurse is True:
self.checkSearch(map, direction, testSquare,recurse)
elif self.isOtherTeam(map,testSquare) is True:
squareOccupant = map[x][y]
for threat in possibleThreats[direction]:
if threat == squareOccupant[1]:
# Position is in check
self.isPosInCheck = self.isPosInCheck * 0
def directionalSearch(self, map, direction, square, recurse):
# Recursive function to find all possible spaces moving
# directly in a specific direction.
# Iterates once in that direction, checks next space is
# on the board, then checks if the space is empty or
# contains a piece of the opposite team
possibleDirections = {
'north': (0,1),
'north-east': (1,1),
'east': (1,0),
'south-east': (1,-1),
'south': (0, -1),
'south-west': (-1,-1),
'west': (-1, 0),
'north-west': (-1, 1),
'k1': (1,2),
'k2': (2,1),
'k3': (2,-1),
'k4': (1,-2),
'k5': (-1,-2),
'k6': (-2,-1),
'k7': (-1,2),
'k8': (-2,1)
}
x = square[0]
y = square[1]
iterativeVector = possibleDirections[direction]
# Iterating once in given direction
x = coordcon["l2n"][x]
x += iterativeVector[0]
y = int(y)
y += iterativeVector[1]
# Checking still on board
if y < 9 and x < 9 and y > 0 and x > 0:
y = str(y)
x = coordcon["n2l"][str(x)]
testSquare = x+y
# checking square is empty or opposite team
if self.isEmpty(map,testSquare) is True:
self.possibleMoves.append(testSquare)
if recurse is True:
self.directionalSearch(map, direction, testSquare,recurse)
elif self.isOtherTeam(map,testSquare) is True:
self.possibleMoves.append(testSquare)
def isOtherTeam(self, map, square):
# returns true if square is empty or occupied by a member of
# the other team, else reutrns false
squareStatus = map[square[0]][square[1]]
team = self.team
if (squareStatus[0] == 'b' and team == 'w') or (squareStatus[0] == 'w' and team == 'b') :
return True
else:
return False
def ischeckFromPawn(self,remap,team,square):
kingX = coordcon['l2n'][square[0]]
kingY = int(square[1])
x1 = kingX-1
x2 = kingX+1
if team == 'w':
# White team, pawn position must be higher
Y = kingY+1
if Y < 9:
Y = str(Y)
if x1 > 0:
trialX = coordcon['n2l'][str(x1)]
status = remap[trialX][Y]
if status[0] == 'b' and status[1] == 'p':
self.isPosInCheck = self.isPosInCheck * 0
if x2 < 9:
trialX = coordcon['n2l'][str(x2)]
status = remap[trialX][Y]
if status[0] == 'b' and status[1] == 'p':
self.isPosInCheck = self.isPosInCheck * 0
else:
# Black team, pawn position must be lower
Y = kingY-1
if Y > 0:
Y = str(Y)
if x1 > 0:
trialX = coordcon['n2l'][str(x1)]
status = remap[trialX][Y]
if status[0] == 'w' and status[1] == 'p':
self.isPosInCheck = self.isPosInCheck * 0
if x2 < 9:
trialX = coordcon['n2l'][str(x2)]
status = remap[trialX][Y]
if status[0] == 'w' and status[1] == 'p':
self.isPosInCheck = self.isPosInCheck * 0
def isEmpty(self, map, square):
# returns true if square is empty or occupied by a member of
# the other team, else reutrns false
squareStatus = map[square[0]][square[1]]
if squareStatus == 'null':
return True
else:
return False
class King(Chesspiece):
def __init__(self,screen,pos,sprites,pref,whitegroup,blackgroup):
Chesspiece.__init__(self,screen,pos,sprites,pref,whitegroup,blackgroup)
self.directions = [
'north',
'north-east',
'east',
'south-east',
'south',
'south-west',
'west',
'north-west'
]
def legalMoves(self,map):
directions = self.directions
position = self.square
self.possibleMoves = []
for direction in directions:
self.directionalSearch(map, direction, position, recurse = False)
return self.possibleMoves
class Queen(Chesspiece):
def __init__(self,screen,pos,sprites,pref,whitegroup,blackgroup):
Chesspiece.__init__(self,screen,pos,sprites,pref,whitegroup,blackgroup)
self.directions = [
'north',
'north-east',
'east',
'south-east',
'south',
'south-west',
'west',
'north-west'
]
def legalMoves(self,map):
directions = self.directions
position = self.square
self.possibleMoves = []
for direction in directions:
self.directionalSearch(map, direction, position, recurse = True)
return self.possibleMoves
class Bishop(Chesspiece):
def __init__(self,screen,pos,sprites,pref,whitegroup,blackgroup):
Chesspiece.__init__(self,screen,pos,sprites,pref,whitegroup,blackgroup)
self.directions = [
'north-east',
'south-east',
'south-west',
'north-west'
]
def legalMoves(self,map):
directions = self.directions
position = self.square
self.possibleMoves = []
for direction in directions:
self.directionalSearch(map, direction, position, recurse = True)
return self.possibleMoves
class Knight(Chesspiece):
def __init__(self,screen,pos,sprites,pref,whitegroup,blackgroup):
Chesspiece.__init__(self,screen,pos,sprites,pref,whitegroup,blackgroup)
self.directions = [
'k1',
'k2',
'k3',
'k4',
'k5',
'k6',
'k7',
'k8'
]
def legalMoves(self,map):
directions = self.directions
position = self.square
self.possibleMoves = []
for direction in directions:
self.directionalSearch(map, direction, position, recurse = False)
return self.possibleMoves
class Rook(Chesspiece):
def __init__(self,screen,pos,sprites,pref,whitegroup,blackgroup):
Chesspiece.__init__(self,screen,pos,sprites,pref,whitegroup,blackgroup)
self.directions = [
'north',
'east',
'south',
'west',
]
def legalMoves(self,map):
directions = self.directions
position = self.square
self.possibleMoves = []
for direction in directions:
self.directionalSearch(map, direction, position, recurse = True)
return self.possibleMoves
class Pawn(Chesspiece):
def __init__(self,screen,pos,sprites,pref,whitegroup,blackgroup):
Chesspiece.__init__(self,screen,pos,sprites,pref,whitegroup,blackgroup)
def legalMoves(self,map):
# Tests for legal moves case by case
# Recalling current position of pawn
position = self.square
self.possibleMoves = []
# Converting coords to integers
x = coordcon['l2n'][position[0]]
y = int(position[1])
# Pawn team determines which direction it can move in
if self.team == 'w':
# 1 step forward
y += 1
if y < 9:
targetX = position[0]
targetY = str(y)
targetSqr = targetX+targetY
if map[targetX][targetY] == 'null':
self.possibleMoves.append(targetSqr)
# Checking diagonal taking
if x - 1 > 0:
targetX = coordcon['n2l'][str(x-1)]
targetSqr = targetX+targetY
targetPiece = map[targetX][targetY]
if targetPiece[0] == 'b':
self.possibleMoves.append(targetSqr)
if x + 1 < 9:
targetX = coordcon['n2l'][str(x+1)]
targetSqr = targetX+targetY
targetPiece = map[targetX][targetY]
if targetPiece[0] == 'b':
self.possibleMoves.append(targetSqr)
# First move 2 steps
if self.hasMoved == False:
y += 1
targetX = position[0]
targetY = str(y)
targetSqr = targetX+targetY
if map[targetX][targetY] == 'null':
self.possibleMoves.append(targetSqr)
elif self.team == 'b':
# 1 step forward
y -= 1
if y > 0:
targetX = position[0]
targetY = str(y)
targetSqr = targetX+targetY
if map[targetX][targetY] == 'null':
self.possibleMoves.append(targetSqr)
# Checking diagonal taking
if x - 1 > 0:
targetX = coordcon['n2l'][str(x-1)]
targetSqr = targetX+targetY
targetPiece = map[targetX][targetY]
if targetPiece[0] == 'w':
self.possibleMoves.append(targetSqr)
if x + 1 < 9:
targetX = coordcon['n2l'][str(x+1)]
targetSqr = targetX+targetY
targetPiece = map[targetX][targetY]
if targetPiece[0] == 'w':
self.possibleMoves.append(targetSqr)
# First move 2 steps
if self.hasMoved == False:
y -= 1
targetX = position[0]
targetY = str(y)
targetSqr = targetX+targetY
if map[targetX][targetY] == 'null':
self.possibleMoves.append(targetSqr)
return self.possibleMoves
def move(self,target):
moveX = self.grid[target[0]]
moveY = self.grid[target[1]]
self.rect.topleft = [moveX,moveY]
self.square = target
self.col = target[0]
self.row = target[1]
self.hasMoved = True
### function loading pieces pictures
def load_pieces(square_size):
# Loading sprite sheet
ss = SpriteSheet('Sprites/Pieces_trans.png')
# Storing each image in directory
# Kings
w_king = pygame.transform.scale(ss.image_at((0,0,200,200)),(square_size,square_size))
w_king.set_colorkey(TRANS)
b_king = pygame.transform.scale(ss.image_at((0,200,200,200)),(square_size,square_size))
b_king.set_colorkey(TRANS)
# Queens
w_queen = pygame.transform.scale(ss.image_at((200,0,200,200)),(square_size,square_size))
w_queen.set_colorkey(TRANS)
b_queen = pygame.transform.scale(ss.image_at((200,200,200,200)),(square_size,square_size))
b_queen.set_colorkey(TRANS)
# Bishops
w_bishop = pygame.transform.scale(ss.image_at((400,0,200,200)),(square_size,square_size))
w_bishop.set_colorkey(TRANS)
b_bishop = pygame.transform.scale(ss.image_at((400,200,200,200)),(square_size,square_size))
b_bishop.set_colorkey(TRANS)
# Knights
w_knight = pygame.transform.scale(ss.image_at((600,0,200,200)),(square_size,square_size))
w_knight.set_colorkey(TRANS)
b_knight = pygame.transform.scale(ss.image_at((600,200,200,200)),(square_size,square_size))
b_knight.set_colorkey(TRANS)
# Rook
w_rook = pygame.transform.scale(ss.image_at((800,0,200,200)),(square_size,square_size))
w_rook.set_colorkey(TRANS)
b_rook = pygame.transform.scale(ss.image_at((800,200,200,200)),(square_size,square_size))
b_rook.set_colorkey(TRANS)
# Pawn
w_pawn = pygame.transform.scale(ss.image_at((1000,0,200,200)),(square_size,square_size))
w_pawn.set_colorkey(TRANS)
b_pawn = pygame.transform.scale(ss.image_at((1000,200,200,200)),(square_size,square_size))
b_pawn.set_colorkey(TRANS)
pieces = {
"w_king" : w_king,
"b_king" : b_king,
"w_queen" : w_queen,
"b_queen" : b_queen,
"w_bishop" : w_bishop,
"b_bishop" : b_bishop,
"w_knight" : w_knight,
"b_knight" : b_knight,
"w_rook" : w_rook,
"b_rook" : b_rook,
"w_pawn" : w_pawn,
"b_pawn" : b_pawn
}
return pieces
# Placing sprites on board
def initial_setup_board(screen,whitegroup,blackgroup,pos,images):
sprite_dict = {}
# Queens
sprite_dict['wqu'] = Queen(screen,pos,images,'wqu',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wqu'])
sprite_dict['bqu'] = Queen(screen,pos,images,'bqu',whitegroup,blackgroup)
blackgroup.add(sprite_dict['bqu'])
#Kings
sprite_dict['wki'] = King(screen,pos,images,'wki',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wki'])
sprite_dict['bki'] = King(screen,pos,images,'bki',whitegroup,blackgroup)
blackgroup.add(sprite_dict['bki'])
#Bishop
sprite_dict['wb1'] = Bishop(screen,pos,images,'wb1',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wb1'])
sprite_dict['wb2'] = Bishop(screen,pos,images,'wb2',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wb2'])
sprite_dict['bb1'] = Bishop(screen,pos,images,'bb1',whitegroup,blackgroup)
blackgroup.add(sprite_dict['bb1'])
sprite_dict['bb2'] = Bishop(screen,pos,images,'bb2',whitegroup,blackgroup)
blackgroup.add(sprite_dict['bb2'])
#Knight
sprite_dict['wn1'] = Knight(screen,pos,images,'wn1',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wn1'])
sprite_dict['wn2'] = Knight(screen,pos,images,'wn2',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wn2'])
sprite_dict['bn1'] = Knight(screen,pos,images,'bn1',whitegroup,blackgroup)
blackgroup.add(sprite_dict['bn1'])
sprite_dict['bn2'] = Knight(screen,pos,images,'bn2',whitegroup,blackgroup)
blackgroup.add(sprite_dict['bn2'])
#Rook
sprite_dict['wr1'] = Rook(screen,pos,images,'wr1',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wr1'])
sprite_dict['wr2'] = Rook(screen,pos,images,'wr2',whitegroup,blackgroup)
whitegroup.add(sprite_dict['wr2'])
sprite_dict['br1'] = Rook(screen,pos,images,'br1',whitegroup,blackgroup)
blackgroup.add(sprite_dict['br1'])
sprite_dict['br2'] = Rook(screen,pos,images,'br2',whitegroup,blackgroup)
blackgroup.add(sprite_dict['br2'])
#Pawns
white_pawn_keys = ["wp1","wp2","wp3","wp4","wp5","wp6","wp7","wp8"]
black_pawn_keys = ["bp1","bp2","bp3","bp4","bp5","bp6","bp7","bp8"]
for key in white_pawn_keys:
sprite_dict[key] = Pawn(screen,pos,images,key,whitegroup,blackgroup)
whitegroup.add(sprite_dict[key])
for key in black_pawn_keys:
sprite_dict[key] = Pawn(screen,pos,images,key,whitegroup,blackgroup)
blackgroup.add(sprite_dict[key])
return sprite_dict