Public readonly int ArrayLimitI, ArrayLimitJ Private (int i, int j) _currentIndex, _centreCell, _centreMin, _centreMax Private byte _currentState, _stateSnapshot ArrayToCentreCoordinates methods are used to convert between these two coordinate systems. using 0 based array coordinates (variables prefixed with array). array centred origin coordinates (variables prefixed with centre) while the game state is handled internally Callers interact with CurrentIndex, CellState and NextCellStateUpdate using _stateSnapshot is used by UpdateState to store a version of the game state that stays constant during a The game state is held as an byte in _currentState, where 1 represents a live cell and 0 a dead cell. This class encapsulates the game state and the methods used to update it. Public GameStateUpdateOutOfBoundsException(string message, Exception inner) Public GameStateUpdateOutOfBoundsException(string message) Public GameStateUpdateOutOfBoundsException() Public class GameStateUpdateOutOfBoundsException : Exception ConwayStateVector.CellState or ConwayStateVector.NextCellStateUpdate. the boundary of game space during a state update, or that a caller has passed invalid coordinates to This exception type is used within the ConwayStateVector class to indicate either that live cells have reached This code is intended to be a component in an Android app implementation of Conway's Game of Life, My overall goal is to build an Android app implementation of the game (using Xamarin) where this class is a component. I'm also learning about implementing light automated unit tests for this project from the beginning. How can I improve the code? Was making an extra 2 rows and columns in the grid array a good idea?Īctive oldest votes Your Answer StackExchange.ifUsing("editor", function () return ing("mathja圎diting", function () (function (editor, postfix) StackExchange.mathja圎diting.prepareWmdForMathJax(editor, postfix, ]) ) ), "mathjax-editing") StackExchange.ifUsing("editor", function () ing("externalEditor", function () ing("snippets", function () () ) ), "code-snippets") StackExchange.ready(function() var channelOptions = tags: "".split(" "), id: "196" initTagRenderer("".split(" "), "".split(" "), channelOptions) ing("externalEditor", function() // Have to fire editor after snippets, if snippets enabled if () ing("snippets", function() createEditor() ) else createEditor() ) function createEditor() StackExchange.prepareEditor( heartbeatType: 'answer', convertImagesToLinks: false, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: null, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".I'm learning C# and have written the below class to encapsulate the game state of Conway's Game of Life and its update methods. */ #include #include #include #include #include #include #define EXTRA_SPACE 1 #define GRID_SIZE 35 #define ALIVE_CELL '#' #define DEAD_CELL ' ' struct CellCoords int y, x void setup_grid() void generation() void display_grid() void sleep(int) std::array, GRID_SIZE + EXTRA_SPACE * 2> grid int main() setup_grid() int gen = 1 do system("cls") std::cout cells_to_kill std::vector cells_to_be_born int neighbors for (int y = EXTRA_SPACE y < GRID_SIZE y++) for (int x = EXTRA_SPACE x < GRID_SIZE x++) neighbors = 0 if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) neighbors++ if (grid = ALIVE_CELL) else if (neighbors = 3) cells_to_be_born.push_back( y, x ) for (int i = 0 i < cells_to_kill.size() i++) CellCoords cell = cells_to_kill grid = DEAD_CELL for (int i = 0 i < cells_to_be_born.size() i++) CellCoords cell = cells_to_be_born grid = ALIVE_CELL void display_grid() std::cout << std::endl for (int y = EXTRA_SPACE y < GRID_SIZE y++) for (int x = EXTRA_SPACE x < GRID_SIZE x++) std::cout << grid << ' ' std::cout << std::endl std::cout << std::endl void sleep(int time) for (int i = 0 i < time i++) Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. Any live cell with more than three live neighbors dies, as if by overpopulation. Any live cell with two or three live neighbors lives on to the next generation. * Any live cell with fewer than two live neighbors dies, as if by under population. I have programmed Conway's Game of Life in C++.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |