def get_new_instance(self, prefix, player):
        """ Create a new GameInstance and return its model.

    Args:
      prefix: A string used as the beginning of the instance id.
      player: The email address of the player.

    When this returns, neither this Game model or the new
    GameInstance have been put() in the database. If the GameInstance
    should persist, both models need to be put().

    Returns:
      A GameInstance object with a unique instance id beginning with
      prefix and player as the leader and sole member of the
      instance.
    """
        prefix = prefix.replace(' ', '')
        new_iid = prefix
        self.instance_count += 1
        new_index = self.instance_count
        while GameInstance.get_by_key_name(new_iid, parent=self) is not None:
            new_index += 1
            new_iid = prefix + str(new_index)
        instance = GameInstance(parent=self,
                                key_name=new_iid,
                                players=[player],
                                leader=player)
        return instance
  def get_new_instance(self, prefix, player):
    """ Create a new GameInstance and return its model.

    Args:
      prefix: A string used as the beginning of the instance id.
      player: The email address of the player.

    When this returns, neither this Game model or the new
    GameInstance have been put() in the database. If the GameInstance
    should persist, both models need to be put().

    Returns:
      A GameInstance object with a unique instance id beginning with
      prefix and player as the leader and sole member of the
      instance.
    """
    prefix = prefix.replace(' ', '')
    new_iid = prefix
    self.instance_count += 1
    new_index = self.instance_count
    while GameInstance.get_by_key_name(new_iid, parent=self) is not None:
      new_index += 1
      new_iid = prefix + str(new_index)
    instance = GameInstance(parent = self, key_name = new_iid,
                          players = [player], leader = player)
    return instance
    def get_joined_instance_keys_query(self, player):
        """ Return a query object for instances a player has already joined.

    Args:
      player: The email address of the player.

    Returns:
      A query object of all game instances that player has joined in
      order of creation time from oldest to newest.
    """
        query = GameInstance.all(keys_only=True)
        query.filter("players =", player)
        query.ancestor(self.key())
        query.order('-date')
        return query
  def get_joined_instance_keys_query(self, player):
    """ Return a query object for instances a player has already joined.

    Args:
      player: The email address of the player.

    Returns:
      A query object of all game instances that player has joined in
      order of creation time from oldest to newest.
    """
    query = GameInstance.all(keys_only = True)
    query.filter("players =", player)
    query.ancestor(self.key())
    query.order('-date')
    return query
    def get_invited_instance_keys_query(self, player):
        """ Return a query object for instances a player has been invited to.

    Args:
      player: The email address of the player.

    Returns:
      A query object of all game instances that player has been
      invited to and that are not full in order of creation time from
      oldest to newest. Any instance returned by this query should be
      able to be joined by the player at the time the results are
      fetched.
    """
        query = GameInstance.all(keys_only=True)
        query.filter("invited =", player)
        query.filter("full =", False)
        query.ancestor(self.key())
        query.order('-date')
        return query
    def get_public_instances_query(self, keys_only=False):
        """ Return a query object for public instances of this game.

    Args:
      keys_only (optional): Whether this database query should return
        only keys, or entire models.

    Returns:
      A query object of all public game instances that are not full
      in order of creation time from oldest to newest. Any instance
      returned by this query should be able to be joined by any
      player at the time the results are fetched.
    """
        query = GameInstance.all(keys_only=keys_only)
        query.filter("public =", True)
        query.filter("full =", False)
        query.ancestor(self.key())
        query.order('-date')
        return query
  def get_invited_instance_keys_query(self, player):
    """ Return a query object for instances a player has been invited to.

    Args:
      player: The email address of the player.

    Returns:
      A query object of all game instances that player has been
      invited to and that are not full in order of creation time from
      oldest to newest. Any instance returned by this query should be
      able to be joined by the player at the time the results are
      fetched.
    """
    query = GameInstance.all(keys_only = True)
    query.filter("invited =", player)
    query.filter("full =", False)
    query.ancestor(self.key())
    query.order('-date')
    return query
  def get_public_instances_query(self, keys_only = False):
    """ Return a query object for public instances of this game.

    Args:
      keys_only (optional): Whether this database query should return
        only keys, or entire models.

    Returns:
      A query object of all public game instances that are not full
      in order of creation time from oldest to newest. Any instance
      returned by this query should be able to be joined by any
      player at the time the results are fetched.
    """
    query = GameInstance.all(keys_only = keys_only)
    query.filter("public =", True)
    query.filter("full =", False)
    query.ancestor(self.key())
    query.order('-date')
    return query
Example #9
0

def get_sprite_by_square(square):
    sprite = None
    for s in pieces.sprites():
        if s.square == square:
            sprite = s
            break
    if sprite is None:
        raise Exception('could not find piece in (%d, %d)' % square)
    else:
        return sprite


# Инициализация объекта игровой партии
game_instance = GameInstance()

# Инициализация спрайтов
valid_moves = pg.sprite.Group()
pieces = pg.sprite.Group()
set_up_board(pieces, game_instance.get_current_setup())

# Шрифты
upper_size = 24  #18
main_size = 42  #36
bottom_size = 20  #20
score_size = 88
hint_size = 28

NEUTRAL_COLOR = (255, 255, 255)
DULL_COLOR = (215, 215, 215)
Example #10
0
        if len(img.shape) == 3 and img.shape[0]==3:
            img = img.transpose(1,2,0)
        
        img = skimage.transform.resize(img, RESOLUTION, mode="constant")
        img = img.astype(np.float32)
        return img

    def convert_action_agent2engine(agent_action):
        assert type(agent_action) == type(int()) or type(agent_action) == type(np.int64()), print("type(agent_action)=",type(agent_action))
        ans = []
        for i in range(6):
            ans.append(agent_action%2)
            agent_action = int(agent_action / 2)
        return ans
    
    game = GameInstance(game=DoomGame(), config_file_path=CONFIG_FILE_PATH,name='test', n_adv=5, rewards=REWARDS)
    IMG_BUFF = []
    DAMAGE_BUFF = []
    ATTACK_BUFF = []
    pre_health = 100.0
    for i in range(10):
        game.new_episode(0)
        while not game.is_episode_finished():
            s = preprocess(game.get_screen_buff())
            h = game.get_health()
            engine_action =convert_action_agent2engine( np.random.randint(32) * 2)
            game.make_action(engine_action, 4)
            IMG_BUFF.append(s)
            DAMAGE_BUFF.append(pre_health - game.get_health())
            pre_health = game.get_health()