48
loading...
This website collects cookies to deliver better user experience
coderone-challenge-dungeon-0.1.6.tar.gz
from the Releases page.pip install coderone-challenge-dungeon-0.1.6.tar.gz
python -m coderone.dungeon.main --interactive coderone.dungeon.agent
ENTER
to un-pause the game. You'll be able to play as the knight, using the arrow keys ↑
/ ↓
/ ←
/ →
and SPACE
to place a bomb. You're playing against the default agent provided in the game (which does nothing but stand still). Close the window when you're done.my_agent.py
. In this file, paste the following:import random
class Agent:
def __init__(self):
'''
Place any initialization code for your agent here (if any)
'''
pass
def next_move(self, game_state, player_state):
'''
This method is called each time your Agent is required to choose an action
'''
###### CODE HERE ######
# a list of all the actions your Agent can choose from
actions = ['','u','d','l','r','p']
# randomly choosing an action
action = random.choice(actions)
###### END CODE ######
return action
my_agent.py
script is to:Agent
containing a method next_move
next_move
such that it can accept game information on each tick, stored in the variables game_state
and player_state
next_move
return an output action
which can take the form of a string representing one of the valid game moves:
''
: do nothingu
, d
, l
, r
: up, down, left, right (respectively)p
: place bombcoderone-dungeon --watch --interactive my_agent
my_agent.py
.--watch
loads the game in a format where you can make live changes to your code.--interactive
allows you to play the game as well. my_agent
is the name of your bot's Python script that you want to play against.my_agent
is Player 1 (Wizard) and you are Player 2 (Knight). You can also try:# play your agent against itself
coderone-dungeon --watch my_agent my_agent
game_state
and player_state
. These variables contain information about the game environment and your player respectively. They both contain some useful information (a full list is available in the Game Documentation), but the most important ones for now are:game_state
:size
: the size of the Game Map in the form (cols, rows) - i.e. (12,10) for a 12x10 mapbombs
: a list of all the current positions of bombs placedplayer_state
:location
: the current location co-ordinates of your player in the form (x,y)ammo
: the amount of ammo you havegame_state
and player_state
. Have a go at filling in the code yourself, and checking them against the provided answers.# get your Agent's current location
my_agents_location = pass ### CHANGE THIS
# get the number of columns and rows of the Game Map
cols = pass ### CHANGE THIS
rows = pass ### CHANGE THIS
# print the location of all the bombs placed on the Game Map
list_of_bombs = pass ### CHANGE THIS
for bomb in list_of_bombs:
print(f"Bomb at x: {None} y: {None}") ### Change 'None'
game_state
also contains some useful methods. The ones we'll use in this tutorial are:entity_at(location)
: returns the entity/object at the specified locationis_in_bounds(location)
: returns True or False depending on whether the specified location is actually within the Game Map (within the 12x10 grid)is_occupied(location)
: returns True or False depending on whether that block is occupied by another object or not# return the entity at co-ordinate (1,1)
entity_at_1_1 = pass ### CHANGE THIS
# is the co-ordinate (12,11) within the boundaries of the game?
is_in_bounds = pass ### CHANGE THIS
# is the co-ordinate (4,2) occupied?
is_occupied = pass ### CHANGE THIS