예제 #1
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))
예제 #2
0
파일: gamestate.py 프로젝트: EdTsft/ggp
    def apply_moves(self, moves):
        """A new game state representing the game after a move is applied.

        Returns a new state, this state is unchanged.

        Args:
            moves (dict) : Dict of `Role` => `Action`, one entry per role.

        Returns:
            GeneralGameState: The new game state.
        """
        with Frame() as f:
            game_id_term = self._game_id_term()

            moves_term = Term.from_list_terms([
                self._does_functor(Term.from_atom(role._atom),
                                   action._term_record.get())
                for (role, action) in moves.items()])

            # prepare_moves(game_id, moves_term, PreparedMoves)
            prepared_moves = f.term()
            try:
                self._prepare_moves_predicate(
                    game_id_term, moves_term, prepared_moves, check=True)
            except PrologCallFailed:
                raise ValueError(
                    'Invalid move set. Possibly not 1 move per role.')

            # NewMoveHistory = [PreparedMoves | old_move_history]
            new_move_history = Term.from_cons_list(prepared_moves,
                                                   self.move_history.get())

            # truth_history(game_id, NewMoveHistory, old_truth_history,
            #               NewTruthHistory)
            new_truth_history = f.term()
            try:
                self._truth_history_4_predicate(
                    game_id_term, new_move_history, self.truth_history.get(),
                    new_truth_history, check=True)
            except PrologCallFailed:
                raise ValueError('Invalid moves: {}'.format(
                    {str(role): str(action)
                     for role, action in moves.items()}))

            # final_truth_state(NewTruthHistory, NewTruthState)
            new_truth_state = f.term()
            self._final_truth_state_predicate(
                new_truth_history, new_truth_state, check=True)

            return GeneralGameState(
                game=self.game,
                move_history_term=new_move_history,
                truth_history_term=new_truth_history,
                truth_state_term=new_truth_state,
            )