Exemplo n.º 1
0
def playVersusAINoReplay(difficulty, player1, player2):
    running = True

    board = boardLogic.createBoard()
    pieces = boardLogic.createPieces()
    
    turn = Turn.PLAYER

    prints.printFancyBoard(board, turn, player1, player2)
    prints.printPieces(pieces)
    
    prints.printPieceToGive(pieces)
    piece = userInput.askForPiece(pieces)
    turn = Turn.OPPONENT

    while (running):
        if (turn == Turn.PLAYER):
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToPlace(piece, turn)
            coords = userInput.askWhereToPlace(board)
            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
          #      input('Press enter to advance')
                return result
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)        
            piece = userInput.askForPiece(pieces)        
            turn = Turn.OPPONENT

        else:
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            time.sleep(0.5)
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
         #       input('Press enter to advance')
                return result
            piece = AI.placePiece(board, piece, difficulty) #add difficulty
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
        #        input('Press enter to advance')
                return result
            piece = AI.pickPiece(board, pieces, difficulty) #add difficulty
            

            turn = Turn.PLAYER
Exemplo n.º 2
0
def playAIvsAI(difficulty, player1, player2):
    running = True

    board = boardLogic.createBoard()
    pieces = boardLogic.createPieces()
    
    turn = Turn.OPPONENT

   # prints.printFancyBoard(board, turn)
   # prints.printPieces(pieces)
    

    piece = AI.pickPiece(board, pieces, difficulty)
    turn = Turn.PLAYER

    while (running):
        if (turn == Turn.PLAYER):
    #        prints.printFancyBoard(board, turn)
     #       prints.printPieces(pieces)

            boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            piece = AI.placePiece(board, piece, difficulty)
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
                #input('Press enter to advance')
                return result
            piece = AI.pickPiece(board, pieces, difficulty)        
            turn = Turn.OPPONENT
        else:
      #      prints.printFancyBoard(board, turn)
       #     prints.printPieces(pieces)

            boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            piece = AI.placePiece(board, piece, difficulty)
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
                #input('Press enter to advance')
                return result
            piece = AI.pickPiece(board, pieces, difficulty)            
            turn = Turn.PLAYER
Exemplo n.º 3
0
def playVersusAI(difficulty, player1, player2):
    running = True

    board = boardLogic.createBoard()
    pieces = boardLogic.createPieces()
    
    turn = Turn.PLAYER

    prints.printFancyBoard(board, turn, player1, player2)
    prints.printPieces(pieces)
    
    prints.printPieceToGive(pieces)
    piece = userInput.askForPiece(pieces)
    turn = Turn.OPPONENT

    while (running):
        if (turn == Turn.PLAYER):
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToPlace(piece, turn)
            coords = userInput.askWhereToPlace(board)
            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            boardLogic.endGame(board, piece, turn, player1, player2)            
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)        
            piece = userInput.askForPiece(pieces)        
            turn = Turn.OPPONENT

        else:
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            time.sleep(0.5)
            boardLogic.endGame(board, piece, turn, player1, player2)
            piece = AI.placePiece(board, piece, difficulty) #add difficulty
            boardLogic.endGame(board, piece, turn, player1, player2) 
            piece = AI.pickPiece(board, pieces, difficulty) #add difficulty
            

            turn = Turn.PLAYER
Exemplo n.º 4
0
def playVersusHuman(player1, player2):
    running = True

    board = boardLogic.createBoard()
    pieces = boardLogic.createPieces()
    
    turn = Turn.PLAYER

    prints.printFancyBoard(board, turn, player1, player2)
    prints.printPieces(pieces)
    
    prints.printPieceToGive(pieces)
    piece = userInput.askForPiece(pieces)
    turn = Turn.OPPONENT

    while (running):
        if (turn == Turn.PLAYER):
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToPlace(piece, turn)
            coords = userInput.askWhereToPlace(board)
            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            boardLogic.endGame(board, piece, turn, player1, player2)            
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)        
            piece = userInput.askForPiece(pieces)        
            turn = Turn.OPPONENT
        else:
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToPlace(piece, turn)
            coords = userInput.askWhereToPlace(board)
            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            boardLogic.endGame(board, piece, turn, player1, player2)            
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)        
            piece = userInput.askForPiece(pieces)        
            turn = Turn.PLAYER
