Пример #1
0
 def __check_inrole(condition_tmp: Condition = None,
                    game_status_tmp: GameStatus = None):
     LoggingController.logger.debug(
         "Evaluating: " + str(inspect.currentframe().f_code.co_name))
     match = False
     # check number of parameters supplied
     if len(condition_tmp.list) == 1:
         parameter = condition_tmp.list[0]
         player = game_status_tmp.players.get_player_by_name(parameter)
         if player is not None:
             if player.name in game_status_tmp.get_speakers():
                 match = True
             else:
                 match = False
         else:
             match = True
             speakers = game_status_tmp.get_speakers()
             for speaker in speakers:
                 player = game_status_tmp.players.get_player_by_name(
                     speaker)
                 role = parameter
                 if role not in player.roles:
                     match = False
                     break
     return match
Пример #2
0
 def __evaluate_next_player_by_turns(self, game_status_tmp: GameStatus = None) -> bool:
     new_turn = False
     if controllers.GameController.GameController.game.turns.magnitude == Magnitude.SINGLE:
         new_turn = True
         if game_status_tmp.turns.ordering == Ordering.STRICT:
             game_status_tmp = game_status_tmp.assign_speaker_assign_listener()
         elif game_status_tmp.turns.ordering == Ordering.LIBERAL:
             # TODO implement Ordering.LIBERAL
             pass
     elif controllers.GameController.GameController.game.turns.magnitude == Magnitude.MULTIPLE:
         if game_status_tmp.max_moves_per_turn is not None:
             if self.multiple_moves_count >= game_status_tmp.max_moves_per_turn:
                 new_turn = True
                 if game_status_tmp.turns.ordering == Ordering.STRICT:
                     game_status_tmp = game_status_tmp.assign_speaker_assign_listener()
                 elif game_status_tmp.turns.ordering == Ordering.LIBERAL:
                     # TODO implement Ordering.LIBERAL
                     pass
                 self.__multiple_moves_count = 0
             else:
                 new_turn = False
                 self.__turn_count_increment()
         elif game_status_tmp.last_interaction_move is not None:
             if game_status_tmp.last_interaction_move.final:
                 new_turn = True
                 if game_status_tmp.turns.ordering == Ordering.STRICT:
                     game_status_tmp = game_status_tmp.assign_speaker_assign_listener()
                 elif game_status_tmp.turns.ordering == Ordering.LIBERAL:
                     # TODO implement Ordering.LIBERAL
                     pass
             else:
                 new_turn = False
     if game_status_tmp.all_players_did_move:
         self.__initial = False
     return new_turn
Пример #3
0
 def update_collector(self, game_status_tmp: GameStatus = None):
     game_status_tmp.new_turn = self.__evaluate_next_player_by_turns(game_status_tmp)
     game_status_tmp.speakers = game_status_tmp.get_speakers()
     if game_status_tmp.all_players_did_move:
         game_status_tmp.turns_counter += 1
     if game_status_tmp.turns.max is not None:
         if game_status_tmp.turns_counter >= game_status_tmp.turns.max:
             game_status_tmp.status = Status.TERMINATE
             GameEndController.finished = True
     return game_status_tmp
Пример #4
0
 def evaluate_conditions_controller(game_status_tmp: GameStatus = None):
     if len(game_status_tmp.mandatory_moves) > 0:
         # check conditions for that move
         for key in game_status_tmp.mandatory_moves:
             game_status_tmp.mandatory_moves[key] = ConditionsController. \
                 __get_interaction_moves_with_failed_conditions(game_status_tmp.mandatory_moves[key],
                                                                game_status_tmp)
     if len(game_status_tmp.available_moves) > 0:
         # check conditions for that move
         for key in game_status_tmp.available_moves:
             game_status_tmp.available_moves[key] = ConditionsController. \
                 __get_interaction_moves_with_failed_conditions(game_status_tmp.available_moves[key],
                                                                game_status_tmp)
     return game_status_tmp
Пример #5
0
 def update_collector(self, game_status_tmp: GameStatus = None):
     """
     This only updates current speaker and last interaction move,
     last_move should only be updated after validation in MoveValidationController
     :param game_status_tmp:
     :return: GameStatus
     """
     if self.__interaction_move is not None:
         game_status_tmp.current_speaker = self.__interaction_move.playerName
         game_status_tmp.last_interaction_move = self.__interaction_move
     else:
         LoggingController.logger.warning(
             "Most likely json invalid format or id returned none")
         raise Exception(Constants.WRONG_MESSAGE_FORMAT)
     return game_status_tmp
Пример #6
0
 def __init__(self,
              game_tmp: Game = None,
              game_status: GameStatus = None,
              dialogueId: str = None):
     super().__init__()
     if game_status is not None:
         self.game_status = game_status
     else:
         self.game_status = GameStatus(game_tmp, dialogueId=dialogueId)
     self.__turns_controller = TurnsController()
     self.__conditions_controller = ConditionsController()
     self.__effects_controller = EffectsController()
     self.__store_controller = StoreController()
     self.__rules_controller = RulesController()
     self.__output_controller = OutputController()
     self.__move_controller = MoveController()
     self.__move_validation_controller = MoveValidationController()
     self.__transcript_controller = TranscriptController()
     self.__handlers = [
         self.__turns_controller, self.__rules_controller,
         self.__conditions_controller, self.__move_controller,
         self.__move_validation_controller, self.__effects_controller,
         self.__store_controller, self.__transcript_controller,
         self.__output_controller
     ]
