Chess Queen moves [Help]

Pages: 12
Let's see your latest code please.
Here it is. I haven't changed much, because i can't find what is the reason why my program won't tell if the move is applicable or not.
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
111
#include<iostream>
#include <cstdlib>
using namespace std;
bool valid_move (char board[8][8], int ROWS, int COLS);
int main(){
	bool valid_move();
    char board[8][8];
    int p,o,z,ROWS,COLS,num_pat=0;
    char ans;
    char again;
   int digits=0;
    for(int i=0;i<8;i++)
            for(int j=0;j<8;j++)
    board[i][j]= 0;
    cout<<"+-- +--    /| +---+    ---+ |\n";
    cout<<"|   |__     | |   | --  __| |\n";
    cout<<"|__ ___|    | |___|    |___ |___\n";
    cout<<endl<<endl;
	
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
	cout<<"!   !   !   !   !   !   !   !   !"<<endl;
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
	cout<<"!   !   !   !   !   !   !   !   !"<<endl;
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
	cout<<"!   !   !   !   !   !   !   !   !"<<endl;
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
    cout<<"!   !   !   !   !   !   !   !   !"<<endl;
    cout<<"+===+===+===+===+===+===+===+===+"<<endl;
	cout<<"!   !   !   !   !   !   !   !   !"<<endl;
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
	cout<<"!   !   !   !   !   !   !   !   !"<<endl;
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
	cout<<"!   !   !   !   !   !   !   !   !"<<endl;
	cout<<"+===+===+===+===+===+===+===+===+"<<endl;
    cout<<"!   !   !   !   !   !   !   !   !"<<endl;
    cout<<"+===+===+===+===+===+===+===+===+"<<endl;
   do{
    cout<<"Enter Rows:"; cin>>ROWS;
    if(ROWS < 0 || ROWS > 7)
    {
    	cout<<"The value of "<<ROWS<<" is not a valid row!\n";
    	return 0;
	}
    cout<<"Enter Columns:"; cin>>COLS;
	if(COLS < 0 || COLS > 7)
	{
		cout<<"The value of "<<COLS<<" is not a valid column!\n";
		return 0;
	 }
    board[ROWS][COLS]='Q';
    cout<<endl<<endl<<"Add another move? (y/n): ";
    cin>>ans;
    }while(ans=='Y' || ans=='y');
    system("cls");
    cout<<"+===+===+===+===+===+===+===+===+"<<endl;
     
    
    for(int i=0;i<8;i++){
            cout<<"! ";
            for(int j=0;j<8;j++)
            cout<<board[i][j]<<" ! ";
            cout<<endl<<"+===+===+===+===+===+===+===+===+"<<endl;
            }       
    system("pause");
    }
bool valid_move (char board[8][8], int ROWS, int COLS)
{  int z, o, p;

    for (z = 0; z < COLS; z++)
    {  
	if (board[ROWS][z])
           return false;
    }
   for (z = 7; z > COLS; z--)
   { 
   if (board[ROWS][z])
        return false;   
    }
    for (z = 0; z < ROWS; z++)
    { 
	if (board[z][COLS])
         return false;
     }
     for (z = 7; z > ROWS; z--)
    {  
	if (board[z][COLS])
          return false;
    }
    for (z= 0, o= COLS-ROWS; z<COLS && ROWS>o ; z++, o++)
    {  
	if (board[z][o])
           return false;
    }
    for (z= 7, o= ROWS-p ; z>=0 && o<7 ; z--, o++)
    { 
	if (board[z][o])
         return false;
    }
    return true;

    if (valid_move (board, ROWS, COLS))
      {
      	cout<< "Move is applicable" << endl;
	   }
    else
    {
    	cout << "Move is not applicable" << endl;
	}
	  system("pause");
	  
}
i can't find what is the reason why my program won't tell if the move is applicable or not.

Because you never call valid_move()?

Line 6 is bogus. You're declaring a function prototype for valid_move that takes no arguments.

Lines 101-108 were intended to be inside main. As you have it, you will never reach line 101 because of the return true at line 99. Even if you did reach line 101, you would be making a recursive call to valid_move() resulting in your program abnormally terminating with a stack overflow.

Thanks @AbstractionAnon!. Now my program is complete :).
Last edited on
Topic archived. No new replies allowed.
Pages: 12