Пример #1
0
def Gameover1():
    game = Checkerboard()
    r1 = [0, 0, 0, 0, 0, 0, 0, 0]
    r2 = [0, 0, 0, 0, 0, 0, 0, 0]
    r3 = [0, 0, 0, 0, 0, 0, 0, 0]
    r4 = [0, 0, 0, 0, 0, 0, 0, 0]
    r5 = [0, 0, 0, 0, 0, 0, 0, 0]
    r6 = [-1, 0, -1, 0, -1, 0, -1, 0]
    r7 = [0, -1, 0, -1, 0, -1, 0, -1]
    r8 = [-1, 0, -1, 0, -1, 0, -1, 0]
    game.board = [r1, r2, r3, r4, r5, r6, r7, r8]
    game.turn = 1
    Test1 = TwoPlayers() 
    Test1.enterName("A","B") # The first player A (first one who enters the name) corresponds to chess piece labeled as 1, who loses this game. The second player B (second one who enters the name) corresponds to chess piece labeled as -1, who wins the game.
    Test1.gameProcess(game) # Should not do anything other then print "The game is over. " because clearly the player A loses the game by losing all his chess pieces.
    Test1.gameOver(game) # Should print out "B won the game!"
Пример #2
0
def Gameover2():
    game = Checkerboard()
    r1 = [0, 0, 0, 0, 0, 0, 0, 0]
    r2 = [0, 2, 0, 0, 0, 2, 0, 0]
    r3 = [0, 0, 1, 0, 1, 0, 0, 0]
    r4 = [0, 0, 0, -2, 0, 0, 0, 0]
    r5 = [0, 0, 2, 0, 1, 0, 0, 0]
    r6 = [0, 1, 0, 0, 0, 1, 0, 0]
    r7 = [0, 0, 0, 0, 0, 0, 0, 0]
    r8 = [0, 0, 0, 0, 0, 0, 0, 0]
    game.board = [r1, r2, r3, r4, r5, r6, r7, r8]
    game.turn = -1
    Test2 = TwoPlayers() 
    Test2.enterName("A","B") # The first player A (first one who enters the name) corresponds to chess piece labeled as 1, who wins this game. The second player B (second one who enters the name) corresponds to chess piece labeled as -1, who loses the game.
    Test2.gameProcess(game) # Should not do anything other then print out "The game is over. " because clearly the player B loses the game by not being able to move his chess piece for his turn.
    Test2.gameOver(game) # Should print out "A won the game!"
Пример #3
0
def AIMultipleJumps():
    game = Checkerboard()
    r1 = [0, 0, 1, 0, 0, 0, 0, 0]
    r2 = [0, 0, 0, -1, 0, 0, 0, 0]
    r3 = [0, 0, 0, 0, 0, 0, 0, 0]
    r4 = [0, 0, 0, 0, 0, -1, 0, 0]
    r5 = [0, 0, 0, 0, 0, 0, 0, 0]
    r6 = [0, 0, 0, 0, 0, 0, 0, 0]
    r7 = [0, 0, 0, 0, 0, 0, 0, 0]
    r8 = [0, 0, 0, 0, 0, 0, 0, 0]
    game.board = [r1, r2, r3, r4, r5, r6, r7, r8]
    game.turn = 1
    Test4 = SinglePlayer()
    Test4.state = game
    Test4.turn = game.turn
    Test4.decisionMove() # AI should make the decision of double capturing as requierd by the rule of the game.
    print (Test4.state) # Print out the final result after AI's move, which should be only the chess piece 1 moving from (1,3) to (5,7).
Пример #4
0
def AIAvoidBeingCaptured():
    game = Checkerboard()
    r1 = [0, 0, 0, 0, 0, 0, 0, 0]
    r2 = [0, 0, -1, 0, 0, 0, 0, 0]
    r3 = [1, 0, 0, 0, 0, 0, 0, 0]
    r4 = [0, 1, 0, 0, 0, 0, 0, 0]
    r5 = [0, 0, -1, 0, 0, 0, 0, 0]
    r6 = [0, 0, 0, 0, 0, 0, 0, 0]
    r7 = [0, 0, 0, 0, 0, 0, 0, 0]
    r8 = [0, 0, 0, 0, 0, 0, 0, 0]
    game.board = [r1, r2, r3, r4, r5, r6, r7, r8]
    game.turn = -1
    Test5 = SinglePlayer()
    Test5.state = game
    Test5.turn = game.turn
    print (game)
    Test5.decisionMove() # AI should make the decision of always moving the -1 chess piece at (5,3) to (4,4) because it is in danger of being captured.
    print (Test5.state) # Print out the final result. 