Exemplo n.º 5
0
def playOnlineVersus(host, player1, player2):
    running = True

    connection = peer.Peer(host)

    board = boardLogic.createBoard()
    pieces = boardLogic.createPieces()

    firstTurn = True
    if (host):
        turn = Turn.PLAYER
        connection.accept_client()

        # First turn (just handing a piece)
        prints.printFancyBoard(board, turn, player1, player2)
        prints.printPieces(pieces)
        prints.printPieceToGive(pieces)
        piece = userInput.askForPiece(pieces)
        turn = Turn.OPPONENT
        connection.send([piece, pieces, board])
        firstTurn = False

    else:
        turn = Turn.OPPONENT
        connection.connect_to_server()
        prints.printFancyBoard(board, turn, player1, player2)
        prints.printPieces(pieces)

    while (running):
        if (firstTurn):
            [piece, pieces, board] = connection.receive()
            turn = Turn.PLAYER
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            #Show given piece and place it
            prints.printPieceToPlace(piece, turn)
            coords = userInput.askWhereToPlace(board)
            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            connection.send([piece, pieces, board])
            # Pick a piece for opponent
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToGive(pieces)
            piece = userInput.askForPiece(pieces)
            connection.send([piece, pieces, board])
            firstTurn = False
            turn = Turn.OPPONENT
        else:
            turn = Turn.OPPONENT
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            [piece, pieces, board] = connection.receive()
            boardLogic.endGame(board, piece, turn, player1, player2)   

            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            [piece, pieces, board] = connection.receive()
            turn = Turn.PLAYER
            # Show given piece, place it
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToPlace(piece, turn)
            coords = userInput.askWhereToPlace(board)
            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            connection.send([piece, pieces, board])
            boardLogic.endGame(board, piece, turn, player1, player2)            
        
            # Pick a piece for opponent
            prints.printFancyBoard(board, turn,  player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToGive(pieces)
            piece = userInput.askForPiece(pieces)
            turn = Turn.OPPONENT
            connection.send([piece, pieces, board])
Exemplo n.º 6
0
def playOnlineAI(host, connection, player1, player2):
    running = True

#    connection = peer.Peer(host)

    board = boardLogic.createBoard()
    pieces = boardLogic.createPieces()
    difficulty = Difficulty.HARD

    firstTurn = True
    if (host):
        turn = Turn.PLAYER
 #       connection.accept_client()

        # First turn (just handing a piece)
        prints.printFancyBoard(board, turn, player1, player2)
        prints.printPieces(pieces)
        prints.printPieceToGive(pieces)
        piece = AI.pickPiece(board, pieces, difficulty) 
        turn = Turn.OPPONENT
        time.sleep(0.05)
        connection.send([piece, pieces, board])
        firstTurn = False

    else:
        turn = Turn.OPPONENT
#        connection.connect_to_server()
        prints.printFancyBoard(board, turn, player1, player2)
        prints.printPieces(pieces)

    while (running):
        if (firstTurn):
            [piece, pieces, board] = connection.receive()
            turn = Turn.PLAYER
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            #Show given piece and place it
            prints.printPieceToPlace(piece, turn)
            AI.placePiece(board, piece, difficulty) #add difficulty        
#            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            time.sleep(0.05)
            connection.send([piece, pieces, board])
            # Pick a piece for opponent
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToGive(pieces)
            piece = AI.pickPiece(board, pieces, difficulty) #add difficulty
            time.sleep(0.05)
            connection.send([piece, pieces, board])
            firstTurn = False
            turn = Turn.OPPONENT
        else:
            turn = Turn.OPPONENT
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            [piece, pieces, board] = connection.receive()
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
            #    input('Press enter to advance')
                return result

            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            [piece, pieces, board] = connection.receive()
            turn = Turn.PLAYER
            # Show given piece, place it
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToPlace(piece, turn)
            AI.placePiece(board, piece, difficulty) #add difficulty
#            boardLogic.updateBoard(board, piece, int(coords[0]), int(coords[1]))
            time.sleep(0.05)
            connection.send([piece, pieces, board])
            result = boardLogic.endGameNoReplay(board, piece, turn, player1, player2)
            if (result != 'NONE'):
           #     input('Press enter to advance')
                return result
        
            # Pick a piece for opponent
            prints.printFancyBoard(board, turn, player1, player2)
            prints.printPieces(pieces)
            prints.printPieceToGive(pieces)
            piece = AI.pickPiece(board, pieces, difficulty)
            turn = Turn.OPPONENT
            time.sleep(0.05)
            connection.send([piece, pieces, board])