def succesor_boards(max_player, game, board):
    moves = ['U', 'D', 'L', 'R']
    succs = []
    for move in moves:
        if max_player:
            new_game = Game_IJK(copy.deepcopy(board), "+",
                                game.getDeterministic())
            succ = new_game.makeMove(move)
            succs.append((move, succ.getGame()))
        else:
            new_game = Game_IJK(board, "-", game.getDeterministic())
            succ = new_game.makeMove(move)
            succs.append((move, succ.getGame()))
    return succs
Esempio n. 2
0
def chance_boards(max_player, game, board, move, empty_tiles):
    succs = []
    for i in range(0, empty_tiles):
        if max_player:
            new_game = Game_IJK(copy.deepcopy(board), "+",
                                game.getDeterministic())
            succ = new_game.makeMove(move)
            succs.append((move, succ.getGame()))
        else:
            new_game = Game_IJK(copy.deepcopy(board), "-",
                                game.getDeterministic())
            succ = new_game.makeMove(move)
            succs.append((move, succ.getGame()))
    return succs
Esempio n. 3
0
def find_successors(board, player, deterministic):
    moves = ['L', 'R', 'U', 'D']
    child_nodes = []
    for i in moves:
        game1 = Game_IJK(board, player, deterministic)
        child_nodes.append(game1.makeMove(i).getGame())
    return child_nodes
def Max(move, game: Game_IJK, depth, alpha, beta):

    game = game.makeMove(move)

    depth = depth + 1
    board = game.getGame()

    if (depth == 6):
        return [utility(board), move]

    for m in moves:
        alpha, move = max([alpha, move], Min(move, game, depth, alpha, beta))
        if alpha > beta:
            return [alpha, move]
    return [alpha, move]
Esempio n. 5
0
def max_utility(game: Game_IJK, d, alpha, beta):
    d = d + 1
    state = game.state()
    board = game.getGame()
    if state == 'K' or state == 'k' or state == 'tie' or d == 6:
        return heuristics(board)
    moves = ['U', 'D', 'L', 'R']
    best_utility = float('-inf')
    for move in moves:
        clone = game.makeMove(move)
        utility = min_utility(clone, d, -float('inf'), float('inf'))
        if utility > best_utility:
            best_move = move
            best_utility = utility
            alpha = max(alpha, best_utility)
            if beta <= alpha:
                break
    return best_utility
Esempio n. 6
0
def next_move(game: Game_IJK):
    '''board: list of list of strings -> current state of the game
       current_player: int -> player who will make the next move either ('+') or -'-')
       deterministic: bool -> either True or False, indicating whether the game is deterministic or not
    '''
    board = game.getGame()
    player = game.getCurrentPlayer()
    deterministic = game.getDeterministic()

    # You'll want to put in your fancy AI code here. For right now this just
    # returns a random move.

    moves = ['U', 'D', 'L', 'R']
    best_move = moves[0]
    best_utility = float('-inf')
    for move in moves:
        clone = game.makeMove(move)
        utility = min_utility(clone, 0, -float('inf'), float('inf'))
        if utility > best_utility:
            best_utility = utility
            best_move = move
    yield best_move