Exemplo n.º 1
0
def depthFirstSearch(problem):
    parseStack = utils.Stack()
    state = problem.getStartState()
    parseStack.push(Branch(state)) #push root branch to stack
    visited = set()
    while not parseStack.isEmpty():
        branch = parseStack.pop()
        if branch.state not in visited:
            visited.add(branch.state)
            if problem.isGoalState(branch.state):
                return branch.path()
            for state, action, _ in problem.getSuccessors(branch.state):    
                parseStack.push(Branch(state, action, parent = branch))
Exemplo n.º 2
0
def return_sick_neibohrs(atom_map, neibohrs, p_crews, turn, cand):
    if p_crews == 0:
        sick_neibohrs = ut.Stack()
        for n in neibohrs:
            if turn == 1:
                sick_neibohrs.append(atom_map[n][turn - 1][1])
            elif turn == 2:
                sick_neibohrs.append(atom_map[n][turn - 1][1])
                sick_neibohrs.append(atom_map[n][turn - 1][2])
            else:
                sick_neibohrs.append(atom_map[n][turn - 1][1])
                sick_neibohrs.append(atom_map[n][turn - 1][2])
                sick_neibohrs.append(atom_map[n][turn - 1][3])
    for i in sick_neibohrs:
        cand.append(i)

    return cand
Exemplo n.º 3
0
def find_neibohrs(coord_a, coord_b, rows, cols):
    neibohrs = ut.Stack()
    if (coord_a == 0):
        neibohrs.append((coord_a + 1, coord_b))
    elif (coord_a + 1 == rows):
        neibohrs.append((coord_a - 1, coord_b))
    else:
        neibohrs.append((coord_a + 1, coord_b))
        neibohrs.append((coord_a - 1, coord_b))
    if (coord_b == 0):
        neibohrs.append((coord_a, coord_b + 1))
    elif (coord_b + 1 == cols):
        neibohrs.append((coord_a, coord_b - 1))
    else:
        neibohrs.append((coord_a, coord_b + 1))
        neibohrs.append((coord_a, coord_b - 1))
    return neibohrs
 def __init__(self, positions):
     '''
     :param positions: a list of 6 integers that determine the starting position of each player
     '''
     self.thief = Player(positions[0], 1000, 1000, 1000, 3)
     self.detective1 = Player(positions[1], 12, 8, 4, 0)
     self.detective2 = Player(positions[2], 12, 8, 4, 0)
     self.detective3 = Player(positions[3], 12, 8, 4, 0)
     self.detective4 = Player(positions[4], 12, 8, 4, 0)
     self.detective5 = Player(positions[5], 12, 8, 4, 0)
     self.move_number = 1
     self.current_player = 0
     self.occupied_positions = positions
     self.last_thief_location = None
     self.outcome = 0
     self.last_moves = utils.Stack(
     )  # a list containing the last mode of transportation used by the players
     self.possible_thief_nodes = None
Exemplo n.º 5
0
    def postprocess(self, action_list):

        dropoff_stack = utils.Stack()
        result = []

        for action in action_list:

            if "drop off" in action:
                dropoff_stack.push(action)

            else:

                result.append(action)

                while not dropoff_stack.isEmpty():
                    result.append(dropoff_stack.pop())

        return result
Exemplo n.º 6
0
def create_knowledge_base(map, rows, cols, turns, atoms_map, p_crews, m_crews):
    k_base = ut.Stack()
    # Iterating over the map status per turn.
    for day in range(turns):
        for i in range(rows):
            for j in range(cols):
                # on the current turn - the state of the coord is S
                current_state = get_state(map, day, i, j)
                if current_state == 'S':
                    k_base.append(get_atoms_for_sick_state_on_other_turns(map, atoms_map, day, i, j))
                if current_state == 'H':
                    k_base.append([atoms_map[(i, j)][day][0]])
                if current_state == 'U':
                    for k in range(turns):
                        k_base.append([atoms_map[(i, j)][k][-1]])
                if current_state == 'Q':
                    k_base.append(get_atoms_for_Q_state_on_other_turns(map, atoms_map, day, i, j))
                if current_state == 'I':
                    for k in range(day, turns):
                        k_base.append([atoms_map[(i, j)][k][-2]])
                if current_state == '?':
                    daylist = []
                    for foo in range(len(atoms_map[(i, j)][day])):
                        daylist.append(atoms_map[(i, j)][day][foo])
                    k_base.append(daylist)
    mul_map(atoms_map, turns)
    for i in atoms_map:
        for j in range(turns):
            for x in itertools.combinations(atoms_map[i][j], 2):
                k_base.append(list(x))
    mul_map(atoms_map, turns)
    k_base = treat_sick_neibohrs(k_base, map, atoms_map, rows, cols, p_crews, turns)
    k_base = treat_healthy(k_base, map, atoms_map, rows, cols, m_crews, turns)
    k_base = treating_advanced_sickness(k_base, atoms_map, rows, cols, turns, p_crews)
    k_base = treating_advanced_q(k_base, atoms_map, rows, cols, turns, p_crews)
    k_base = police_actions(k_base, atoms_map, rows, cols, turns, p_crews)
    k_base = check_healthy_states_with_p(k_base, atoms_map, rows, cols, turns, p_crews)
    k_base = check_healthy_states_with_p_and_m(k_base, atoms_map, rows, cols, turns, p_crews, m_crews)
    k_base = check_healthy_state_with_m(k_base, atoms_map, rows, cols, turns, m_crews)
    k_base = check_p_capacity(k_base, atoms_map, rows, cols, turns, p_crews)
    k_base = check_m_capacity(k_base, atoms_map, rows, cols, turns, m_crews)
    return k_base
Exemplo n.º 7
0
def depth_first_graph_search(problem):
    "Search the deepest nodes in the search tree first."
    return graph_search(problem, utils.Stack())
Exemplo n.º 8
0
from telebot import util
import utils
import config
import Keyboards
import telebot
from telebot import types
import sqlite3
from Tables import Hero

bot = telebot.TeleBot(config.token)

stack = utils.Stack()
curpos = utils.massive[0]
@bot.message_handler(commands=['game'])
def game(message):
    conn = sqlite3.connect("1.db")
    cursor = conn.cursor()
    sql = "SELECT * FROM Players WHERE id=?"
    cursor.execute(sql, [(message.chat.id)])
    if len(cursor.fetchall()) == 0:
        cursor.execute("""INSERT INTO Players
                              VALUES ('%s','%s1','1','0','white','20','5','0','0','0','0','0')""" % (
            message.chat.id, "@"+message.chat.username))
        conn.commit()
        cursor.close()
        conn.close()
    bot.send_message(message.chat.id, message.chat.id, reply_markup=Keyboards.markup)

    @bot.message_handler(content_types=["text"])
    def handle_message(message):
        global curpos
Exemplo n.º 9
0
def get_list(arg1, arg2):
    n = ut.Stack()
    n.append([arg1])
    n.append([arg2])
    return n