Skip to content

Commit

Permalink
Fixed headless client game_over assertion and increased min treasure …
Browse files Browse the repository at this point in the history
…respawn time
  • Loading branch information
abbyssoul committed Dec 6, 2020
1 parent a901402 commit 07d00a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions coderone/dungeon/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class Game:
STATIC_BLOCK_COUNT = 18 # 15% of the board are Indestructible blocks
SOFT_BLOCK_COUNT = 30 # 20% of the board are low-value destructable blocks
ORE_BLOCK_COUNT = 5 # 5% of the board are Ore blocks
TREASURE_SPAWN_FREQUENCY = 6*30 # Once every 180 steps

PLAYER_START_AMMO = 2 # Amount of ammo a player starts the match with
FREE_AMMO_COUNT = 1 # Amount of free ammo, Should be Number of players - 1 - to create resource scarcity
Expand All @@ -83,7 +82,10 @@ class Game:

PLAYER_START_POWER = 2 # Initial blast radius
BOMB_TTL = 35 # Number of turns before bomb expires

AMMO_RESPAWN_TTL = 2*BOMB_TTL # Number of turns before ammo respawns
TREASURE_SPAWN_FREQUENCY_MIN = 5*10 # Once every 180 steps
TREASURE_SPAWN_FREQUENCY_MAX = 25*10 # Once every 180 steps


ACTION_CODES = {
Expand Down Expand Up @@ -431,7 +433,7 @@ def generate_map(self, seed=1):
self._reset_state()

# FIXME: We need to record enqueued delayed effects, otherwise replay won't match
self._enqueue_effect(DelayedEffectType.SPAWN_TREASURE, ttl=random.randint(0, self.TREASURE_SPAWN_FREQUENCY))
self._enqueue_effect(DelayedEffectType.SPAWN_TREASURE, ttl=random.randint(self.TREASURE_SPAWN_FREQUENCY_MIN, self.TREASURE_SPAWN_FREQUENCY_MAX))

all_cells = []
for x in range(0, self.column_count):
Expand Down Expand Up @@ -687,12 +689,12 @@ def __safe_remove(pos):
def _spawn_treasure(self):
good_locations = self._pick_good_spots()
if not good_locations:
self._enqueue_effect(DelayedEffectType.SPAWN_TREASURE, ttl=random.randint(0, self.TREASURE_SPAWN_FREQUENCY))
self._enqueue_effect(DelayedEffectType.SPAWN_TREASURE, ttl=random.randint(1, self.TREASURE_SPAWN_FREQUENCY_MIN))
return False

loc = random.choice(good_locations)
self.treasure_list.append(Game._Treasure(loc))
self._enqueue_effect(DelayedEffectType.SPAWN_TREASURE, ttl=random.randint(0, self.TREASURE_SPAWN_FREQUENCY))
self._enqueue_effect(DelayedEffectType.SPAWN_TREASURE, ttl=random.randint(self.TREASURE_SPAWN_FREQUENCY_MIN, self.TREASURE_SPAWN_FREQUENCY_MAX))

return True

Expand Down
2 changes: 1 addition & 1 deletion coderone/dungeon/hack_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main(self, stdscr, tick_step):

def _run(self, tick_step):
try:
while not self.game.game_ended:
while not self.game.is_over:
logger.info(f"Game step [{self.game.tick_counter}/{self.game.max_iterations}]... ")

cycle_start_time = time.time()
Expand Down
4 changes: 2 additions & 2 deletions coderone/dungeon/headless_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, game, config):
def _update(self, tick_step):
self.game.tick(tick_step)

stats = self.game.stats()
stats = self.game.stats
for p in stats['players'].values():
name = "{}{}".format(p['name'], '(bot)' if p['is_bot'] else "")
logger.info(f"{name} HP: {p['hp']} / Ammo: {p['ammo']} / Score: {p['score']}, loc: ({p['position'][0]}, {p['position'][0]})")
Expand All @@ -22,7 +22,7 @@ def _update(self, tick_step):

def run(self, tick_step):
try:
while not self.game.game_ended:
while not self.game.is_over:
logger.info(f"Game step [{self.game.tick_counter}/{self.game.max_iterations}]... ")

cycle_start_time = time.time()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='coderone-challenge-dungeons',
version='0.1.3.dev1',
version='0.1.3.dev2',
description='Dungeons and data structures: Coder one AI Game Tournament',
url='https://github.com/gocoderone/dungeons-and-data-structures',
author='Ivan Ryabov',
Expand Down

0 comments on commit 07d00a8

Please sign in to comment.