00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // 00015 00016 #if !defined(__CLIFEENGINE_H__) 00017 #define __CLIFEENGINE_H__ 00018 00019 #include <e32base.h> 00020 00021 // Cell array dimensions 00022 const TInt DIM_X_ARRAY = 16; 00023 const TInt DIM_Y_ARRAY = 8; 00024 00025 // Cell array type 00026 typedef TBool TCellArray[DIM_X_ARRAY][DIM_Y_ARRAY]; 00027 00028 // A "Game of Life" engine 00029 // After John Conway, Scientific American 223 (October 1970): 120-123 00030 class CLifeEngine: public CBase 00031 { 00032 public: 00033 // Initalise engine with random seed 00034 CLifeEngine(const TInt64& aSeed); 00035 // Moves forward one generation 00036 void AddGeneration(); 00037 // Gets cell array 00038 const TCellArray& GetCellArray() const 00039 {return iCellArray;} 00040 // Resets all cells to random state 00041 void Reset(); 00042 00043 private: 00044 // Gets number of neighbors for cell x,y 00045 TInt NumNeighbors(TInt x, TInt y); 00046 00047 private: 00048 // Random num generator seed 00049 TInt64 iSeed; 00050 // Cell array 00051 TCellArray iCellArray; 00052 // Temporary working cell array 00053 TCellArray iTempCellArray; 00054 }; 00055 00056 00057 #endif
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.