@ADoctor/

Pre-release AS 2019 - Edited

Python

Original name: FairStylishSphere

fork
loading
Files
  • main.py
  • game1.txt
  • game2.txt
  • game3.txt
  • game4.txt
main.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
# Skeleton Program for the AQA A1 Summer 2019 examination
# this code should be used in conjunction with the Preliminary Material
# written by the AQA AS1 Programmer Team
# developed in a Python 3 environment

# Version number: 0.1.3

import random
import traceback

SPACE = '     '
UNUSED = 'XXXXX'

BOARD_SIZE = 8
NUMBER_OF_PIECES = 12
MAX_MOVES = 50
ROW = 0
COLUMN = 1
DAME = 2

class MoveRecord:
  def __init__(self):
    self.Piece = ''
    self.NewRow = -1
    self.NewColumn = -1
    self.CanJump = False

def LoadPieces(FileHandle, PlayersPieces):   
  for Index in range(NUMBER_OF_PIECES + 1):
    PlayersPieces[Index][ROW] = int(FileHandle.readline())
    PlayersPieces[Index][COLUMN] = int(FileHandle.readline())
    PlayersPieces[Index][DAME] = int(FileHandle.readline())
  return PlayersPieces

def CreateNewBoard(Board): 
  for ThisRow in range(BOARD_SIZE):
    for ThisColumn in range(BOARD_SIZE):
      if (ThisRow + ThisColumn) % 2 == 0:
        Board[ThisRow][ThisColumn] = UNUSED
      else:
        Board[ThisRow][ThisColumn] = SPACE
  return Board

def AddPlayerA(Board, A):
  for Index in range(1, NUMBER_OF_PIECES + 1):
    print(A)
    PieceRow = A[Index][ROW]
    PieceColumn = A[Index][COLUMN]
    PieceDame = A[Index][DAME]
    if PieceRow > -1:
      if PieceDame == 1:
        Board[PieceRow][PieceColumn] = 'A' + str(Index)
      else:
        Board[PieceRow][PieceColumn] = 'a' + str(Index)
  return Board
    
def AddPlayerB(Board, B):      
  for Index in range(1, NUMBER_OF_PIECES + 1):
    PieceRow = B[Index][ROW]
    PieceColumn = B[Index][COLUMN]
    PieceDame = B[Index][DAME]
    if PieceRow > -1:
      if PieceDame == 1:
        Board[PieceRow][PieceColumn] = 'B' + str(Index)
      else:
        Board[PieceRow][PieceColumn] = 'b' + str(Index)   
  return Board

def DisplayErrorCode(ErrorNumber):
  errors = ["1 - Invalid piece chosen","2 - Cannot move to space","3 - Co-ordinate input was not a integer","4 - File not found"]
  print('Error',errors[ErrorNumber-1])

def SaveGame(A,B):
  saved = False
  while saved == False:
    saveName = input("Please input the file name you wish to use: ")
    if saveName[(len(saveName)-4):] != '.txt':
      saveName += '.txt'
    try:
      fileTest = open(saveName,'r')
      overwrite = 'X'
      while overwrite != 'Y' and overwrite != 'N':
        overwrite = input("That file name has already been used. Do you want to overwrite it?")
        if overwrite == 'Y':
          print("Saving...")
          continueSaving = True
        elif overwrite == 'N':
          continueSaving = False
        else:
          print("Sorry, that's not a valid option.")
    except:
      print("That file name has not yet been used. Saving...")
      continueSaving = True
    if continueSaving == True:
      fileSave = open(saveName,'w')
      for i in A:
        fileSave.write(str(i[0]))
        fileSave.write('\n')
        fileSave.write(str(i[1]))
        fileSave.write('\n')
        fileSave.write(str(i[2]))
        fileSave.write('\n')
      for i in range(0,len(B)):
        fileSave.write(str(B[i][0]))
        fileSave.write('\n')
        fileSave.write(str(B[i][1]))
        fileSave.write('\n')
        fileSave.write(str(B[i][2]))
        if i != len(B)-1:
          fileSave.write('\n')
      saved = True

