I am attempting to create a knights tour program which is driven by a stl stack. The problem is I keep getting "Illegal move type 35 in try_move" (from line 132). The Stack was hacked in from a previous version driven by arrays so I know it's probably something I've done, but I'm at my wits end trying to figure it out so if someone could give me a hint as to the root cause I would be very grateful.
When I look at your main function, my first quip is with: void main (). The C++ standard states that main must return int. Therefore, that definition must be int main().
The second issue is with this:
30 31 32 33 34 35 36 37 38 39
int move_valid ();
void print_board();
void retract_move ();
void try_move (int);
void push(int v);
int pop();
int top();
int stack_empty();
int stack_full();
being inside main.
I also just noticed this:
1 2 3 4 5 6 7 8 9 10
stack<int> istack;
int board[N][N];
int x,
y,
newx,
newy,
move_number,
move_type;
These should not be global. They should all be inside main.
---
I think you need to redesign this; you don't need those globals and the function declarations go outside of main().
Yes, I know that there are a few flaws with this program but that was how I was given it. I had to add a stl stack implementation to count the number of 'pops' made (it was array driven before), and that is what I came up with. The program compiles but doesn't work properly, because I am not 100% on how to implement it (see first post). I was asking if anyone could give assistance on implementing the stack.
Chrisname is right, but he wouldn't be giving you a hard time if it was part of a struct.
Line 33: You're declaring functions inside of main?
Line 53: Maybe try a while() instead of a do {...}while();?
Line 59: I will not evaluate. See below.
Line 92-94: move_valid function, no f***ing NO! This might work but I don't like reading it. If your problem is here then I will not catch it because I don't have the patience to dig through it.
This is also a reason to take the parts the chrisname pointed to and make them into a struct.
Rip-down-and-redo, some of this code is ok, but as a whole this is a garbled mess. I'm not surprized you can't find what is wrong with it.
HINT: If your switch statement is ALWAYS choosing the default, then there is something wrong with the int you are feeding it. Try a cout test to see what value mt holds at this point in the code.