# Re: [Tutor] matrixes

Magnus Lycka magnus at thinkware.se
Wed Apr 28 09:03:13 EDT 2004

```Conrad wrote:
> matrix = (('glade', 'stream', 'mountains'),('woods', 'creak', 'dunes'),
> ('forest', 'river', 'desert'))
>
> Is this the correct way and 'pythonic' way of doing it, or am I missing
> a module or something.

This would work, at least if the map is static. If you want to be able
to change the matrix in runtime, it might be better to use a dictionary
with coordinate tuples as keys.

> The starting location would be glade, and I would represent that in the
> location variable:
>
> location = [0, 0]
>
> and then north would be:
>
> north = [0, 1]
>
> and then if the input would be north. I would do something like this:
>
> location =  [location[0] + north[0], location[1] + location[1]]
>
> The problem is if you went south for your first 'move' how would i make
> it wrap and end up at forest?

Are you telling us that this matrix is really a small, warped globe? ;)
If you think it's too boring with if statements, you can have a look
at the modulo operator (%).

If there are things that you feel clutter the code in many places,
put that "clutter" in one place, and make it a fuction or a class etc.

> This seems like a real roundabout way of doing things, is there a
> better/faster way of doing this?

A programmer should be lazy, but that doesn't mean that he can avoid *all*
work! ;)

> As for my visual part, I was thinking of having a command line prompt to
> take input and a seperate window which shows a picture depending on
> which place you would be. This picture would have to dynamically change
> and pretty rapidly. I'll do a little research before asking about it.
>
> Thanks a lot!!
>
>
> P.S. The teachers want me to make this in Flash or html, or any tools
> found in our computer labs. But I think python would be appropriate for
> the job. *grin* I'm not sure I could use pygame because im either going
> to have to boot knoppix to demonstrate the game or find a small python
> distrobution that can go on the labs, without adminstrative priveleges
> since they only use windows. I relize this is homework but I do not
> think the questions detract from the assignment.

No, I think you will have some work with this, even if we give