def SetPieceLocation(PieceCreated,PieceDame,PieceRow,PieceColumn,Board,PiecesSoFar):
  if 0 <= PieceRow < BOARD_SIZE and 0 <= PieceColumn < BOARD_SIZE:
    if PieceDame == 'Y':
      PieceDame = 1
    else:
      PieceDame = 0
    if [PieceRow,PieceColumn,0] not in PiecesSoFar and [PieceRow,PieceColumn,1] not in PiecesSoFar:
      if Board[PieceRow][PieceColumn] == SPACE:
        PieceCreated = True
      else:
        print("Invalid Location - Location is not a space.")
    else:
      print("Invalid Location - Location has already been used.")
  else:
    print("Invalid Location - Row and Column must be a natural number lower than the board size of {0}.".format(BOARD_SIZE))
  return PieceCreated,PieceDame

def GetPieceInfo(PiecesPerPlayer,Board,PlayerPieces):
  for i in range(1,PiecesPerPlayer+1):
    PieceCreated = False
    while PieceCreated != True:
      try:
        print("Piece {0} of {1}:".format(i,PiecesPerPlayer))
        PieceRow = int(input("What row will this piece be on? "))
        PieceColumn = int(input("What column will this piece be on? "))
        PieceDame = input("Is this piece a dame? (Y/N) ").upper()
        if PieceDame == 'Y' or PieceDame == 'N':
          PieceCreated,PieceDame = SetPieceLocation(PieceCreated,PieceDame,PieceRow,PieceColumn,Board,PlayerPieces)
        else:
          print("Invalid Dame Response - Must be Y or N.")
      except ValueError:
        print("Invalid Location - Row and Column must be a natural number lower than the board size of {0}.".format(BOARD_SIZE))
    PlayerPieces.append([PieceRow,PieceColumn,PieceDame])
  return PlayerPieces

def CreateAllPieces(Board,PiecesPerPlayer):
  print("Player A:")
  A = [[0,0,0]]
  A = GetPieceInfo(PiecesPerPlayer,Board,A)
  for i in range(0,NUMBER_OF_PIECES-PiecesPerPlayer):
    A.append([-1,-1,0])
  print("Player B:")
  B = [[0,0,0]]
  B = GetPieceInfo(PiecesPerPlayer,Board,B)
  for i in range(0,NUMBER_OF_PIECES-PiecesPerPlayer):
    B.append([-1,-1,0])
  return Board,A,B

def CreateCustomBoard(Board):
  Board = CreateNewBoard(Board)
  PiecesPerPlayer = NUMBER_OF_PIECES + 1
  while PiecesPerPlayer <= 0 or PiecesPerPlayer > NUMBER_OF_PIECES:
    try:
      PiecesPerPlayer = int(input("How many pieces do you want each player to have? "))
      if PiecesPerPlayer <= 0:
        print("Sorry, your value must be at least 1.")
      elif PiecesPerPlayer > NUMBER_OF_PIECES:
        print("Sorry, your value is too high to load all the pieces.")
    except ValueError:
      print("Sorry, but your value needs to be an integer.")
  Board, A, B = CreateAllPieces(Board,PiecesPerPlayer)
  Board = AddPlayerA(Board, A)
  Board = AddPlayerB(Board, B)
  SaveGame(A,B)
  return A, B, Board

