Esempio n. 1
0
 def test_rule_variadic_translation(self):
     rule = Functor(':-', 2)
     and_ = Functor(',', 2)
     assert_equal(
         prefix_gdl_statement_to_prolog('(<= foo 1 2 3 4)'),
         rule(Term.from_atom_name('foo'),
              and_(Term.from_atom_name('1'),
                   and_(Term.from_atom_name('2'),
                        and_(Term.from_atom_name('3'),
                             Term.from_atom_name('4'))))))
Esempio n. 2
0
    def check_parse_atoms(*atoms):
        terms = []
        for atom in atoms:
            term = Term.from_atom_name(atom)
            terms.append(term)
            TestPrefixGdlStatementToPrologAtom.check_parse_statement(
                term, atom)

        TestPrefixGdlStatementToPrologAtom.check_parse_statements(
            Term.from_list_terms(terms), '\n'.join(atoms))
Esempio n. 3
0
    def create_game(self, game_id, game_description):
        """Create a game with the given game_id using the game description.

        Args:
            game_id (str)          : Game is created with this ID.
            game_description (str) : Game description given in Game Description
                Language (GDL).
        """
        with Frame():
            self._create_game_predicate(
                Term.from_atom_name(game_id),
                prefix_gdl_statements_to_prolog(game_description),
                check=True)
Esempio n. 4
0
 def _game_id_term(self):
     return Term.from_atom_name(self.game_id())
Esempio n. 5
0
 def _stateful_query(self, state, *queries):
     return Query.call_term(self.game_manager._game_state_term(
         Term.from_atom_name(self.game_id), state, *queries))
Esempio n. 6
0
    prolog_term_to_prefix_gdl,
)

__all__ = [
    'GeneralGameManager',
    'GeneralGame',
    'GeneralGameState',
    'Role',
    'Action',
    'GameProposition',
]

logger = logging.getLogger(__name__)

# Read in game state rules
Functor('consult', 1)(Term.from_atom_name(
    os.path.join(prolog_dir, 'ggp_state.pl')))()


class GeneralGameManager(object):
    """Manage game descriptions using SWI-Prolog"""
    _ggp_state = Module(Atom('ggp_state'))
    _game_id_predicate = Predicate(functor=Functor(Atom('game_id'), 1),
                                   module=_ggp_state)
    _create_game_predicate = Predicate(functor=Functor(Atom('create_game'), 2),
                                       module=_ggp_state)
    _game_state_functor = Functor(Atom('game_state'), 3)
    _game_state_predicate = Predicate(functor=_game_state_functor,
                                      module=_ggp_state)
    _and_predicate = Predicate.from_name_arity(',', 2)

    def __init__(self):
Esempio n. 7
0
 def test_compound_term(self):
     assert_equal(prolog_term_to_prefix_gdl(
         Functor('foo', 2)(Term.from_atom_name('bar'),
                           Term.from_atom_name('2'))),
         '(foo bar 2)')
Esempio n. 8
0
 def test_atom_term(self):
     assert_equal(prolog_term_to_prefix_gdl(Term.from_atom_name('foo')),
                  'foo')
Esempio n. 9
0
 def test_rule_symbol_translation(self):
     assert_equal(prefix_gdl_statement_to_prolog('(<= foo bar)'),
                  Functor(':-', 2)(Term.from_atom_name('foo'),
                                   Term.from_atom_name('bar')))
Esempio n. 10
0
 def test_compound_term_nexted(self):
     assert_equal(
         prefix_gdl_statement_to_prolog('(foo (bar 1 2) (baz 3))'),
         Functor('foo', 2)(Functor('bar', 2)(Term.from_atom_name('1'),
                                             Term.from_atom_name('2')),
                           Functor('baz', 1)(Term.from_atom_name('3'))))
Esempio n. 11
0
 def test_compound_term_mixed_atomic(self):
     term = prefix_gdl_statement_to_prolog('(foo arg1 ?arg2 arg3)')
     assert_equal(term.get_functor(), Functor('foo', 3))
     assert_equal(term.get_arg(0), Term.from_atom_name('arg1'))
     assert_true(term.get_arg(1).is_variable())
     assert_equal(term.get_arg(2), Term.from_atom_name('arg3'))
Esempio n. 12
0
 def test_compound_term_one_atom(self):
     assert_equal(prefix_gdl_statement_to_prolog('(foo arg)'),
                  Functor('foo', 1)(Term.from_atom_name('arg')))