Exemplo n.º 1
0
        private void CreateState()
        {
            // Get a random number of Dirty Cells
            int numDirty = RandomNumberHelper.RandomNumber(1, (_gridSize * _gridSize));

            // Set variables
            _initState = new bool[_gridSize, _gridSize];

            // Build stack of tuples (Usually more efficient than looping till the right cell is randomly chosen)
            ArrayList arrList = new ArrayList();

            for (int i = 0; i < _gridSize; i++)
            {
                for (int j = 0; j < _gridSize; j++)
                {
                    arrList.Add((i, j));
                }
            }

            // Loop until all dirty cells are selected
            while (arrList.Count > 0 && numDirty-- > 0)
            {
                // Get row,col tuple
                int nextIndex = RandomNumberHelper.RandomNumber(0, arrList.Count - 1);
                var nextTuple = (Tuple <int, int>)arrList[nextIndex];

                // Set state to dirty and remove row,col combo
                _initState[nextTuple.Item1, nextTuple.Item2] = true;
                arrList.RemoveAt(nextIndex);
            }
        }
Exemplo n.º 2
0
        public void RandomNumberHelperTests_RandomNumber()
        {
            var r = RandomNumberHelper.RandomNumber();

            Logger.Debug("random number: {0}", r);

            for (var i = 0; i <= 1000; i++)
            {
                r = RandomNumberHelper.RandomNumber();
            }
        }
Exemplo n.º 3
0
 // Set Agent Position Properties
 public void SetAgentPosition(int xpos, int ypos)
 {
     // if < 0 Set Random, if > gridsize set 0
     AgentXPos = xpos >= 0 ? (xpos >= GridSize ? 0 : xpos) : RandomNumberHelper.RandomNumber(0, GridSize);
     AgentYPos = ypos >= 0 ? (ypos >= GridSize ? 0 : ypos) : RandomNumberHelper.RandomNumber(0, GridSize);
 }