def SetUpBoard(Board, A, B, FileFound):
  while True:
    Answer = input('Do you want to load a saved game or board template? (Y/N): ').upper()
    if Answer == 'Y':
      FileName = input('Enter the filename: ')
      if FileName[(len(FileName)-4):] != '.txt':
        FileName += '.txt'
      try:
        FileHandle = open(FileName, 'r')
        FileFound = True
        A = LoadPieces(FileHandle, A)
        B = LoadPieces(FileHandle, B)
        FileHandle.close()
        Board = CreateNewBoard(Board)
        Board = AddPlayerA(Board, A)
        Board = AddPlayerB(Board, B)
        break
      except:
        DisplayErrorCode(4)
        FileFound == 'Error'
    elif Answer == 'N':
      SecondAnswer = input('Do you want to create a custom board? (Y/N): ').upper()
      if SecondAnswer == 'Y':
        A, B, Board = CreateCustomBoard(Board)
        FileFound = True
        break
      elif SecondAnswer == 'N': 
        A, B, Board = '', '', []
        break
      else:
        print("Sorry, that's not a valid answer.")
    else:
      print("Sorry, that's not a valid answer.")
  return Board, A, B, FileFound

def PrintHeading():
  print('    ', end='')
  for BoardColumn in range(BOARD_SIZE):
    print('{0:3}'.format(BoardColumn), end='   ')
  print()
  
def PrintRow(Board, ThisRow):
  print('   |', end='')
  for BoardColumn in range(BOARD_SIZE):
    if Board[ThisRow][BoardColumn] == UNUSED:
      print(Board[ThisRow][BoardColumn], end='|')
    else:
      print(SPACE, end='|')
  print()

def PrintMiddleRow(Board, ThisRow):    
  print('{0:>2}'.format(ThisRow), end=' |')
  for BoardColumn in range(BOARD_SIZE):
    if Board[ThisRow][BoardColumn] == UNUSED or Board[ThisRow][BoardColumn] == SPACE:
      print(Board[ThisRow][BoardColumn], end='|')
    else:
     print('{0:>4}'.format(Board[ThisRow][BoardColumn]), end=' |')
  print()
       
def PrintLine():  
  print('   ', end='')
  for BoardColumn in range(BOARD_SIZE):
    print('------', end='')
  print('-')

def DisplayBoard(Board):
  PrintHeading()
  PrintLine()
  for ThisRow in range(BOARD_SIZE):
    PrintRow(Board, ThisRow)
    PrintMiddleRow(Board, ThisRow)
    PrintRow(Board, ThisRow)
    PrintLine()

def PrintPlayerPieces(A, B):
  print()
  print('Player A:')
  print(A)
  print('Player B:')
  print(B)
  print()
  
def ClearList(ListOfMoves):
  for Index in range(MAX_MOVES):
    ListOfMoves[Index].Piece = ''
    ListOfMoves[Index].NewRow = -1
    ListOfMoves[Index].NewColumn = -1
    ListOfMoves[Index].CanJump = False
  return ListOfMoves

def ValidMove(Board, NewRow, NewColumn):
  Valid = False
  if NewRow in range(BOARD_SIZE) and NewColumn in range(BOARD_SIZE):  
    if Board[NewRow][NewColumn] == SPACE: 
      Valid = True        
  return Valid

def ValidJump(Board, PlayersPieces, Piece, NewRow, NewColumn):
  Valid = False
  MiddlePiece = ''
  Player = Piece[0].lower()
  Index = int(Piece[1:])
  if Player == 'a':
    OppositePiecePlayer = 'b'
  else:
    OppositePiecePlayer = 'a'
  if NewRow in range(BOARD_SIZE) and NewColumn in range(BOARD_SIZE):  
    if Board[NewRow][NewColumn] == SPACE: 
      CurrentRow = PlayersPieces[Index][ROW]
      CurrentColumn = PlayersPieces[Index][COLUMN]
      MiddlePieceRow = (CurrentRow + NewRow) // 2
      MiddlePieceColumn = (CurrentColumn + NewColumn) // 2
      MiddlePiece = Board[MiddlePieceRow][MiddlePieceColumn]
      MiddlePiecePlayer = MiddlePiece[0].lower()
      if MiddlePiecePlayer != ' ':
        Valid = True       
  return Valid

