![]() Define instance variables "rows", "cols", and "grid". ![]() Now that we know this, write the code for Life's constructor. Thus, instead of needing to define our instance variables outside of the constructor and setting their values inside of it, we can simply write "self.variable = value" in our constructor and have "self.variable" serve as an instance variable which can be used by any other methods in the class. One of the first things you should understand about Python is that, unlike Java, it allows you to both define and set the value of instance variables in the same line. In Python, classes have the following format: class : What you're looking at is a class called "Life". Open the file "life.py" in the "part1" subfolder of the "gameoflife" folder you downloaded. And to just get super meta for a second, a consequence of this is that Game of Life can simulate ITSELF! (#Conwayception) In fact, these rules are so powerful that they actually allow Conway's Game of Life to be Turing Complete, which roughly means that we could perform any computation within the game that a standard computer could (though they would be painfully slow). These extremely simple rules give rise to some incredibly complex and beautiful patterns, as illustrated here:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |