def MakeInitRule(game_name, role, init_conds, fact_rules, min_success_score): sp = MakeTemplateProduction("init-%s" % game_name, "propose", "") sp.add_attrib(sp.get_state_id(), "superstate", "nil") sp.add_neg_attrib(sp.get_state_id(), "name", "") op_id = sp.add_operator_prop("init-%s" % game_name, "+ >") asp = MakeApplyRule(sp) asp.add_create_constant(asp.get_state_id(), 'name', game_name) asp.add_create_constant(asp.get_state_id(), 'next-action', '0') asp.add_create_id(asp.get_state_id(), 'desired') gs_id = asp.add_create_id(asp.get_state_id(), 'gs') fact_id = asp.add_create_id(asp.get_state_id(), 'facts') # game_elabs_var = state_action.add_id_wme_action("elaborations") asp.add_create_constant(gs_id, 'action-counter', '0') if role == "": print "Warning: No role defined" else: asp.add_create_constant(gs_id, 'role', role) var_map = GDLSoarVarMapper(UniqueNameGenerator()) for ic in init_conds: ic.head().make_soar_actions(asp, var_map) for f in fact_rules: f.head().make_soar_actions(asp, var_map) return [sp, asp]
def __init__(self, name, state_name): # if name == 'apply*remove-_next__holding__std_soar_var0__': # pdb.set_trace() self.__name = name self.__state_name = state_name self.__name_gen = UniqueNameGenerator() self.__state_id = self.__name_gen.get_name("s") self.__top_conj = Conjunction.MakeTopConjunction( self.__state_id, self.__name_gen) if state_name != '': self.__top_conj.add_attrib(self.__state_id, "name", state_name) self.__curr_conj = self.__top_conj self.__create_id_actions = {} # id -> [(attrib, id, prefs)] self.__actions = {} # id -> [(attrib, rhs, action)] self.__new_ids = [] # ids created by actions self.__rhs_funcs = []
from UniqueNameGen import UniqueNameGenerator from SoarProd import * from ElementGGP import ElementGGP as ElemGGP from GGPRule import GGPRule from GGPSentence import GGPSentence import re import ElementGGP import pdb from Comparison import Comparison name_gen = UniqueNameGenerator() rule_index = 0 def SentenceIsComp(sentence): Comparison_Ops = ['distinct', '<', '>', '>='] return sentence.name() in Comparison_Ops def same_signature(sent1, sent2): if sent1.name() != sent2.name(): return False if sent1.num_terms() != sent2.num_terms(): return False for i in range(sent1.num_terms()): if (sent1.term(i).type() == 'function') ^ (sent2.term(i).type() == 'function'): return False