def ValidTeleport(PlayersPieces,NextPlayer,ListOfMoves,NumberOfMoves,Board):
  if NextPlayer == 'a':
    EndRow = 7
  else:
    EndRow = 0
  for i in range(1, NUMBER_OF_PIECES + 1):
    if PlayersPieces[i][DAME] == 1:
      for j in range(0,EndRow):
        if Board[7][j] == SPACE:
          Piece = NextPlayer.upper() + str(i)
          print(Piece, 'can teleport to ', EndRow, ' , ', j)
          ListOfMoves[NumberOfMoves].Piece = Piece
          ListOfMoves[NumberOfMoves].NewRow = EndRow
          ListOfMoves[NumberOfMoves].NewColumn = j
          ListOfMoves[NumberOfMoves].CanJump = False
          NumberOfMoves += 1
  return ListOfMoves,NumberOfMoves

def TestMove(Piece,Board,NewRow,LeftColumn,RightColumn,JumpRow,JumpLeftColumn,JumpRightColumn,ListOfMoves,NumberOfMoves,PlayersPieces,jumpsOnly,PieceMoved):
  if jumpsOnly == False:
    if ValidMove(Board, NewRow, LeftColumn):
      print(Piece, ' can move to ', NewRow, ' , ', LeftColumn)
      NumberOfMoves += 1
      ListOfMoves[NumberOfMoves].Piece = Piece
      ListOfMoves[NumberOfMoves].NewRow = NewRow
      ListOfMoves[NumberOfMoves].NewColumn = LeftColumn
      ListOfMoves[NumberOfMoves].CanJump = False   
    if ValidMove(Board, NewRow, RightColumn):
      print(Piece, ' can move to ', NewRow, ' , ', RightColumn)
      NumberOfMoves += 1
      ListOfMoves[NumberOfMoves].Piece = Piece
      ListOfMoves[NumberOfMoves].NewRow = NewRow
      ListOfMoves[NumberOfMoves].NewColumn = RightColumn
      ListOfMoves[NumberOfMoves].CanJump = False 
    if ValidJump(Board, PlayersPieces, Piece, JumpRow, JumpLeftColumn):
      print(Piece, ' can jump to ', JumpRow, ' , ', JumpLeftColumn)
      NumberOfMoves += 1
      ListOfMoves[NumberOfMoves].Piece = Piece
      ListOfMoves[NumberOfMoves].NewRow = JumpRow
      ListOfMoves[NumberOfMoves].NewColumn = JumpLeftColumn
      ListOfMoves[NumberOfMoves].CanJump = True 
    if ValidJump(Board, PlayersPieces, Piece, JumpRow, JumpRightColumn):
      print(Piece, ' can jump to ', JumpRow, ' , ', JumpRightColumn)    
      NumberOfMoves += 1
      ListOfMoves[NumberOfMoves].Piece = Piece
      ListOfMoves[NumberOfMoves].NewRow = JumpRow
      ListOfMoves[NumberOfMoves].NewColumn = JumpRightColumn
      ListOfMoves[NumberOfMoves].CanJump = True 
  else:
    if ValidJump(Board, PlayersPieces, Piece, JumpRow, JumpLeftColumn) and Piece == PieceMoved:
      print(Piece, ' can jump to ', JumpRow, ' , ', JumpLeftColumn)
      NumberOfMoves += 1
      ListOfMoves[NumberOfMoves].Piece = Piece
      ListOfMoves[NumberOfMoves].NewRow = JumpRow
      ListOfMoves[NumberOfMoves].NewColumn = JumpLeftColumn
      ListOfMoves[NumberOfMoves].CanJump = True 
    if ValidJump(Board, PlayersPieces, Piece, JumpRow, JumpRightColumn) and Piece == PieceMoved:
      print(Piece, ' can jump to ', JumpRow, ' , ', JumpRightColumn)    
      NumberOfMoves += 1
      ListOfMoves[NumberOfMoves].Piece = Piece
      ListOfMoves[NumberOfMoves].NewRow = JumpRow
      ListOfMoves[NumberOfMoves].NewColumn = JumpRightColumn
      ListOfMoves[NumberOfMoves].CanJump = True
  return ListOfMoves,NumberOfMoves

