Comments (6)
Here how myagent.py
looks like:
import random
class Agent:
def __init__(self) -> None:
pass
def next_move(self, game_state, player_state):
'''
Call this method when agent makes a move
'''
# Variables
self.cols = game_state.size[0]
self.rows = game_state.size[1]
self.game_state = game_state
self.location = player_state.location
# Agent
surrounding_tiles = self.get_surrounding_tiles(self.location)
empty_tiles = self.get_empty_tiles(surrounding_tiles)
if empty_tiles:
random_tile = random.choice(empty_tiles)
action = self.move_to_tile(self.location, random_tile)
else:
action = ''
# actions = ['', 'u', 'd', 'l', 'r', 'p']
return action
####################
# Helper functions #
####################
def get_surrounding_tiles(self, location):
tile_north = (location[0], location[1]+1)
tile_south = (location[0], location[1]-1)
tile_west = (location[0]-1, location[1])
tile_east = (location[0]+1, location[1])
surrounding_tiles = (tile_north, tile_south, tile_west, tile_east)
for tile in surrounding_tiles:
if not self.game_state.is_in_bounds:
surrounding_tiles.remove(tile)
return surrounding_tiles
def get_empty_tiles(self, tiles):
empty_tiles = []
for tile in tiles:
if not self.game_state.is_occupied:
empty_tiles.append(tile)
return empty_tiles
def move_to_tile(self, location, tile):
# See where the tile is relative to our current location
diff = tuple(x-y for x, y in zip(tile, self.location))
if diff == (0,1):
action = 'u'
elif diff == (0,-1):
action = 'd'
elif diff == (1,0):
action = 'r'
elif diff == (-1,0):
action = 'l'
else:
action = ''
return action
from dungeons-and-data-structures.
Hey there, I'm not immediately sure what the problem could be - can you please share what your myagent.py
looks like?
from dungeons-and-data-structures.
It looks like there is a missing tile
input in this method:
def get_empty_tiles(self, tiles):
empty_tiles = []
for tile in tiles:
# missing tile here
if not self.game_state.is_occupied:
empty_tiles.append(tile)
return empty_tiles
Should read:
def get_empty_tiles(self, tiles):
empty_tiles = []
for tile in tiles:
if not self.game_state.is_occupied(tile):
empty_tiles.append(tile)
return empty_tiles
So the agent isn't returning any empty tiles (and therefore isn't moving).
For reference, you can find the full working agent script here: https://github.com/CoderOneHQ/agent-template/blob/main/wanderer.py
Let me know if that solves your issue.
from dungeons-and-data-structures.
Oh, how silly of me! Thank you for your help.
Do you know a a way to lint this error in VSCode so that I can catch these typos in the future? Right now, VSCode doesn't seem to be aware of items within game_state
, as it doesn't offer autocomplete.
from dungeons-and-data-structures.
No worries!
Not that I know of, but you can find a list of available methods & the inputs they take here:
https://www.notion.so/coderone/Game-Documentation-9b130e1195fc404cbf1d6ad38dbb4832#aa2a4c509571421bb3d3f083dfa9b33c
from dungeons-and-data-structures.
I see. I'm aware of the API docs, but I'll go over them again. Once again, thanks!
from dungeons-and-data-structures.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dungeons-and-data-structures.