예제 #1
0
def make_prediction(board, move):
    # real outcomes
    from_square = squares[move.from_square]
    to_square = squares[move.to_square]

    arr = transform_board(board)
    arr = np.array(arr).reshape(1,9,8,12)

    # move prediction
    from_square_prediction = squares[np.argmax(model_from.predict(arr))]
    to_square_prediction = squares[np.argmax(model_to.predict(arr))]

    print('The model predicts: '+str(from_square_prediction)+' to '+str(to_square_prediction)+' and the real move was '+str(from_square)+' to '+str(to_square))
    display_board(board, move)
def random_board(H, W):
    board = build_map(H, W)

    ghosts_pos = obj_generation(2, 3, H, W, board)
    board = change_board(ghosts_pos, 3, board)

    walls_pos = obj_generation(3, 10, H, W, board)
    board = change_board(walls_pos, 0, board)

    pacman_pos = obj_generation(1, 2, H, W, board)
    board = change_board(pacman_pos, 4, board)
    display_board(board)

    return board, ghosts_pos, walls_pos, pacman_pos
예제 #3
0
def play(board):
    # print('starting random play')
    moves = 0

    while True:
        make_random_move(board)
        moves += 1
        # utils.display_board(board)

        if utils.check_if_won(board):
            break

    # print('random play done')
    utils.display_board(board)
    return moves
예제 #4
0
def play(board):
    moves = 0

    while True:
        make_move(board)
        moves += 1
        print('moves: ',moves)
        # utils.display_board(board)

        if utils.check_if_won(board):
            break

    # print('hunt play done')
    utils.display_board(board)
    return moves
예제 #5
0
def play(board):
    global remaining_ships
    moves = 0

    while True:
        prepare_to_make_move(board)
        moves += 1
        print('moves: ', moves)
        # utils.display_board(board)

        # resetting remaining ships
        remaining_ships = []
        floating_ships = utils.get_floating_ships(board)
        for ship_number in floating_ships:
            remaining_ships.append(utils.ships[ship_number - 1][2])

        if utils.check_if_won(board):
            break

    # print('hunt play done')
    utils.display_board(board)
    return moves
def continuously_move(board, pacman_pos, ghosts_pos, strategy):
    # Ghosts sit initially on empty cells
    restore_info = [1 for g in ghosts_pos]
    s = get_strategy(strategy)
    score = 0

    # moves
    m = 0

    while m < 100:
        m += 1
        display_board(board)

        # Move PACMAN
        old_pos = copy.deepcopy(pacman_pos)
        pacman_pos = s.move(board, old_pos, ghosts_pos, score)
        board[old_pos[0]][old_pos[1]] = 1
        if board[pacman_pos[0]][pacman_pos[1]] == 2:
            print "Gotcha!"
            score += 1
        board[pacman_pos[0]][pacman_pos[1]] = 4

        # Check win
        if win(board, score):
            return score

        # Move ghosts
        for i in range(0, len(ghosts_pos)):
            board, ghosts_pos[i], restore_info[i] = \
            move(board, 3, ghosts_pos[i], restore_info[i])
            if loose(board, score):
                return score

        # delay the board change to see what happens.
        time.sleep(0.5)

    return score
예제 #7
0
    def two_player(self, board):
        '''
		Play in 2 player mode
		'''
        keyboardIndexMapping = constants.keyboardIndexMapping
        playerOne, playerTwo, playerOneChar, playerTwoChar, whichPlayerFirst = utils.getTwoPlayerDetails(
        )
        move_mapping = {playerOne: playerOneChar, playerTwo: playerTwoChar}

        if whichPlayerFirst == 1:
            chance = playerOne
        else:
            chance = playerTwo

        while (utils.check_win(board, playerOneChar, playerTwoChar)[0] == 0):
            utils.clearScreen()
            utils.display_board(board)
            print(chance + ": Your chance")
            index = int(input())
            if index > 9 or index < 1:
                utils.clearScreen()
                continue
            index = keyboardIndexMapping[index]
            if (board[index] != '-'):
                continue
            board[index] = move_mapping[chance]
            if (chance == playerOne):
                chance = playerTwo
            else:
                chance = playerOne
        [isWin, whoWon] = utils.check_win(board, playerOneChar, playerTwoChar)
        if (isWin == 2):
            utils.clearScreen()
            utils.display_board(board)
            print("It's a tie")
        if (isWin == 1):
            utils.clearScreen()
            utils.display_board(board)
            if (whoWon == playerOneChar):
                print(playerOne + " won!")
            else:
                print(playerTwo + " won!")
