Пример #1
0
    /*
     * Precondition:string and double
     * Postcondition:filename is str and 2d array copies the file,double sets the drainRate for the battery for the sensor
     */
    public robot(string str, double drainRate)
    {
        filename = str;
        grid     = new int[SIZE, SIZE];
        count    = 0;
        sObj     = new sensor(drainRate);
        nAct     = new actuator(0);
        sAct     = new actuator(1);
        eAct     = new actuator(2);
        wAct     = new actuator(3);
        rCoord   = 5;
        cCoord   = 5;
        state    = true;
        string text = System.IO.File.ReadAllText(str);
        string ss   = text.Replace("\n", " ");

        ss = string.Join(" ", ss.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
        string[] arr = ss.Split(' ');
        for (int r = 0; r <= 10; r++)
        {
            for (int c = 0; c <= 10; c++)
            {
                grid[r, c] = Int32.Parse(arr[count]);;
                count++;
            }
        }
    }
Пример #2
0
    /*
     * Precondition:string and double
     * Postcondition:filename is str and 2d array copies the file,double sets the drainRate for the battery for the sensor
     */
    public robot(string str, double drainRate)
    {
        if (str == null)
        {
            throw new ArgumentNullException("invalid file");
        }
        orientationState = orientation.Up;
        filename         = str;
        grid             = new int[SIZE, SIZE];
        count            = 0;
        upSensor         = new sensor(drainRate, 0, grid);
        downSensor       = new sensor(drainRate, 1, grid);
        rightSensor      = new sensor(drainRate, 2, grid);
        leftSensor       = new sensor(drainRate, 3, grid);
        nAct             = new actuator(0);
        sAct             = new actuator(1);
        eAct             = new actuator(2);
        wAct             = new actuator(3);
        rCoord           = 5;
        cCoord           = 5;
        state            = true;
        string text = System.IO.File.ReadAllText(filename);
        string ss   = text.Replace("\n", " ");

        ss = string.Join(" ", ss.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
        string[] arr = ss.Split(' ');
        for (int r = 0; r <= 10; r++)
        {
            for (int c = 0; c <= 10; c++)
            {
                grid[r, c] = Int32.Parse(arr[count]);;
                count++;
            }
        }
    }
Пример #3
0
    /*
     * PreCondition: int
     * PostCondition: sets the field arrayofgrid to that one and also intializes the arrayofgrid to strings of the gridfile name i.e Grid0.txt Grid1.txt
     */
    public submersible(int numberofGrid)
    {
        this.numberofGrid = numberofGrid;
        Random random = new Random();
        double rand   = random.Next(1, 20);

        verticalActuator = new actuator(4);
        verticalSensor   = new sensor(rand, 4);
        level            = 0; //higher is deeper
        arrayofgrid      = new string[numberofGrid];
        for (int i = 0; i <= numberofGrid; i++)
        {
            arrayofgrid[i] = "Grid" + i + ".txt";
        }
    }