Arrays and booleans?

Hey guys.

I am looking for method which makes a boolean function return true when an 2d has been evaluated.

The boolean function looks like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
bool manipulate(int distance, int replacement,int start_x , int start_y, int **array,int height, int lenght)
{

    if (start_y + distance > lenght && start_x + distance > height) {
        return true;
    }
    
    cout << "coloured X: " << start_x << " and Y: " << start_y   << "  "<<replacement<< endl;

    if (lenght > (start_y + distance)) {                // West
        if (array[start_x][start_y + distance]  != 1) {
            array[start_x][start_y + distance] = replacement;
            cout << "coloured X: " << start_x << " and Y: " << start_y + distance << endl;

        }
    }
    if (height > start_x+distance) {                    //North
        if (array[start_x+distance][start_y] != 1) {
           array[start_x+distance][start_y] = replacement;
            cout << "coloured X: " << start_x + distance  << " and Y: " << start_y << "value: " << array[start_x+distance][start_y]<< endl;
        }
    }
    
    if (start_y-distance >= 0) {                         //South
        if (array[start_x][start_y-distance] != 1) {
            array[start_x][start_y-distance] = replacement;
            cout << "coloured X: " << start_x   << " and Y: " << start_y-distance<< endl;
    
        }
    }
   
    if (start_x-distance >= 0) {                         //East
        if (array[start_x-distance][start_y] != 1) {
            array[start_x-distance][start_y] = replacement;
            cout << "coloured X: " << start_x - distance  << " and Y: " << start_y<< endl;
        }
    }
   
    
    for (int x = 0; x<= distance; x++) {
        if (start_x-x >= 0 && start_y+distance < lenght) {
            if (array[start_x-x][start_y + distance] != 1) {        // West down
                array[start_x-x][start_y + distance] = replacement;
                cout << "coloured X: " << start_x -x  << " and Y: " << start_y+distance<< endl;

            }
        }
        if (start_x-x >= 0 && start_y-distance >= 0) {
            if (array[start_x-x][start_y - distance] != 1) {         //East down
                array[start_x-x][start_y - distance] = replacement;
                cout << "coloured X: " << start_x -x  << " and Y: " << start_y-distance<< endl;

            }

        }
        
        if (start_y-x >= 0 && start_x-distance >= 0) {
        
            if (array[start_x-distance][start_y-x] != 1) {          //North  <- direction
                array[start_x-distance][start_y-x] = replacement;
                cout << "coloured X: " << start_x -distance  << " and Y: " << start_y-x<< endl;
            }
        }
        if (start_y-x >= 0 && start_x+distance < height) {
            if (array[start_x+distance][start_y-x] != 1) {
                array[start_x+distance][start_y-x] = replacement;   // South <- direction
                cout << "coloured X: " << start_x + distance  << " and Y: " << start_y-x<< endl;
                
            }
        }
        
        
        if (lenght > (start_y + x) && start_x-distance >= 0) {
            if (array[start_x-distance][start_y+x] != 1) {          //North -> direction
                array[start_x-distance][start_y+x] = replacement;
                cout << "coloured X: " << start_x -distance  << " and Y: " << start_y+x<< endl;

            }
        }
        
        if (lenght > (start_y + x) && start_x+distance < height) {
            if (array[start_x+distance][start_y+x]  != 1) {         //South -> direction
                array[start_x+distance][start_y+x] = replacement;
                cout << "coloured X: " << start_x +distance  << " and Y: " << start_y+x<< endl;

            }
        }

        
        if (start_x+x < height && start_y-distance >= 0) {
            if (array[start_x+x][start_y - distance] != 1) {        // West UP
                array[start_x+x][start_y - distance] = replacement;
                cout << "coloured X: " << start_x +x  << " and Y: " << start_y-distance<< endl;

                
            }
        }
        if (start_x+x < height && start_y+distance < lenght) {
            if (array[start_x+x][start_y + distance] != 1) {        //  East up
                array[start_x+x][start_y + distance] = replacement;
                cout << "coloured X: " << start_x+x  << " and Y: " << start_y+distance<< endl;

            }
        
        }
       
    }

    
}


The function manipulate the elements in a certain distance from the stating point. height and length is the dimensions of the array, replacement contains the value which will be used for replacement.

I tried doing this way

1
2
3
if (start_y + distance > lenght && start_x + distance > height) {
        return true;
    }


But when look at the output, it clearly shows that no the whole array has been evaluated.
Last edited on
closed account (28poGNh0)
this is not a
boolean function
this is a mega function :)

what are you trying to do exactly?
This function changes the value all values in a given distance in a 2d matrix.

such that

If i had a matrix which looked like this

0000
0000
0000
0000

and i wanted to change all value which two element away from a center value(lets say (0.0))
i could use this function to do so

0010
0010
1110
0000


I was thinking of making it a boolean, such that it would return true when it had evaluated the whole array.

It's part of a Waveplanner solution based on this
http://www.cs.tufts.edu/comp/150IR/labs/wavefront.html

So this part evaluated each cell and numerate them according to the distance to the center element.
Topic archived. No new replies allowed.