def ListPossibleMoves(Board, PlayersPieces, NextPlayer, ListOfMoves, jumpsOnly, PieceMoved):
  if NextPlayer == 'a':
    Direction = 1
  else:
    Direction = -1
  NumberOfMoves = 0
  for i in range(1, NUMBER_OF_PIECES + 1):
    Piece = NextPlayer + str(i)
    CurrentRow = PlayersPieces[i][ROW]
    CurrentColumn = PlayersPieces[i][COLUMN]
    if PlayersPieces[i][DAME] == 1:
      Piece = Piece.upper()
    NewRow = CurrentRow + Direction  
    LeftColumn = CurrentColumn - 1
    RightColumn = CurrentColumn + 1
    JumpRow = CurrentRow + Direction + Direction
    JumpLeftColumn = CurrentColumn - 2
    JumpRightColumn = CurrentColumn + 2
    ListOfMoves,NumberOfMoves = TestMove(Piece,Board,NewRow,LeftColumn,RightColumn,JumpRow,JumpLeftColumn,JumpRightColumn,ListOfMoves,NumberOfMoves,PlayersPieces,jumpsOnly,PieceMoved)
    if PlayersPieces[i][DAME] == 1:
      NewRow = CurrentRow - Direction
      JumpRow = CurrentRow - Direction - Direction
      ListOfMoves,NumberOfMoves = TestMove(Piece,Board,NewRow,LeftColumn,RightColumn,JumpRow,JumpLeftColumn,JumpRightColumn,ListOfMoves,NumberOfMoves,PlayersPieces,jumpsOnly,PieceMoved)
  if ListEmpty(ListOfMoves) and jumpsOnly == False:
    ListOfMoves,NumberOfMoves = ValidTeleport(PlayersPieces,NextPlayer,ListOfMoves,NumberOfMoves,Board)      
  print('There are ', NumberOfMoves, ' possible moves')
  return ListOfMoves

def ListEmpty(ListOfMoves):
  if ListOfMoves[1].Piece == '':
    return True
  else:
    return False
  
def SelectMove(ListOfMoves):
  ValidPiece = False
  while not ValidPiece:
    Found = False
    EndOfList = False
    PieceMoving = input('Which piece do you want to move? ')
    Index = 0
    if PieceMoving == '':
      EndOfList = True
    while not Found and not EndOfList:
      Index += 1
      if ListOfMoves[Index].Piece == PieceMoving:
        Found = True
      elif ListOfMoves[Index].Piece == '':
        EndOfList = True
        DisplayErrorCode(1) 
    if Found:
        ValidPiece = True
  ChosenPieceIndex = Index
  ValidMove = False
  while not ValidMove:
    RowString = input('Which row do you want to move to? ')
    ColumnString = input('Which column do you want to move to? ')
    try:
      NewRow = int(RowString)
      NewColumn = int(ColumnString)
      Found = False
      EndOfList = False 
      Index = ChosenPieceIndex - 1
      while not Found and not EndOfList:
        Index += 1
        if ListOfMoves[Index].Piece != PieceMoving:
          EndOfList = True
          DisplayErrorCode(2)  
        elif ListOfMoves[Index].NewRow == NewRow and ListOfMoves[Index].NewColumn == NewColumn:
          Found = True
      ValidMove = Found
    except:
      DisplayErrorCode(3)  
  return Index,PieceMoving

def MoveDame(Board, Player, NewRow, NewColumn):
  spaceFound = False #Allows the program to stop looking for an empty space when one is found
  if Player == 'a':
    lookupRow = 0 #Starts from the top
    rowInc = 1 #Goes downwards
  else:
    lookupRow = BOARD_SIZE - 1 #Starts from the bottom
    rowInc = -1 #Goes upwards
  while spaceFound == False:
    for i in range (0, BOARD_SIZE - 1):
      if Board[lookupRow][i] == SPACE: #Checks if the space is empty
        NewColumn = i #Sets new co-ordinates
        NewRow = lookupRow
        spaceFound = True #Used to break out of the while loop
        break #Breaks out of the for loop
    lookupRow += rowInc #Goes to the next row, as no empty spaces found
  return NewRow, NewColumn
  
