Problem with instructions from string[] to bool[][]

I want to use a string[] to change some of the values of a bool[][] 2D array and "move" in the same array.
So I have all the comands for those instructions in a file this way:

true down left
left false right
right true right

and I copy that word for word to a
 
string instruc[] 

andI want to use this string to "move" in the array[n][m] with the first comand of instruc being aplplied to board[10][10] and then moving in the array acording with the instruction as if it was a board. Here is the code with the failing part.

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
#include<iostream>
#include<fstream>
int main(){
int N=20;
bool board[N][N];
//All elements of board are false
for(int i=N;i>=0;i--){
    for(int a=N;a>=0;a--){
        board[i][a]=false;
    }
    std::cout<<std::endl;
}
// Read the file and gives the number of commands.
std::ifstream w("in.txt");
int words = 0;
std::string word;
while(w >> word){
    words++;
}
w.close();
std::cout<<"Number of comands: "<<words<<std::endl;
//Read the file and puts all the commands in the string instruc[]
std::ifstream F;
F.open("in.txt");
std::string instruc[words];
    for(int i=0;i<=words;i++){
            F >> instruc[i];
    }
F.close();
//Shows all the commands in the screen
bool pinta;
for(int c=0;c<=words;c++){
    std::cout<<instruc[c]<<"\t";
}
int a=21;
int r=21;
//Use the commands for the array.
//Don't work, this is my Problem.
for(int c=0;c<=words;c++){
    instruc[c];
    board[a][r];
    if(instruc[c]=="izq"){
       a=a+1;
    }
    if(instruc[c]=="dcha"){
        a=a-1;
    }
    if(instruc[c]=="aba"){
        r=r-1;
        return r;
    }
    if(instruc[c]=="arr"){
        r=r+1;
    }
    if(instruc[c]=="verd"){
        pinta=true;
    }
    if(instruc[c]=="fals"){
        pinta=false;
    }
}
//Shows the modified board
//The board is not how it should be
for(a=0;a<=41;a++){
for(r=0;r<=41;r++){
    std::cout<<board[a][r]<<"\t";
}
std::cout<<"\n";
}
std::cout<<" The program has ended";

return 0;
}


Any idea on how can it be done?
Last edited on
Topic archived. No new replies allowed.