[Tutor] TypeError: unhashable type: 'pygame.math.Vector2'
dn
PyTutor at DancesWithMice.info
Sun Jun 28 02:21:08 EDT 2020
On 27/06/20 1:44 PM, Cravan wrote:
> > On 27/6/20, 8:13 AM, "Tutor on behalf of dn via Tutor" <tutor-bounces+savageapple850=gmail.com at python.org on behalf of tutor at python.org> wrote:
>
>
> > It may be worth taking a step-back - both in terms of the design you are
> implementing and the questions you are asking of us:-
> Sure! I apologise for any inconvenience caused, and really appreciate your efforts to help me
It's not inconvenience, per-se, more a thought that sometimes 'the
problem' may not be a 'programming error', but instead be a short-coming
in design...
(I don't know! However, you will see more of that level of question, below)
> > Have looked and looked, and then used 'find', but failed to find the
> code-line at-error. Why? [help us to help you!]
> Essentially right now my dictionary is only churning out values of a current index when printing it out, so e.g.
> {((1023, 767), 'U'): 0, ((1023, 767), 'D'): 0, ((1023, 767), 'L'): 0, ((1023, 767), 'R'): 0} when it's supposed to be inclusive of all the coords. in the game (and the possible actions). I can't seem to rectify it(I don't know how).
So, you didn't include this information!? The more generous you can be
with us, the more readily folk will dive-in to help you. You will see
(below) that one problem may be purely Python, thus even those who do
not use Pygame could have been helping, given the info...
Please see previous msg - covering the generation of different views of
the same data/data-components.
Why look at all possible coordinates, cf only those occupied by players,
zombies, and obstructions? (see later)
Regardless, to be able to see what's (not) happening, insert a
debug-print after self.stateSpace = [(a,b)] (and the nested for-loops),
run, and observe...
What is the content of self.stateSpace, its type(), and its len()?
If that is not sufficient to provoke an 'ahah!', then put another
debug-print 'inside' the loops...
My guess is that you have confused the syntax for a list comprehension
with that appropriate to explicit, nested, for-loops. To add elements to
the end of a list, use list.append( value ) - see Python Docs for more info.
Another [design] question, if I may: might it be better to use a
dict[ionary] so that (later) you could have either "serial" or
"direct-access" to 'squares' (coordinates) in the game's grid?
> > Aside from learning Python's idioms, are you using a competent IDE?
> Could you then use full-names instead of abbreviations, without adding
> major effort? I think we could guess what a "zomb" is, but would it be
> better (and kinder) to remove all doubt?
> I'm using Atom to do it.
IIRC once a variable-name has been entered, next time the entry being
typed appears to be similar, Atom will offer to 'fill' for you - saving
typing *and* improving readability...
An enemy in this case would be a zombie.(zomb) who is seeking to kill
the player. The player has a health bar which decreases when the zombie
touches it, and my game is a maze game. The zombies can pass through
walls to give them an advantage over the player (making it more difficult)
So, (one) "collision" is defined as a zombie either landing on the same
'square' as the player, or on a neighboring square. Which, and
(expressed in English) how do you see this as a calculation (and
data-structure)?
> > Have comments and "docstrings" (a pythonic idiom) been used to describe
> what the code/each function is supposed to do, and why?
> Well, some (haha).
Recognising that there is a difference between someone working
by-and-for himself, and someone who is part of a team; by involving us
have you effectively moved from one to the other? ie would improving
this situation help us to understand your thinking and thus move more
rapidly towards an 'answer'?
> > If the game's environment is described as a "grid", why is its width and
> height described using anything other than int[eger]s?
> Width and Height are the actual width and height. Essentially gridwidth and gridheight are the width and height (in tilesize units) e.g. 3 tiles x 4 tiles for example
Which strike me as integers!
(yet the code calls int() to convert them, but from what?)
Also, how many times does the code perform these conversions, cf the
number of times that it is strictly-necessary?
> > What is the purpose of "state"? Is there a difference between "state"
> and "position" (or next-/previous-position)?
> A state is essentially the current state of the system (i.e. I can set the state as the product of my coordinates, for example but now I'm using it as the coords. for convenience), within a set of states (product of the maximum y-coord and the max. x-coord but it also can be all the coords in my environment(which I am using))
With apologies, but I failed to understand.
Is "state" related to whether the game is 'on' or over? Is it the
ability of the player (or each zombie) to move into a neighboring
square/tile? Something else? How would you express its purpose and
functions, in English?
The "all the coords" part is (hopefully) addressed with the debug-print
investigation proposed, above.
> > Have you understood the (animation) concept of collision? (assuming that
> is part of the intent here) Have you noted various algorithms and
> approximations which are commonly-used?
> Yes, the collision part is fine since I was able to get it to work before the implementation of machine learning
--
Regards =dn
More information about the Tutor
mailing list