/
GraphTreeHeap
/
NeuroFighter
Обзор
Документация
Войти
/
GraphTreeHeap
/
NeuroFighter
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
legacy/universal_bot_prototype.py
87 строк
4 KB
FedMam
moving to the new project version
11 окт 2025, 04:16
11 окт 2025, 04:16
00409b0
Код
Авторство
О чём код?
# A Universal bot is a bot player with playstyle characteristics # randomly sampled. UNIVERSAL_BOT_CONFIG = { 'move_to': (0.0, 1.0), # probability to move towards the opponent anytime 'move_away': (0.0, 1.0), # probability to move away from the opponent anytime (overridden by the previous one) 'turn_on_shoot': (0.0, 1.0), # probability to turn towards the opponent on shooting 'jump': (0.0, 1.0), # probability to jump out of nowhere (^ jump_power) 'jump_power': (1.0, 4.0), 'jump_on_projectile': (0.0, 1.0), # probability to jump on seeing projectile 'jump_on_projectile_antipower': (1.0, 4.0), # 'antipower': 1 - (1 - x)^y 'jump_on_projectile_reaction_time': (FPS // 6, FPS * 2), # time to jump before the projectile reaches 'jump_height_mean': (0.0, 1.0), # * character jump height 'jump_height_std': (0.0, 0.5), # * character jump height 'shoot': (0.5, 1.0), # probability to hold the shoot button anytime (* (1 - cooldown/max_cooldown)) 'shoot_on_box_trigger': (0.0, 1.0), # * (1 - distance/max_distance) ^ shoot_distance_power 'shoot_distance_power': (0.5, 2.0), 'shoot_bounding_box': (CHR_HITBOX_HALFSIZE, CHR_HITBOX_SIZE * 3), } class UniversalBot(Bot): def __init__(self, seed: int | None=None): super().__init__(seed) c = {} for k in UNIVERSAL_BOT_CONFIG.keys(): l, r = UNIVERSAL_BOT_CONFIG[k] c[k] = self.rand.random() * (r - l) + l self.c = box.Box(c) self.next_jump_height = None def decide_inner(self, env, me, enemy, my_projs, enemy_projs): # move if self.rand.random() < self.c.move_to: me.buttons_held[0] = me.pos[0] > enemy.pos[0] me.buttons_held[1] = me.pos[0] < enemy.pos[0] elif self.rand.random() < self.c.move_away: me.buttons_held[0] = me.pos[0] < enemy.pos[0] me.buttons_held[1] = me.pos[0] > enemy.pos[0] if me.pos[0] == enemy.pos[0]: if self.rand.random() < 0.5: me.buttons_held[0] = True else: me.buttons_held[1] = True else: me.buttons_held[0] = False me.buttons_held[1] = False # jump if me.pos[1] == 0: me.buttons_held[2] = False self.next_jump_height = max(0.0, self.rand.gauss(self.c.jump_height_mean * me.jump_height, self.c.jump_height_std * me.jump_height)) # on ground if self.rand.random() < self.c.jump ** self.c.jump_power: me.buttons_held[2] = True proj_approaching = False for proj in enemy_projs: if proj.pos[1] <= me.pos[1] + CHR_HITBOX_HALFSIZE and \ ((proj.h_speed > 0 and proj.pos[0] >= me.pos[0] - abs(proj.h_speed) * self.c.jump_on_projectile_reaction_time and proj.pos[0] <= me.pos[0] + CHR_HITBOX_SIZE) or \ (proj.h_speed < 0 and proj.pos[0] <= me.pos[0] + abs(proj.h_speed) * self.c.jump_on_projectile_reaction_time and proj.pos[0] >= me.pos[0] - CHR_HITBOX_SIZE)): proj_approaching = True break if proj_approaching: self.next_jump_height = max(CHR_HITBOX_SIZE, me.v_speed * (CHR_HITBOX_SIZE / abs(proj.h_speed)), self.next_jump_height) if self.rand.random() < 1 - (1 - self.c.jump_on_projectile) ** self.c.jump_on_projectile_antipower: me.buttons_held[2] = True else: if me.jumping and me.pos[1] < self.next_jump_height: me.buttons_held[2] = True else: me.buttons_held[2] = False # shoot me.buttons_held[3] = False if me.shoot_cooldown_ctr == 0: if self.rand.random() < self.c.shoot * (1 - me.shoot_cooldown / CHARACTER_MAX_SHOOT_COOLDOWN * 0.8): me.buttons_held[3] = True if abs(enemy.pos[1] - me.pos[1]) < self.c.shoot_bounding_box: if self.rand.random() < self.c.shoot_on_box_trigger * (((1 - abs(me.pos[0] - enemy.pos[0]) / ROOM_WIDTH / 2) * me.shoot_speed / CHARACTER_MAX_SHOOT_SPEED) ** self.c.shoot_distance_power): me.buttons_held[3] = True # turn on shoot if me.buttons_held[3] and self.rand.random() < self.c.turn_on_shoot: me.buttons_held[0] = me.pos[0] > enemy.pos[0] me.buttons_held[1] = me.pos[0] > enemy.pos[0]