Пример #7
0
def start_dialogue(game_id: str, game_status: GameStatus = None):
    game_fac = GameFactory()
    game_from_db, error = get_game_from_db(game_id)
    if error is not None:
        return None, error
    input_stream = InputStream(game_from_db.dialogueDescription)
    game = game_fac.create_game(input_stream)
    if game_status is not None:
        game_status.set_game_template(game)
    game_controller = controllers.GameController.GameController(
        game_tmp=game, dialogueId=game_id, game_status=game_status)
    try:
        response, error = game_controller.play()
    except Exception as err:
        code = err.args[0] if len(err.args) > 1 else 500
        message = err.args[1] if len(err.args) > 1 else err.args[0]
        response = jsonify(code=code, message=message), code
        LoggingController.logger.debug("Error: ", err)
    return response, error
Пример #8
0
 def handle(self, game_status_tmp: GameStatus = None):
     valid = MoveValidationController.__validate(game_status_tmp)
     if not valid:
         details = {"player_expected": game_status_tmp.get_speakers(),
                    "player_got": game_status_tmp.last_interaction_move.playerName,
                    "moves_expected": {"mandatory": [x.moveName for x in game_status_tmp.mandatory_moves[NEXT]],
                                       "available": [x.moveName for x in game_status_tmp.available_moves[NEXT]]},
                    "move_got": game_status_tmp.last_interaction_move.moveName}
         return None, ExceptionHandler("INVALID_MOVE", 400, payload=details)
     game_status_tmp = self.update_collector(game_status_tmp)
     self.update_flag()
     LoggingController.logger.debug("Handling in: " + str(type(self)))
     return game_status_tmp, None
Пример #9
0
 def update_collector(self, game_status_tmp: GameStatus = None):
     dId = str(game_status_tmp.id)
     game_status_db = db_controller.session.query(GameStatus).filter_by(id=dId).first()
     serialized = GameStatusSerializer().serialize(game_status_tmp)
     game_status_tmp.gameStatusSerialized = json.dumps(serialized)
     if game_status_db is None:
         db_controller.session.add(game_status_tmp)
         db_controller.session.commit()
         return game_status_tmp
     # else update db model
     game_status_db.gameStatusSerialized = game_status_tmp.gameStatusSerialized
     db_controller.session.add(game_status_db)
     db_controller.session.commit()
     return game_status_tmp
Пример #10
0
 def __assign_speaker_assign_listener(self, game_status_tmp: GameStatus = None):
     if game_status_tmp.last_interaction_move is None:
         return game_status_tmp
     next_player = game_status_tmp.get_next_player_name_from_the_list(game_status_tmp.last_interaction_move.playerName)
     if next_player is None:
         return game_status_tmp
     for player in game_status_tmp.players.list:
         if next_player == player.name:
             if SPEAKER not in player.roles:
                 if LISTENER in player.roles:
                     player.roles.remove(LISTENER)
                 player.roles.append(SPEAKER)
         else:
             if LISTENER not in player.roles:
                 if SPEAKER in player.roles:
                     player.roles.remove(SPEAKER)
                 player.roles.append(LISTENER)
     return game_status_tmp
Пример #11
0
 def update_collector(self, game_status_tmp: GameStatus = None):
     game_status_tmp.speakers = game_status_tmp.get_speakers()
     return game_status_tmp
Пример #12
0
 def __terminate(game_status_tmp: GameStatus = None, system_id: str = EMPTY):
     if game_status_tmp.name == system_id:
         game_status_tmp.status = Status.TERMINATE
     return game_status_tmp
Пример #13
0
 def __initiate(game_status_tmp: GameStatus = None, system_id: str = EMPTY):
     if game_status_tmp.name == system_id:
         game_status_tmp.status = Status.INITIATE
     return game_status_tmp
Пример #14
0
 def __incomplete(game_status_tmp: GameStatus = None, system_id: str = EMPTY):
     if game_status_tmp.name == system_id:
         game_status_tmp.status = Status.INCOMPLETE
     return game_status_tmp
Пример #15
0
 def __inactive(game_status_tmp: GameStatus = None, system_id: str = EMPTY):
     if game_status_tmp.name == system_id:
         game_status_tmp.status = Status.INACTIVE
     return game_status_tmp
Пример #16
0
 def update_collector(self, game_status_tmp: GameStatus = None):
     if game_status_tmp.last_interaction_move:
         game_status_tmp = game_status_tmp.assign_speaker_assign_listener()
         game_status_tmp.speakers = game_status_tmp.get_speakers()
         game_status_tmp.current_speaker = game_status_tmp.last_interaction_move.playerName
         game_status_tmp.set_last_move_by_name(game_status_tmp.last_interaction_move.moveName)
         game_status_tmp.past_moves.append(game_status_tmp.last_interaction_move)
         game_status_tmp.set_did_move_flag(game_status_tmp.current_speaker)
         game_status_tmp.remove_interaction_move_from_moves(game_status_tmp.last_interaction_move)
         game_status_tmp.initial_turn = False
         game_status_tmp.clear_init_moves_dicts()
     else:
         LoggingController.logger.warning(
             "game_status_tmp.last_interaction_move: None\n\tLast move could not be parsed")
         GameEndController.finished = True
     return game_status_tmp