Пример #5
0
def MultipleJumps():
    game = Checkerboard()
    r1 = [0, 0, 1, 0, 0, 0, 0, 0]
    r2 = [0, 0, 0, -1, 0, 0, 0, 0]
    r3 = [0, 0, 0, 0, 0, 0, 0, 0]
    r4 = [0, 0, 0, 0, 0, -1, 0, 0]
    r5 = [0, 0, 0, 0, 0, 0, 0, 0]
    r6 = [0, 0, 0, 0, 0, 0, 0, 0]
    r7 = [0, 0, 0, 0, 0, 0, 0, 0]
    r8 = [0, 0, 0, 0, 0, 0, 0, 0]
    game.board = [r1, r2, r3, r4, r5, r6, r7, r8]
    game.turn = 1
    Test3 = TwoPlayers()
    Test3.enterName("A","B")
    print (game)
    Test3.gameProcess(game) # Should have an interactive process asking A to "choose the piece to move" and "where to move the piece to", and a multiple captures/multiple jumps process is required if the player choose the do the first capture.
    # This test of multiple jumps/captures is shown by the log file of the game too.
    Test3.gameOver(game) # SHould print "A won the game! " after the interactive process.
Пример #6
0
def AIHaveToMoveRealSituation():
    game = Checkerboard()
    r1=[0, 0, 0, 0, 0, 0, 0, 0]
    r2=[1, 0, 1, 0, 1, 0, 1, 0]
    r3=[0, 1, 0, 1, 0, 1, 0, 1]
    r4=[1, 0, -1, 0, 0, 0, 1, 0]
    r5=[0, -1, 0, -1, 0, -1, 0, 1]
    r6=[0, 0, -1, 0, -1, 0, -1, 0]
    r7=[0, -1, 0, -1, 0, -1, 0, 0]
    r8=[0, 0, 0, 0, -1, 0, 0, 0]
    game.board = [r1, r2, r3, r4, r5, r6, r7, r8]
    game.turn = 1
    Test6 = SinglePlayer()
    Test6.state = game
    Test6.turn = game.turn
    print (Test6.state)
    print ("This is the AI's move: ")
    print ("\n")
    Test6.decisionMove() # The AI only have to choices here -- to either move the chess piece at (3,4) or the one at (3,6) to the position (4,5). This is not a safe move, but AI does not have choice so has to do it.
    print (Test6.state) # Print out the final result.
Пример #7
0
     turn = raw_input("Do you want to go first or second? ")
 print ("\n")
 AI.firstOrSecond(turn)
 print(game)
 while game.CheckLost() == False:
     if game.turn == AI.turn:
         print ("This is the AI's move: ")
         AI.currentState(game)
         AI.piecesAvailable()
         AI.allLegalMove()
         if AI.legalMoves != [] or AI.canCapture(): # If AI can not make any more legal moves nor captures, the AI loses the game. This is just an unnecessary double check for the condition specified by the while loop.
             AI.decisionMove()
         else:
             break
         game = AI.state
         game.turn = game.turn * -1
         print(game)
     else:
         f1 = raw_input(player + " choose the piece that you want to move: ")
         t1 = raw_input("Where do you want to move the piece to: ")
         while len(f1)!=5 or len(t1)!=5 or f1[0]!='(' or t1[0]!='(' or f1[2]!=',' or t1[2]!=',' or f1[4]!=')' or t1[4]!=')' or not f1[1].isdigit() or not f1[3].isdigit() or not t1[1].isdigit() or not t1[3].isdigit() or not game.LegalMove((int(f1[1])-1, int(f1[3])-1),(int(t1[1])-1, int(t1[3])-1)):
             print ("Illegal move! Do it again.")
             f1 = raw_input(player + " choose the piece that you want to move: ") # Keep asking inputs until they are correcty entered by the players.
             t1 = raw_input("Where do you want to move the piece to: ")         
         f1 = (int(f1[1])-1, int(f1[3])-1)
         t1 = (int(t1[1])-1, int(t1[3])-1)
         if game.LegalCapture(f1,t1):
             game.Move(f1,t1)
             Player.checkCaptureOrMove(game,f1,t1) # The method that takes care of the multiple capture features of the checker game for a player.
         else:
             game.Move(f1,t1)