/// <summary>
        /// Attempt to compile delta function code entered. Any compiler
        /// messages are displayed.
        /// </summary>
        private void compile(object sender, RoutedEventArgs e)
        {
            // Gather information entered
            string deltaStr = deltaInputBox.Text;
            int numStates = (numStatesInputBox.Text == "") ? 1 : int.Parse(numStatesInputBox.Text);
            uint defaultState = (defaultStateInputBox.Text == "") ? 0 : uint.Parse(defaultStateInputBox.Text);
            CPoint[] neighbors = new CPoint[Neighborhood.Count];
            int i = 0;
            foreach (OPoint p in Neighborhood) {
                neighbors[i] = new CPoint(p.X, p.Y);
                i++;
            }

            // Attempt to compile a new CA with the entered information
            ca = new CA(numStates, defaultState, neighbors, deltaStr);
            compileMesseageOutputBox.Text = ca.compileDelta();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the specified CA into this simulation, and clear the grid if necessary
        /// </summary>
        /// <param name="newCA">A CA representing a CA and its parameters</param>
        /// <returns>True if the CA is valid, or false otherwise</returns>
        public bool initCA(CA newCA)
        {
            // If an incompatible CA has previously been run, clear the grid
            if (getNumStates() > newCA.NumStates) initGridBlank(gridSizeX, gridSizeY);

            // Load and compile the new CA
            string result;
            lock (ca) {
                ca = newCA;
                result = newCA.compileDelta();
                if (ca.Neighborhood != null) optimizing = true;
                else optimizing = false;
            }

            // Return true if the CA's delta function compiled successfully
            return (result == "Delta function successfully compiled");
        }