My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
No, it's not my homework. I'm doing it for myself and trying to learn c++. I'm trying to solve it, but nothing works. Elysia mentioned that i should try with flowchart or pseudo code, but i don't know what it is. Tried to google it but still can't understand. I think that i should change something here:
should i change column into a variable? And is it possible to change row pos0,pos1,pos2... into one variable?Code:if(turn == 1) { place[pos0][0] = cPlayerMark; pos0--; // every time you place mark, it goes up by 1 column tie++; // not sure if this necessary , but if tie == 42, game is draw, because then its full board. } else if(turn == 2) { place[pos1][1] = cPlayerMark; pos1--; tie++; } else if(turn == 3) { place[pos2][2] = cPlayerMark; pos2--; tie++; } else if(turn == 4) { place[pos3][3] = cPlayerMark; pos3--; tie++; } else if(turn == 5) { place[pos4][4] = cPlayerMark; pos4--; tie++; } else if(turn == 6) { place[pos5][5] = cPlayerMark; pos5--; tie++; } else if(turn == 7) { place[pos6][6] = cPlayerMark; pos6--; tie++; }
Flowchart - Wikipedia, the free encyclopedia
Regardless of homework or not, we do not usually help people solve their problems by fixing it for them. We tend to give them a nudge in the right direction, so to speak.
Ok, but could you write some little code? Just a start of it, because i don't know how to start.
Yes!!! Finally finished my checkwin function:
Works perfectly. Thanks to all who helped me!Code:int checkwin(){ for(int i=0; i<4; i++) // check for horizontal { for(int j=0; j<6; j++) { if(place[j][i] == cPlayerMark && place[j][i+1] == cPlayerMark && place[j][i+2] == cPlayerMark && place[j][i+3] == cPlayerMark) { return 1; } } } for(int i=0; i<4; i++) // check for vertical { for(int j=0; j<3; j++) { if(place[j][i] == cPlayerMark && place[j+1][i] == cPlayerMark && place[j+2][i] == cPlayerMark && place[j+3][i] == cPlayerMark) { return 1; } } } for(int i=0; i<4; i++) // check for diagonal right to left { for(int j=0; j<6; j++) { if(place[j][i] == cPlayerMark && place[j+1][i+1] == cPlayerMark && place[j+2][i+2] == cPlayerMark && place[j+3][i+3] == cPlayerMark) { return 1; } } } for(int i=0; i<4; i++) // check for diagonal left to right { for(int j=0; j<6; j++) { if(place[j][i] == cPlayerMark && place[j+1][i-1] == cPlayerMark && place[j+2][i-2] == cPlayerMark && place[j+3][i-3] == cPlayerMark) { return 1; } } } }
EDITED: Not perfectly.
Last edited by Aeoskype; 04-24-2013 at 07:42 AM.
You should change to using an array for posN, and then this code will be 1/7th of the length.
Yes not perfectly alright.
If you came up with that on your own then well done, I'm glad you stuck in there and thought it through. Getting there on your own is always more satisfying.
The problem remaining is that you have buffer overruns and buffer underruns. These can be corrected for by adjusting the bounds of all of the for-loops.
E.g. if you loop contains [i-1]. Then start i at one, not zero.
You've already corrected line 18 for this, but you have more to go.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"