Esempio n. 1
0
def analyze(design):
    """
        Gets a design object from p6_tool
        Do breath first search to find path for every position, 
        Save a dictionary of parent states.
    """
    global ANALYSIS
    sim = Simulator(design)

    init = sim.get_initial_state()
    ANALYSIS = {init: (None, None)}

    queue = []
    queue.append(init)

    while queue:
        curr_state = queue.pop(
            0)  # list.pop(0) gets the first item, pop() gets the last one
        adj_list = get_adj(sim, curr_state)
        for adj in adj_list:
            if adj not in ANALYSIS:
                queue.append(adj)
                ANALYSIS[adj] = curr_state

    return
Esempio n. 2
0
def analyze(design):

    sim = Simulator(design)
    init = sim.get_initial_state()  #states are position, abilities
    ANALYSIS = {init: None}
    queue = Q.PriorityQueue()
    queue.put((0, init[0], init[1]))

    while not queue.empty():
        curr_state = queue.get()
        moves = sim.get_moves()
        states = []

        for m in moves:
            print curr_state
            if sim.get_next_state((curr_state[1], curr_state[2]), m) != None:
                pos, abs = sim.get_next_state((curr_state[1], curr_state[2]),
                                              m)
                state = (curr_state[0] + 1, pos, abs)
                states.append(state)

        for s in states:
            this = (s[1], s[2])
            if this not in ANALYSIS:
                ANALYSIS[this] = (curr_state[1], curr_state[2])
                queue.put(s)

    return ANALYSIS
Esempio n. 3
0
def analyze(design):

    visited = []
    prev = {}
    queve = deque()
    abilities = {}
    # visited = []
    sim = Simulator(design)
    init = sim.get_initial_state()
    init_pos, init_ability = init

    abilities[init_pos] = init_ability
    # print ANALYSIS[init_pos]

    visited.append(init_pos)
    queve.append(init)
    # # while queve is not empty
    while queve:

        current_state = queve.popleft()
        current_position, current_abilities = current_state

        #     # if node has reached its destination cell it will quit while loop
        #     # calls the get_steps function stored in adj
        moves = sim.get_moves()
        for next_move in moves:
            if next_move == "NOTHING":
                continue

            next_state = sim.get_next_state(current_state, next_move)
            if next_state == None:
                # ANALYSIS[next_position] = None
                continue
            # if in the current state the character dies ignore this state

            next_position, next_abilities = next_state

            if next_position == current_position:
                continue

            # stores new ability into Analysis for later use when it comes to drawing out the lines
            if next_position not in visited:
                visited.append(next_position)
                abilities[next_position] = current_abilities
                prev[next_position] = current_position
                queve.append(next_state)
            elif next_position in visited:
                for ability in next_abilities:
                    if ability not in abilities[next_position]:
                        abilities[next_position] = current_abilities
                        ANALYSIS.append(prev)
                        prev.clear()
                        prev[current_position] = None
                        prev[next_position] = current_position
                        queve.append(next_state)

    ANALYSIS[str(len(abilities))] = prev

    # ANALYSIS.reverse()
    print current_abilities
Esempio n. 4
0
def analyze(design):
    sim = Simulator(design)
    specials = design['specials']
    init = sim.get_initial_state()
    frontier = []
    frontier.append(init)
    global ANALYSIS
    ANALYSIS = {
        init: (None, None)
    }  # Reset the ANALYSIS dictionary to scrub out old data.

    while len(frontier) > 0:
        current = frontier.pop(0)
        for neighbor in _get_neighbors(sim, current):
            if neighbor not in ANALYSIS:
                # Record the unvisited state
                frontier.append(neighbor)
                ANALYSIS[neighbor] = current

    # Check if goal coordinate (Special 5) is reachable
    reach = False
    for state in ANALYSIS:
        position, _ = state
        if specials.get(position, 0) == 5:
            reach = True
            break
    if reach:
        print "Special 5 is reachable!"
    else:
        print "Special 5 is NON reachable!"
Esempio n. 5
0
def analyze(design):
    sim = Simulator(design)
    init = sim.get_initial_state()
    moves = sim.get_moves()
    next_state = sim.get_next_state(init, moves[0])

    queue = Queue.Queue()
    queue.put(next_state)
    ANALYSIS[next_state] = None
    while not queue.empty():
        current = queue.get()
        for i in range(0, 4):
            next = sim.get_next_state(current, moves[i])
            if next == None:
                continue
            if next not in ANALYSIS:
                queue.put(next)
                ANALYSIS[next] = current
Esempio n. 6
0
def analyze(design):
    PREV.clear()

    sim = Simulator(design)
    init = sim.get_initial_state()
    moves = sim.get_moves()

    queue = []
    queue.append(init)
    PREV[init] = None

    while queue:
        current_state = queue.pop(0)
        for move in moves:
            next_state = sim.get_next_state(current_state, move)
            if next_state != None and next_state not in PREV:
                queue.append(next_state)
                PREV[next_state] = current_state
Esempio n. 7
0
def analyze(design):
    sim = Simulator(design)
    # TODO: fill in this function, populating the ANALYSIS dict
    queue = [sim.get_initial_state()]
    ANALYSIS.clear()
    PREV.clear()
    ANALYSIS[sim.get_initial_state()[0]] = [sim.get_initial_state()]
    PREV[sim.get_initial_state()] = None
    while (queue):
        current_state = queue.pop()
        for move in sim.get_moves():
            next_state = sim.get_next_state(current_state, move)
            if next_state:
                if next_state not in PREV:
                    position, _ = next_state  # or None if character dies
                    if position not in ANALYSIS:
                        ANALYSIS[position] = []
                    ANALYSIS[position].append(next_state)
                    PREV[next_state] = current_state
                    queue.append(next_state)
Esempio n. 8
0
def analyze(design):
    ANALYSIS.clear()
    queve = deque()
    sim = Simulator(design)
    init = sim.get_initial_state()
    #init_pos, init_ability = init
    #ANALYSIS = {next_state:current_state}
    ANALYSIS[init] = None
    queve.append(init)

    while queve:
        current_state = queve.popleft()
        #current_position,current_abilities = current_state
        moves = sim.get_moves()
        for next_move in moves:
            next_state = sim.get_next_state(current_state, next_move)
            if next_state == None:
                continue
            #next_position, next_abilities = next_state
            if next_state not in ANALYSIS:
                ANALYSIS[next_state] = current_state
                queve.append(next_state)
Esempio n. 9
0
def analyze(design):

    sim = Simulator(design)
    # TODO: fill in this function, populating the ANALYSIS dict
    init = sim.get_initial_state()

    global ANALYSIS

    queue = []
    ANALYSIS = {init: (None, None)}

    queue.append(init)
    while queue:
        curr_state = queue.pop(0)
        adj_list = get_adj(sim, curr_state)
        for adj in adj_list:
            if adj not in ANALYSIS:
                queue.append(adj)
                ANALYSIS[adj] = curr_state

    print ANALYSIS

    return