Example #1
0
def playVersusHumanNoReplay(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)
            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.PLAYER
Example #2
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
Example #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
Example #4
0
def endGameNoReplay(board, piece, turn, player, opponent):
    choice = False

    win = determineState(board, piece)
    if (win and turn == game.Turn.PLAYER):
        prints.printFancyBoard(board, turn, player, opponent)
        print('      ', end='')
        prints.eprint(player, prints.sf.GREEN, True, False)
        prints.eprint(' won!', prints.sf.WHITE, True, True)
        return player

    elif (win and turn == game.Turn.OPPONENT):
        prints.printFancyBoard(board, turn, player, opponent)
        print('      ', end='')
        prints.eprint(opponent, prints.sf.RED, True, False)
        prints.eprint(' won!', prints.sf.WHITE, True, True)
        return opponent

    elif (not win and not movesRemaining(board)):
        prints.printFancyBoard(board, turn, player, opponent)
        prints.eprint('It\'s a tie!', prints.sf.YELLOW, True, True)
        return 'DRAW'
    return 'NONE'
Example #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])
Example #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])