Beispiel #1
0
		public static void Main(string[] args) {
			//ICASettings settings = CAServer.CACompiler.compile(args[0]);
			uint size = 500;
			CABoard board = new CABoard(size, 0);
			board.setCASettings(new Life());

			uint[][] bd = new uint[size][];
			for(int i = 0; i < bd.Length; i++) {
				bd[i] = new uint[size];
			}
			IDictionary<Point, uint> glider = new Dictionary<Point, uint>();
			glider[new Point(1,0)] = 1;
			glider[new Point(0,2)] = 1;
			glider[new Point(1,2)] = 1;
			glider[new Point(3,1)] = 1;
			glider[new Point(4,2)] = 1;
			glider[new Point(5,2)] = 1;
			glider[new Point(6,2)] = 1;

			foreach(Point p in glider.Keys) {
				bd[p.x][p.y] = glider[p];
			}

			board.userChanged(glider);

			//printBoard(bd);
			int numSteps = 0;
			int maxChanges = 0;
			/*while(true) {
				string next = Console.ReadLine();
				if(next == "q") {
					break;
				} else if(next == "g") {
					foreach(Point p in glider.Keys) {
						bd[p.x][p.y] = glider[p];
					}
					board.userChanged(glider);
					continue;
				}*/
			for(int i = 0; i < 10000; i++) {
				numSteps++;
				IDictionary<Point, uint> changes = board.step();
				if(changes.Count > maxChanges) {
					maxChanges = changes.Count;
				}

				foreach (Point p in changes.Keys) {
					bd[p.x][p.y] = changes[p];
				}

				//Console.WriteLine("Step : " + numSteps);
				//Console.WriteLine("NumChanges : " + changes.Count);
				//printBoard(bd);
			}
			Console.WriteLine("Max changes in a round: " + maxChanges);
		}
Beispiel #2
0
			/**
			 * Creates a StepPart for  the given board
			 *
			 * @param parent The parent of this StepPart
			 * @param board The state board
			 **/
			public StepPart(CABoard parent, uint[][] board) {
				this.objLock = new object();
				this.rangeLock = new object();
				this.valid = false;
				this.rangeSet = false;
				this.start = 0;
				this.end = 0;

				this.board = board;
				this.parent = parent;
				this.parts = new Dictionary<Point, uint>();
			}
		public bool reinit(uint defaultState) {
			if(state == State.UnInited) {
				if(caSettings != null) {
					for(int i = 0; i < 500; i++) {
						for(int j = 0; j < 500; j++) {
							lastState[i][j] = defaultState;
						}
					}
					if(board != null) {
						board.closeBoard();
					}
					board = new CABoard(500, defaultState);
					board.setCASettings(caSettings);
					accumulated.Clear();
					state = State.Stopped;
					return true;
				} else {
					return false;
				}
			} else {
				return false;
			}
		}