def MovePiece(Board, PlayersPieces, ChosenPiece, NewRow, NewColumn):
  Index = int(ChosenPiece[1:])
  CurrentRow = PlayersPieces[Index][ROW]
  CurrentColumn = PlayersPieces[Index][COLUMN]
  Board[CurrentRow][CurrentColumn] = SPACE
  
  if NewRow == BOARD_SIZE - 1 and PlayersPieces[Index][DAME] == 0:
    Player = 'a'
    PlayersPieces[0][1] += 1
    PlayersPieces[Index][DAME] = 1
    ChosenPiece = ChosenPiece.upper()
    NewRow, NewColumn = MoveDame(Board, Player, NewRow, NewColumn) 
  elif NewRow == 0 and PlayersPieces[Index][DAME] == 0:
    Player = 'b'
    PlayersPieces[0][1] += 1
    PlayersPieces[Index][DAME] = 1
    ChosenPiece = ChosenPiece.upper()
    NewRow, NewColumn = MoveDame(Board, Player, NewRow, NewColumn) 
  PlayersPieces[Index][ROW] = NewRow
  PlayersPieces[Index][COLUMN] = NewColumn
  Board[NewRow][NewColumn] = ChosenPiece  
  return Board, PlayersPieces

def MakeMove(Board, PlayersPieces, OpponentsPieces, ListOfMoves, PieceIndex, canDoubleJump):
  PlayersPieces[0][0] += 1
  if PieceIndex > 0:
    Piece = ListOfMoves[PieceIndex].Piece
    NewRow = ListOfMoves[PieceIndex].NewRow
    NewColumn = ListOfMoves[PieceIndex].NewColumn
    PlayersPieceIndex = int(Piece[1:])
    CurrentRow = PlayersPieces[PlayersPieceIndex][ROW]
    CurrentColumn = PlayersPieces[PlayersPieceIndex][COLUMN]
    Jumping = ListOfMoves[PieceIndex].CanJump
    Board, PlayersPieces = MovePiece(Board, PlayersPieces, Piece, NewRow, NewColumn)
    if Jumping:
      MiddlePieceRow = (CurrentRow + NewRow) // 2
      MiddlePieceColumn = (CurrentColumn + NewColumn) // 2
      MiddlePiece = Board[MiddlePieceRow][MiddlePieceColumn]
      Player = Piece[0].lower()
      if (Player == 'a' and MiddlePiece[:1] == 'b') or (Player == 'b' and MiddlePiece[:1] == 'a'):
        Board[MiddlePieceRow][MiddlePieceColumn] = SPACE
        OpponentsPieces[int(MiddlePiece[1:])][0]=-1
        OpponentsPieces[int(MiddlePiece[1:])][1]=-1
      print('jumped over ', MiddlePiece)
      if canDoubleJump == False:
        canDoubleJump = True
      else:
        canDoubleJump = False
    else:
      canDoubleJump = False
  return Board, PlayersPieces, OpponentsPieces, canDoubleJump

def ComputerMove(ListOfMoves):
  FoundPiece = False
  for i in range(0,len(ListOfMoves)-1):
    if ListOfMoves[i].NewRow == 0:
      Index = i
      Piece = ListOfMoves[i].Piece
      NewRow = ListOfMoves[i].NewRow
      NewColumn = ListOfMoves[i].NewColumn
      FoundPiece = True
  while FoundPiece == False:
    i = random.randint(0,len(ListOfMoves)-1)
    if ListOfMoves[i].NewRow != -1:
      Index = i
      Piece = ListOfMoves[i].Piece
      NewRow = ListOfMoves[i].NewRow
      NewColumn = ListOfMoves[i].NewColumn
      FoundPiece = True
  print("""Piece Moved: {0}
Row moved to: {1}
Column moved to: {2}""".format(Piece,NewRow,NewColumn))
  return Index