예제 #8
0
    def one_player(self, board):
        """
		Play with the computer
		"""
        keyboardIndexMapping = constants.keyboardIndexMapping
        computerChar, playerChar, displayWinChance, whichPlayerFirst = utils.getSinglePlayerDetails(
        )

        if whichPlayerFirst == 1:
            utils.clearScreen()
            utils.display_board(board)
            while utils.check_win(board, computerChar, playerChar)[0] == 0:
                if utils.check_empty(board):
                    tut = [0, 0, 0, 0, 0, 0, 0, 0, 0]
                else:
                    tut = [
                        -i for i in self.minimax(board, playerChar,
                                                 computerChar, playerChar)
                    ]
                if displayWinChance == 1:
                    utils.clearScreen()
                    utils.display_tutorial_board(board, tut)
                index = int(input())
                if index > 9 or index < 1:
                    utils.clearScreen()
                    utils.display_board(board)
                    if displayWinChance == 1:
                        utils.clearScreen()
                        utils.display_tutorial_board(board, tut)
                    continue
                index = keyboardIndexMapping[index]
                # cant use already used index
                if board[index] != '-':
                    utils.clearScreen()
                    utils.display_board(board)
                    if displayWinChance == 1:
                        utils.clearScreen()
                        utils.display_tutorial_board(board, tut)
                    continue
                board[index] = playerChar
                utils.clearScreen()
                utils.display_board(board)
                if displayWinChance == 1:
                    utils.clearScreen()
                    utils.display_tutorial_board(board, tut)
                if utils.check_win(board, computerChar, playerChar)[0] != 0:
                    break
                ret = self.minimax(board, computerChar, computerChar,
                                   playerChar)
                # chose move for computer
                board[utils.the_move(board, ret)] = computerChar
                utils.clearScreen()
                utils.display_board(board)
            if utils.check_win(board, computerChar, playerChar)[0] == 1:
                print("You lost!!")
            else:
                print("It's a draw!")

        if whichPlayerFirst == 2:
            while utils.check_win(board, computerChar, playerChar)[0] == 0:
                if utils.check_empty(board):
                    board[random.randrange(0, 9)] = computerChar
                else:
                    ret = self.minimax(board, computerChar, computerChar,
                                       playerChar)
                    # chose move for computer
                    board[utils.the_move(board, ret)] = computerChar
                utils.clearScreen()
                utils.display_board(board)
                if utils.check_win(board, computerChar, playerChar)[0] != 0:
                    break
                # index already used can't be reused
                flag = 0
                while flag == 0:
                    tut = [
                        -i for i in self.minimax(board, playerChar,
                                                 computerChar, playerChar)
                    ]
                    utils.clearScreen()
                    utils.display_board(board)
                    if displayWinChance == 1:
                        utils.clearScreen()
                        utils.display_tutorial_board(board, tut)
                    index = int(input())
                    if index > 9 or index < 1:
                        utils.clearScreen()
                        utils.display_board(board)
                        if displayWinChance == 1:
                            utils.clearScreen()
                            utils.display_tutorial_board(board, tut)
                        continue
                    index = keyboardIndexMapping[index]
                    if board[index] == '-':
                        flag = 1
                        board[index] = playerChar
                        utils.clearScreen()
                        utils.display_board(board)
                        if displayWinChance == 1:
                            utils.clearScreen()
                            utils.display_tutorial_board(board, tut)
                    else:
                        utils.clearScreen()
                        utils.display_board(board)
                        if displayWinChance == 1:
                            utils.clearScreen()
                            utils.display_tutorial_board(board, tut)

            if utils.check_win(board, computerChar, playerChar)[0] == 1:
                print("You lost!!")
            else:
                print("It's a draw!")