Coder Social home page Coder Social logo

Comments (6)

coolandsmartrr avatar coolandsmartrr commented on August 12, 2024 1

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.

joooyzee avatar joooyzee commented on August 12, 2024

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.

joooyzee avatar joooyzee commented on August 12, 2024

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.

coolandsmartrr avatar coolandsmartrr commented on August 12, 2024

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.

joooyzee avatar joooyzee commented on August 12, 2024

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.

coolandsmartrr avatar coolandsmartrr commented on August 12, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.