Importing game_state

I put self.SCRAMBLER = SCRAMBLER
inside of the __init__ of game_state

it still says it isn’t defined

it is right under self.CORES = 1

That should be fine, I would check for typos and make sure you are passing the game_state object to the parameter. Also, you should no longer need to import game_state - this will cause a name conflict and could maybe be the problem if you’re still trying to import it.

Im not importing game_state, and there are no typos, just checked

I have a new question, I get an error

Traceback (most recent call last):
  File "/tmp/algo4619622758388830678/algo_strategy.py", line 422, in 
    algo.start()
  File "/tmp/algo4619622758388830678/gamelib/algocore.py", line 65, in start
    self.on_turn(game_state_string)
  File "/tmp/algo4619622758388830678/algo_strategy.py", line 119, in on_turn
    self.algo_strategy(game_state)
  File "/tmp/algo4619622758388830678/algo_strategy.py", line 139, in algo_strategy
    self.adaptive_replacing1(game_state) #if you can, replace broken firewalls with destructors
  File "/tmp/algo4619622758388830678/algo_strategy.py", line 313, in adaptive_replacing1
    if game_state.can_spawn(DESTRUCTOR, location) and (game_state.get_resource(game_state.CORES)) >= 5:
  File "/tmp/algo4619622758388830678/gamelib/game_state.py", line 283, in can_spawn
    if not self.game_map.in_arena_bounds(location):
  File "/tmp/algo4619622758388830678/gamelib/game_map.py", line 91, in in_arena_bounds
    x, y = location
ValueError: too many values to unpack (expected 2)

What am I doing wrong?
I have a list inside of init, with the value:

def __init__:
    self.mylist =  [[1, 2]]


for location in self.mylist:
    if game_state.can_spawn(PING, location) # this raises the error

You may have just copied it down incorrectly but I want to make sure, it should be:

def __init__(self):
   self.mylist = [[1,2]]

Every function that is part of a class must have a first parameter, almost always named self that passes a reference to the object.

thats what I wrote, plus for location in self.mylist I also did
so if I put that self.mylist inside if __init__ it can be used anywhere in the class?

another thing, my code says game_map is not defined
when doing game_map.TOP_LEFT inside of the get_path_to_edge function, which the document says to do

My sense is that you have created a module with a lot of different functions and parts. You will have to diagnose each separately since there is likely not one single solution for all of them. I feel you’re main problem is that you do not understand how classes work in python. I can continue to help debug your program, but this is not a sustainable solution for either of us. I recommend these tutorials for getting started:

https://www.w3schools.com/python/python_classes.asp
https://www.learnpython.org/en/Classes_and_Objects

I would especially look at (besides the basics) the implementation of inheritance in the third link.

Another recommendation I have would be to make a completely new file, with a single function, class, etc and just figure out how to get game_state to work in a single new file with nothing complicated. If you have a large file it will be extremely difficult to debug (for me as well, since I can’t see all of your code) since it is hard to isolate an issue. Then, once you have something you know works you can reference that when debugging your main code.

1 Like

so why is self.mylist
give the error expected 2 got 0

Think about the error, it expected 2 and got 0. Thus, it was expected to have 2 “things” inside of it but instead had 0. If it had 0 then it is either an empty list or not a list at all and is None. The first thing you should always do is print out what self.mylist is. Until you know what it is you can’t make any analysis of the problem since you don’t know what the problem is. You should print it out to know what it is, and then work you’re way backwards in the code to see where the value is set to be something you did not expect.

firewall_footprints = [[3, 10], []]
ah, i see

after fixing it to only append if there is a value, here is the error:

firewall_footprints = [[3, 10]]
Traceback (most recent call last):
  File "/tmp/algo6242076008130629784/algo_strategy.py", line 515, in 
    algo.start()
  File "/tmp/algo6242076008130629784/gamelib/algocore.py", line 65, in start
    self.on_turn(game_state_string)
  File "/tmp/algo6242076008130629784/algo_strategy.py", line 120, in on_turn
    self.algo_strategy(game_state)
  File "/tmp/algo6242076008130629784/algo_strategy.py", line 145, in algo_strategy
    self.adaptive_replacing1(game_state) #if you can, replace broken firewalls with destructors
  File "/tmp/algo6242076008130629784/algo_strategy.py", line 406, in adaptive_replacing1
    if game_state.can_spawn(DESTRUCTOR, location) and (game_state.get_resource(game_state.CORES)) >= 5:
  File "/tmp/algo6242076008130629784/gamelib/game_state.py", line 283, in can_spawn
    if not self.game_map.in_arena_bounds(location):
  File "/tmp/algo6242076008130629784/gamelib/game_map.py", line 91, in in_arena_bounds
    x, y = location
ValueError: too many values to unpack (expected 2)

firewall_footprints is the name of the list

Again, trying printing out location and then working backward printing out values to make sure they match what you would expect.