def SwapPlayer(NextPlayer):
  if NextPlayer == 'a':
    return 'b'
  else:
    return 'a'

def PrintResult(A, B, NextPlayer, EndFromSave):
  if EndFromSave == True:
    print("Game saved. You can access this game at any time from the filename you specified.")
  else:
    print('Game ended')
    print(NextPlayer,'lost this game as they cannot make a move')
  PrintPlayerPieces(A, B)

def Game():
  bComputerCheck = 'X'
  while bComputerCheck != 'H' and bComputerCheck != 'C':
    bComputerCheck = input("Will Player B be human- or computer-controlled? (H or C) ").upper()
    if bComputerCheck == 'H':
      bComputer = False
    elif bComputerCheck == 'C':
      bComputer = True
    else:
      print("Sorry, that's an invalid response. Please enter 'H' or 'C'.")
  A = [[0, 0, 0] for Piece in range(NUMBER_OF_PIECES + 1)]
  B = [[0, 0, 0] for Piece in range(NUMBER_OF_PIECES + 1)]
  Board = [['' for Column in range(BOARD_SIZE)] for Row in range(BOARD_SIZE)]
  ListOfMoves = [MoveRecord() for Move in range(MAX_MOVES)]
  GameEnd = False
  FileFound = False
  Players = ['a','b']
  NextPlayer = Players[random.randint(0,1)]
  Board, A, B,  FileFound = SetUpBoard(Board, A, B, FileFound)
  totalMovesMade = -1
  aMovesMade = -1
  bMovesMade = -1
  while FileFound == 'Error':
    print("Sorry, an error occured. Please try again.")
    Board, A, B,  FileFound = SetUpBoard(Board, A, B, FileFound)
  if not FileFound:
    GameEnd = True
  while not GameEnd:
    canDoubleJump = False
    totalMovesMade += 1
    PrintPlayerPieces(A, B)
    DisplayBoard(Board)
    print('Next Player: ', NextPlayer) 
    ListOfMoves = ClearList(ListOfMoves)
    print("Total moves made:",totalMovesMade)
    if NextPlayer == 'a':
      aMovesMade += 1
      print("Moves so far made by player a:",aMovesMade)
      ListOfMoves = ListPossibleMoves(Board, A, NextPlayer, ListOfMoves, False, 'x0')
      if not ListEmpty(ListOfMoves):
        skipMove = 'X'
        while skipMove != 'N' and skipMove != 'Y':
          skipMove = input("Do you wish to skip your move? (Y/N) ").upper()
          if skipMove != 'N' and skipMove != 'Y':
            print("Sorry, please input 'Y' or 'N'.")
        if skipMove == 'N':
          PieceIndex,PieceMoved = SelectMove(ListOfMoves)
          Board, A, B, canDoubleJump = MakeMove(Board, A, B, ListOfMoves, PieceIndex, canDoubleJump)
          if canDoubleJump == True:
            ListOfMoves = ClearList(ListOfMoves)
            ListOfMoves = ListPossibleMoves(Board, A, NextPlayer, ListOfMoves, True, PieceMoved)
            if not ListEmpty(ListOfMoves):
              skipJump = 'X'
              while skipJump != 'N' and skipJump != 'Y':
                skipJump = input("Do you wish to skip your double jump? (Y/N) ").upper()
                if skipJump != 'N' and skipJump != 'Y':
                  print("Sorry, please input 'Y' or 'N'.")
              if skipJump == 'N':
                PieceIndex,PieceMoved = SelectMove(ListOfMoves)
                Board, A, B, canDoubleJump = MakeMove(Board, A, B, ListOfMoves, PieceIndex, canDoubleJump)
        else:
          totalMovesMade -= 1
          aMovesMade -= 1
        NextPlayer = SwapPlayer(NextPlayer)
      else:
        GameEnd = True
    elif bComputer == True:
      bMovesMade += 1
      print("Moves made so far by player b:",bMovesMade)
      ListOfMoves = ListPossibleMoves(Board, B, NextPlayer, ListOfMoves)
      if not ListEmpty(ListOfMoves):
        PieceIndex = ComputerMove(ListOfMoves)
        Board, B, A = MakeMove(Board, B, A, ListOfMoves, PieceIndex)
        NextPlayer = SwapPlayer(NextPlayer)
      else:
        GameEnd = True
    else:
      bMovesMade += 1
      print("Moves made so far by player b:",bMovesMade)
      ListOfMoves = ListPossibleMoves(Board, B, NextPlayer, ListOfMoves, False, 'x0')
      if not ListEmpty(ListOfMoves):
        skipMove = 'X'
        while skipMove != 'N' and skipMove != 'Y':
          skipMove = input("Do you wish to skip your move? (Y/N) ").upper()
          if skipMove != 'N' and skipMove != 'Y':
            print("Sorry, please input 'Y' or 'N'.")
        if skipMove == 'N':
          PieceIndex,PieceMoved = SelectMove(ListOfMoves)
          Board, B, A, canDoubleJump = MakeMove(Board, B, A, ListOfMoves, PieceIndex, canDoubleJump)
          if canDoubleJump == True:
            ListOfMoves = ClearList(ListOfMoves)
            ListOfMoves = ListPossibleMoves(Board, B, NextPlayer, ListOfMoves, True, PieceMoved)
            if not ListEmpty(ListOfMoves):
              skipJump = 'X'
              while skipJump != 'N' and skipJump != 'Y':
                skipJump = input("Do you wish to skip your double jump? (Y/N) ").upper()
                if skipJump != 'N' and skipJump != 'Y':
                  print("Sorry, please input 'Y' or 'N'.")
              if skipJump == 'N':
                PieceIndex,PieceMoved = SelectMove(ListOfMoves)
                Board, B, A, canDoubleJump = MakeMove(Board, B, A, ListOfMoves, PieceIndex, canDoubleJump)
        else:
          totalMovesMade -= 1
          bMovesMade -= 1
        NextPlayer = SwapPlayer(NextPlayer)
      else:
        GameEnd = True
    saveCheck = 'X'
    while saveCheck != 'Y' and saveCheck != 'N' and not ListEmpty(ListOfMoves):
      saveCheck = input("Do you want to save? (Y/N) ").upper()
      if saveCheck == 'Y':
        SaveGame(A,B)
        GameEnd = True
        EndFromSave = True
      elif saveCheck != 'N':
        print("Sorry, that's not a valid option.")
  if FileFound:
    try:
      if EndFromSave == False:
        print("")
    except:
      EndFromSave = False
      print("")
    PrintResult(A, B , NextPlayer, EndFromSave)

if __name__ == "__main__":
  Game()      

print("Goodbye!")

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#             Objective             #Solution exists#Solution coded?#
#       Make player skip turn       #       Y       #       Y       # 
#     Adding '.txt' if required     #       Y       #       Y       #
#   Display number of moves taken   #       Y       #       Y       #
#    Show error values' meanings    #       Y       #       Y       #
# Allow taking of opponent's pieces #       Y       #       Y       #
#           Save the game           #       Y       #       Y       #
#     Saves specify next player     #       N       #       N       # 
#    Don't place dame if no room    #       N       #       N       # 
#     Make dame movement better     #       Y       #       Y       # 
# Have Player B computer controlled #       Y       #       Y       # 
# Let user create custom game files #       Y       #       Y       #
#    Allow pieces to double jump    #       Y       #       Y       # 
#   Check next row to place dames   #       Y       #       Y       #
#  Randomly pick a player to start  #       Y       #       Y       #
#        Use for 'game4.txt'        #       Y       #       Y       #
#                                   #               #               #
#                                   #               #               #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #