AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Conway game of life java code10/16/2023 ![]() All other states (less than 3 live neighbors or more than 3 live neighbors) and the dead cell stays dead. The way the Game of Life is set up, a cell has 8 neighbors, so we should really test for 5, 6, 7, & 8 live neighbors, too.Īnd for Test #4 (dead cell with 3 neighbors comes to life), we should really test the negative conditions as well. We're testing for 4 neighbors, but what about the others. ![]() The same is true for Test #3 (live cell with more than 3 neighbors dies). In addition for Test #2 (live cell with 2 or 3 neighbors lives), we're only testing for 3 neighbors. We really should add another test for 0 neighbors to make sure we're covering the possibilities. For Test #1 (live cell with less than 2 neighbors dies), we're only testing for 1 neighbor. We've implemented all 4 of the rules, but we're not really testing all of the possible states at this point. I know that technically I'm supposed to write a failing test before writing *any* code, but I like to break rules from time to time. To get started, I created a class library to hold our method and an MSTest project to hold our unit tests. As a note, the rules have the British spelling "neighbours", but I'll be using the American spelling "neighbors" throughout the article. We can create a method that takes in the current cell state (live/dead) and the number of live neighbors and then spits out a new state (live/dead).
0 Comments
Read More
Leave a Reply. |