Codie Codie - 10 months ago 58
Python Question

A game within a list of lists using Python

Picture of the two dimensional model

I am not sure where to go about with this program. I am to make a random function that calculates a number (1-4) then whatever number the output is, an "electron" will come out of the "S" in the picture and go in the direction according the the random number. If the "electron" reaches an "E", it escapes. If the "electron" reaches an R it is reflected back to the position right before hand. If the "electron" hits an A it is absorbed. I am to run 500 "electrons" through this program all starting at the S with 500 moves each and count how many "electrons" where absorbed, escaped and ones that neither escaped or were absorbed. The approach I made to this was to make a list of lists. with the first list being the 1st row in the picture, the 2nd being the 2nd row and so on.. Does anyone know of a better or nice approach for me to make with this program? If so I would greatly apreciate it..

Answer Source

It seems like a list of lists, with counters to keep track of position would be useful for what you are trying to do. For example:


would be your starting position. You would also likely have 5 unique values in your list for the 5 types of tiles you have in your game (A,S,E,R, blank).

For position as:


Going up and down would increase/decrease i, while moving left and right would do the equivalent to j.