コード例 #1
0
 def __init__(self,
              origin_y=100,
              height=BUTTON_HEIGHT,
              width=BUTTON_WIDTH,
              spacing=MENU_BUTTON_SPACING):
     self.objects = []
     self.buttons_height = height
     self.width = width
     self.buttons_spacing = spacing
     self.y = origin_y
     self.gif = GIFImage('anim.gif')
     self.inputbox_id = 0
     cursor_path = os.path.join('cursors', 'cursor_pacman_text.xbm')
     self.text_cursor = pygame.cursors.load_xbm(cursor_path, cursor_path)
     self.prepare_scene()
     self.facts = Facts()
コード例 #2
0
 def declare(kb, input):
     while input:
         sent_str, input = Sentence.next(input)
         sent_type = Sentence.classify(sent_str)
         if sent_type == 'fact':
             fact = Facts.parse_fact(sent_str)
             kb.add_fact(fact)
         elif sent_type == 'rule':
             rule = Rules.parse_rule(sent_str)
             kb.add_rule(rule)
コード例 #3
0
    def parse_rule(str_rule):
        str_rule=str_rule.replace(" ","")   #Delete space
        str_rule=str_rule.strip(".")        #Delete dots at the end

        arr1=str_rule.split(":-")

        conclusion = Facts.parse_fact(arr1[0])

        s=arr1[1]
        premises=[]

        while(s.find(")")!=len(s)-1):
            idx=s.find(")")
            temp=s[:idx+1]
            s=s[idx+2:]
            temp_fact=Facts.parse_fact(temp)
            premises.append(temp_fact)
        
        temp_fact=Facts.parse_fact(s)
        premises.append(temp_fact)

        return Rules(conclusion, premises)
コード例 #4
0
ファイル: suprc.py プロジェクト: lil-cain/super-reboot-checks
def main():
    init_logging(10)

    # Load all of our datasources. This will also validate that all required
    # properties are present.
    datasources = modules.load_modules('datasources')

    # Order the datasources to make sure their dependencies are satisfied.
    datasource_load_ordered = order_dependencies(datasources)

    # Build our facts object using all of our loaded datasources
    facts = Facts(datasource_load_ordered)

    # Run modules which will consume the data from our datasources
    modules.run_modules(modules.load_modules('plugins'), facts)
コード例 #5
0
 def is_rule(self, line):
     hash_index = line.find("=>")
     if hash_index == (-1):
         return False
     line = self.remove_comment(line)
     split_sides = line.split("=>")
     antecedent = split_sides[0]
     consequent = split_sides[1]
     if (not antecedent) or (not consequent):
         return False
     resolver = resolve_proposition.ResolveProposition()
     facts = Facts()
     try:
         resolver.resolve(antecedent, facts)
         resolver.resolve(consequent, facts)
     except:
         return False
     return True
コード例 #6
0
    def __init__(self, conclusion = Facts(), premises = []):
        self.conclusion = conclusion
        self.premises = premises

        self.duplicate = self.detect_duplicate()
        self.ops = self.get_ops()       #Get a set of facts
コード例 #7
0
from facts import Facts

facts = Facts()
print("A = {}".format(facts.atoms["A"]))
print("Z = {}".format(facts.atoms["Z"]))
print("V = {}".format(facts.atoms["V"]))
print("Q = {}".format(facts.atoms["Q"]))
print("X = {}".format(facts.atoms["X"]))
コード例 #8
0
class Menu(Scene):
    def __init__(self,
                 origin_y=100,
                 height=BUTTON_HEIGHT,
                 width=BUTTON_WIDTH,
                 spacing=MENU_BUTTON_SPACING):
        self.objects = []
        self.buttons_height = height
        self.width = width
        self.buttons_spacing = spacing
        self.y = origin_y
        self.gif = GIFImage('anim.gif')
        self.inputbox_id = 0
        cursor_path = os.path.join('cursors', 'cursor_pacman_text.xbm')
        self.text_cursor = pygame.cursors.load_xbm(cursor_path, cursor_path)
        self.prepare_scene()
        self.facts = Facts()

    def prepare_scene(self):
        button_labels = [
            'Single', 'Double', 'Levels', 'Table records', 'How to play',
            'Exit'
        ]
        button_functions = [
            self.proceed_game_single, self.proceed_game_double,
            self.proceed_levels, self.proceed_table_records,
            self.proceed_control, self.proceed_close_app
        ]

        for i in range(len(button_labels)):
            self.objects.append(
                Button((WIDTH / 2 - self.width / 2, self.y + i *
                        (self.buttons_height + self.buttons_spacing),
                        BUTTON_WIDTH, self.buttons_height),
                       LIGHT_ORANGE,
                       button_functions[i],
                       text=button_labels[i],
                       font=pygame.font.SysFont('Comic Sans MS', 42),
                       **BUTTON_STYLE))
        f = open('players.txt', 'r')
        players = f.read().split(sep=',')
        f.close()

        self.inputbox_id = len(self.objects)
        self.objects.append(InputBox(0, 0, 200, 40, 0, players[0]))
        self.objects.append(InputBox(WIDTH - 200, 0, 200, 40, 1, players[1]))

    def process_events(self, event):
        if self.objects[self.inputbox_id].active or self.objects[
                self.inputbox_id + 1].active:
            pygame.mouse.set_cursor(*self.text_cursor)
        else:
            pygame.mouse.set_cursor(*pygame.cursors.arrow)
        for object in self.objects:
            object.check_event(event)

    def proceed_game_single(self):
        self.next_scene = proceed_game_single + '1'

    def proceed_game_double(self):
        self.next_scene = proceed_game_double + '1'

    def proceed_levels(self):
        self.next_scene = proceed_levels

    def proceed_table_records(self):
        self.next_scene = proceed_table_records

    def proceed_control(self):
        self.next_scene = proceed_control

    def proceed_close_app(self):
        self.next_scene = proceed_close_app

    def draw(self, screen):
        self.gif.render(screen, (0, 0))
        for object in self.objects:
            object.draw(screen)
        self.facts.draw(screen)