Chess in C++

Pages: 12
1
2
3
4
5
6
7
8
9
10
11
if (board[row2+1][column2+2]=='n' || board[row2+2][column2+1]=='n' || board[row2-1][column2+2]=='n' || board[row2-2][column2+1]=='n' || // Check From Knight        
				    board[row2+1][column2-2]=='n' || board[row2+2][column2-1]=='n' || board[row2-1][column2-2]=='n' || board[row2-2][column2-1]=='n')
				{	return true; }
				if (board[row2-1][column2-1]=='p' || board[row2-1][column2+1]=='p')                                                                     // Check From Pawn  
				{	return true; }
				if (board[row2-1][column2]=='k' || board[row2-1][column2-1]=='k' || board[row2-1][column2+1]=='k' || board[row2][column2-1]=='k' ||     // Check From King
					board[row2][column2+1]=='k' || board[row2+1][column2-1]=='k' || board[row2+1][column2]=='k' || board[row2+1][column2+1]=='k') 
				{	return true; }
				else
					return false; 
			}
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
if (turn=='Y' && board[row2][column2]=='k')                // Searches Board For Black King
			{
				if (board[row2+1][column2]=='R' || board[row2+2][column2]=='R' || board[row2+3][column2]=='R' || board[row2+4][column2]=='R' ||         // Check From Below Rook 
				    board[row2+5][column2]=='R' || board[row2+6][column2]=='R' || board[row2+7][column2]=='R')
				{
					if (board[row2+1][column2]=='R')                                                                                                
					{	return true; }
					else if (board[row2+2][column2]=='R' && board[row2+1][column2]==' ')
					{	return true; }
					else if (board[row2+3][column2]=='R' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ')
					{	return true; }
					else if (board[row2+4][column2]=='R' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ')
					{	return true; }
					else if (board[row2+5][column2]=='R' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ' && board[row2+4][column2]==' ')
					{	return true; }
					else if (board[row2+6][column2]=='R' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ' && board[row2+4][column2]==' ' && board[row2+5][column2]==' ')
					{	return true; }
					else if (board[row2+7][column2]=='R' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ' && board[row2+4][column2]==' ' && board[row2+5][column2]==' ' && 
							 board[row2+6][column2]==' ')
					{	return true; }
				}
				if(board[row2-1][column2]=='R' || board[row2-2][column2]=='R' || board[row2-3][column2]=='R' || board[row2-4][column2]=='R' ||          // Check From Above Rook  
				   board[row2-5][column2]=='R' || board[row2-6][column2]=='R' || board[row2-7][column2]=='R')
				{
					if (board[row2-1][column2]=='R')
					{	return true; }
					else if (board[row2-2][column2]=='R' && board[row2-1][column2]==' ')
					{	return true; }
					else if (board[row2-3][column2]=='R' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ')
					{	return true; }
					else if (board[row2-4][column2]=='R' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ')
					{	return true; }
					else if (board[row2-5][column2]=='R' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ' && board[row2-4][column2]==' ')
					{	return true; }
					else if (board[row2-6][column2]=='R' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ' && board[row2-4][column2]==' ' && board[row2-5][column2]==' ')
					{	return true; }
					else if (board[row2-7][column2]=='R' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ' && board[row2-4][column2]==' ' && board[row2-5][column2]==' ' && 
							 board[row2-6][column2]==' ')
					{	return true; }
				}
				if(board[row2][column2+1]=='R' || board[row2][column2+2]=='R' || board[row2][column2+3]=='R' || board[row2][column2+4]=='R' ||          // Check From Right Rook  
				   board[row2][column2+5]=='R' || board[row2][column2+6]=='R' || board[row2][column2+7]=='R')
				{
					if (board[row2][column2+1]=='R')
					{	return true; }
					else if (board[row2][column2+2]=='R' && board[row2][column2+1]==' ')
					{	return true; }
					else if (board[row2][column2+3]=='R' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ')
					{	return true; }
					else if (board[row2][column2+4]=='R' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ')
					{	return true; }
					else if (board[row2][column2+5]=='R' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ' && board[row2][column2+4]==' ')
					{	return true; }
					else if (board[row2][column2+6]=='R' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ' && board[row2][column2+4]==' ' && board[row2][column2+5]==' ')
					{	return true; }
					else if (board[row2][column2+7]=='R' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ' && board[row2][column2+4]==' ' && board[row2][column2+5]==' ' && 
							 board[row2][column2+6]==' ')
					{	return true; }
				}
				if(board[row2][column2-1]=='R' || board[row2][column2-2]=='R' || board[row2][column2-3]=='R' || board[row2][column2-4]=='R' ||          // Check From Left Rook 
				   board[row2][column2-5]=='R' || board[row2][column2-6]=='R' || board[row2][column2-7]=='R')
				{
					if (board[row2][column2-1]=='R')
					{	return true; }
					else if (board[row2][column2-2]=='R' && board[row2][column2-1]==' ')
					{	return true; }
					else if (board[row2][column2-3]=='R' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ')
					{	return true; }
					else if (board[row2][column2-4]=='R' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ')
					{	return true; }
					else if (board[row2][column2-5]=='R' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ' && board[row2][column2-4]==' ')
					{	return true; }
					else if (board[row2][column2-6]=='R' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ' && board[row2][column2-4]==' ' && board[row2][column2-5]==' ')
					{	return true; }
					else if (board[row2][column2-7]=='R' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ' && board[row2][column2-4]==' ' && board[row2][column2-5]==' ' && 
							 board[row2][column2-6]==' ')
					{	return true; }
				}
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
if (board[row2+1][column2+1]=='B' || board[row2+2][column2+2]=='B' || board[row2+3][column2+3]=='B' || board[row2+4][column2+4]=='B' || // Check From Right-Down Bishop 
				    board[row2+5][column2+5]=='B' || board[row2+6][column2+6]=='B' || board[row2+7][column2+7]=='B')
				{
					if (board[row2+1][column2+1]=='B')
					{	return true; }
					else if (board[row2+2][column2+2]=='B' && board[row2+1][column2+1]==' ')
					{	return true; }
					else if (board[row2+3][column2+3]=='B' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ')
					{	return true; }
					else if (board[row2+4][column2+4]=='B' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ')
					{	return true; }
					else if (board[row2+5][column2+5]=='B' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ' && board[row2+4][column2+4]==' ')
					{	return true; }
					else if (board[row2+6][column2+6]=='B' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ' && board[row2+4][column2+4]==' ' && board[row2+5][column2+5]==' ')
					{	return true; }
					else if (board[row2+7][column2+7]=='B' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ' && board[row2+4][column2+4]==' ' && board[row2+5][column2+5]==' ' && 
							 board[row2+6][column2+6]==' ')
					{	return true; }
				}
				if (board[row2+1][column2-1]=='B' || board[row2+2][column2-2]=='B' || board[row2+3][column2-3]=='B' || board[row2+4][column2-4]=='B' || // Check From Left-Down Bishop 
				    board[row2+5][column2-5]=='B' || board[row2+6][column2-6]=='B' || board[row2+7][column2-7]=='B')
				{
					if (board[row2+1][column2-1]=='B')
					{	return true; }
					else if (board[row2+2][column2-2]=='B' && board[row2+1][column2-1]==' ')
					{	return true; }
					else if (board[row2+3][column2-3]=='B' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ')
					{	return true; }
					else if (board[row2+4][column2-4]=='B' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ')
					{	return true; }
					else if (board[row2+5][column2-5]=='B' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ' && board[row2+4][column2-4]==' ')
					{	return true; }
					else if (board[row2+6][column2-6]=='B' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ' && board[row2+4][column2-4]==' ' && board[row2+5][column2-5]==' ')
					{	return true; }
					else if (board[row2+7][column2-7]=='B' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ' && board[row2+4][column2-4]==' ' && board[row2+5][column2-5]==' ' && 
							 board[row2+6][column2-6]==' ')
					{	return true; }
				}
				if (board[row2-1][column2+1]=='B' || board[row2-2][column2+2]=='B' || board[row2-3][column2+3]=='B' || board[row2-4][column2+4]=='B' || // Check From Right-Up Bishop 
				    board[row2-5][column2+5]=='B' || board[row2-6][column2+6]=='B' || board[row2-7][column2+7]=='B')
				{
					if (board[row2-1][column2+1]=='B')
					{	return true; }
					else if (board[row2-2][column2+2]=='B' && board[row2-1][column2+1]==' ')
					{	return true; }
					else if (board[row2-3][column2+3]=='B' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ')
					{	return true; }
					else if (board[row2-4][column2+4]=='B' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ')
					{	return true; }
					else if (board[row2-5][column2+5]=='B' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ' && board[row2-4][column2+4]==' ')
					{	return true; }
					else if (board[row2-6][column2+6]=='B' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ' && board[row2-4][column2+4]==' ' && board[row2-5][column2+5]==' ')
					{	return true; }
					else if (board[row2-7][column2+7]=='B' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ' && board[row2-4][column2+4]==' ' && board[row2-5][column2+5]==' ' && 
							 board[row2-6][column2+6]==' ')
					{	return true; }
				}
				if (board[row2-1][column2-1]=='B' || board[row2-2][column2-2]=='B' || board[row2-3][column2-3]=='B' || board[row2-4][column2-4]=='B' || // Check From Left-Up Bishop 
				    board[row2-5][column2-5]=='B' || board[row2-6][column2-6]=='B' || board[row2-7][column2-7]=='B')
				{
					if (board[row2-1][column2-1]=='B')
					{	return true; }
					else if (board[row2-2][column2-2]=='B' && board[row2-1][column2-1]==' ')
					{	return true; }
					else if (board[row2-3][column2-3]=='B' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ')
					{	return true; }
					else if (board[row2-4][column2-4]=='B' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ')
					{	return true; }
					else if (board[row2-5][column2-5]=='B' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ' && board[row2-4][column2-4]==' ')
					{	return true; }
					else if (board[row2-6][column2-6]=='B' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ' && board[row2-4][column2-4]==' ' && board[row2-5][column2-5]==' ')
					{	return true; }
					else if (board[row2-7][column2-7]=='B' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ' && board[row2-4][column2-4]==' ' && board[row2-5][column2-5]==' ' && 
							 board[row2-6][column2-6]==' ')
					{	return true; }
				}
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
if (board[row2+1][column2]=='Q' || board[row2+2][column2]=='Q' || board[row2+3][column2]=='Q' || board[row2+4][column2]=='Q' ||         // Check From Below Queen 
				    board[row2+5][column2]=='Q' || board[row2+6][column2]=='Q' || board[row2+7][column2]=='Q')
				{
					if (board[row2+1][column2]=='Q')
					{	return true; }
					else if (board[row2+2][column2]=='Q' && board[row2+1][column2]==' ')
					{	return true; }
					else if (board[row2+3][column2]=='Q' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ')
					{	return true; }
					else if (board[row2+4][column2]=='Q' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ')
					{	return true; }
					else if (board[row2+5][column2]=='Q' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ' && board[row2+4][column2]==' ')
					{	return true; }
					else if (board[row2+6][column2]=='Q' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ' && board[row2+4][column2]==' ' && board[row2+5][column2]==' ')
					{	return true; }
					else if (board[row2+7][column2]=='Q' && board[row2+1][column2]==' ' && board[row2+2][column2]==' ' && 
					         board[row2+3][column2]==' ' && board[row2+4][column2]==' ' && board[row2+5][column2]==' ' && 
							 board[row2+6][column2]==' ')
					{	return true; }
				}
				if(board[row2-1][column2]=='Q' || board[row2-2][column2]=='Q' || board[row2-3][column2]=='Q' || board[row2-4][column2]=='Q' ||          // Check From Above Queen 
				   board[row2-5][column2]=='Q' || board[row2-6][column2]=='Q' || board[row2-7][column2]=='Q')
				{
					if (board[row2-1][column2]=='Q')
					{	return true; }
					else if (board[row2-2][column2]=='Q' && board[row2-1][column2]==' ')
					{	return true; }
					else if (board[row2-3][column2]=='Q' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ')
					{	return true; }
					else if (board[row2-4][column2]=='Q' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ')
					{	return true; }
					else if (board[row2-5][column2]=='Q' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ' && board[row2-4][column2]==' ')
					{	return true; }
					else if (board[row2-6][column2]=='Q' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ' && board[row2-4][column2]==' ' && board[row2-5][column2]==' ')
					{	return true; }
					else if (board[row2-7][column2]=='Q' && board[row2-1][column2]==' ' && board[row2-2][column2]==' ' && 
					         board[row2-3][column2]==' ' && board[row2-4][column2]==' ' && board[row2-5][column2]==' ' && 
							 board[row2-6][column2]==' ')
					{	return true; }
				}
				if(board[row2][column2+1]=='Q' || board[row2][column2+2]=='Q' || board[row2][column2+3]=='Q' || board[row2][column2+4]=='Q' ||          // Check From Right Queen 
				   board[row2][column2+5]=='Q' || board[row2][column2+6]=='Q' || board[row2][column2+7]=='Q')
				{
					if (board[row2][column2+1]=='Q')
					{	return true; }
					else if (board[row2][column2+2]=='Q' && board[row2][column2+1]==' ')
					{	return true; }
					else if (board[row2][column2+3]=='Q' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ')
					{	return true; }
					else if (board[row2][column2+4]=='Q' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ')
					{	return true; }
					else if (board[row2][column2+5]=='Q' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ' && board[row2][column2+4]==' ')
					{	return true; }
					else if (board[row2][column2+6]=='Q' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ' && board[row2][column2+4]==' ' && board[row2][column2+5]==' ')
					{	return true; }
					else if (board[row2][column2+7]=='Q' && board[row2][column2+1]==' ' && board[row2][column2+2]==' ' && 
					         board[row2][column2+3]==' ' && board[row2][column2+4]==' ' && board[row2][column2+5]==' ' && 
							 board[row2][column2+6]==' ')
					{	return true; }
				}
				if(board[row2][column2-1]=='Q' || board[row2][column2-2]=='Q' || board[row2][column2-3]=='Q' || board[row2][column2-4]=='Q' ||          // Check From Left Queen 
				   board[row2][column2-5]=='Q' || board[row2][column2-6]=='Q' || board[row2][column2-7]=='Q')
				{
					if (board[row2][column2-1]=='Q')
					{	return true; }
					else if (board[row2][column2-2]=='Q' && board[row2][column2-1]==' ')
					{	return true; }
					else if (board[row2][column2-3]=='Q' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ')
					{	return true; }
					else if (board[row2][column2-4]=='Q' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ')
					{	return true; }
					else if (board[row2][column2-5]=='Q' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ' && board[row2][column2-4]==' ')
					{	return true; }
					else if (board[row2][column2-6]=='Q' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ' && board[row2][column2-4]==' ' && board[row2][column2-5]==' ')
					{	return true; }
					else if (board[row2][column2-7]=='Q' && board[row2][column2-1]==' ' && board[row2][column2-2]==' ' && 
					         board[row2][column2-3]==' ' && board[row2][column2-4]==' ' && board[row2][column2-5]==' ' && 
							 board[row2][column2-6]==' ')
					{	return true; }
				}
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
if (board[row2+1][column2+1]=='Q' || board[row2+2][column2+2]=='Q' || board[row2+3][column2+3]=='Q' || board[row2+4][column2+4]=='Q' || // Check From Right-Down Queen 
				    board[row2+5][column2+5]=='Q' || board[row2+6][column2+6]=='Q' || board[row2+7][column2+7]=='Q')
				{
					if (board[row2+1][column2+1]=='Q')
					{	return true; }
					else if (board[row2+2][column2+2]=='Q' && board[row2+1][column2+1]==' ')
					{	return true; }
					else if (board[row2+3][column2+3]=='Q' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ')
					{	return true; }
					else if (board[row2+4][column2+4]=='Q' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ')
					{	return true; }
					else if (board[row2+5][column2+5]=='Q' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ' && board[row2+4][column2+4]==' ')
					{	return true; }
					else if (board[row2+6][column2+6]=='Q' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ' && board[row2+4][column2+4]==' ' && board[row2+5][column2+5]==' ')
					{	return true; }
					else if (board[row2+7][column2+7]=='Q' && board[row2+1][column2+1]==' ' && board[row2+2][column2+2]==' ' && 
					         board[row2+3][column2+3]==' ' && board[row2+4][column2+4]==' ' && board[row2+5][column2+5]==' ' && 
							 board[row2+6][column2+6]==' ')
					{	return true; }
				}
				if (board[row2+1][column2-1]=='Q' || board[row2+2][column2-2]=='Q' || board[row2+3][column2-3]=='Q' || board[row2+4][column2-4]=='Q' || // Check From Left-Down Queen 
				    board[row2+5][column2-5]=='Q' || board[row2+6][column2-6]=='Q' || board[row2+7][column2-7]=='Q')
				{
					if (board[row2+1][column2-1]=='Q')
					{	return true; }
					else if (board[row2+2][column2-2]=='Q' && board[row2+1][column2-1]==' ')
					{	return true; }
					else if (board[row2+3][column2-3]=='Q' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ')
					{	return true; }
					else if (board[row2+4][column2-4]=='Q' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ')
					{	return true; }
					else if (board[row2+5][column2-5]=='Q' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ' && board[row2+4][column2-4]==' ')
					{	return true; }
					else if (board[row2+6][column2-6]=='Q' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ' && board[row2+4][column2-4]==' ' && board[row2+5][column2-5]==' ')
					{	return true; }
					else if (board[row2+7][column2-7]=='Q' && board[row2+1][column2-1]==' ' && board[row2+2][column2-2]==' ' && 
					         board[row2+3][column2-3]==' ' && board[row2+4][column2-4]==' ' && board[row2+5][column2-5]==' ' && 
							 board[row2+6][column2-6]==' ')
					{	return true; }
				}
				if (board[row2-1][column2+1]=='Q' || board[row2-2][column2+2]=='Q' || board[row2-3][column2+3]=='Q' || board[row2-4][column2+4]=='Q' || // Check From Right-Up Queen 
				    board[row2-5][column2+5]=='Q' || board[row2-6][column2+6]=='Q' || board[row2-7][column2+7]=='Q')
				{
					if (board[row2-1][column2+1]=='Q')
					{	return true; }
					else if (board[row2-2][column2+2]=='Q' && board[row2-1][column2+1]==' ')
					{	return true; }
					else if (board[row2-3][column2+3]=='Q' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ')
					{	return true; }
					else if (board[row2-4][column2+4]=='Q' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ')
					{	return true; }
					else if (board[row2-5][column2+5]=='Q' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ' && board[row2-4][column2+4]==' ')
					{	return true; }
					else if (board[row2-6][column2+6]=='Q' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ' && board[row2-4][column2+4]==' ' && board[row2-5][column2+5]==' ')
					{	return true; }
					else if (board[row2-7][column2+7]=='Q' && board[row2-1][column2+1]==' ' && board[row2-2][column2+2]==' ' && 
					         board[row2-3][column2+3]==' ' && board[row2-4][column2+4]==' ' && board[row2-5][column2+5]==' ' && 
							 board[row2-6][column2+6]==' ')
					{	return true; }
				}
				if (board[row2-1][column2-1]=='Q' || board[row2-2][column2-2]=='Q' || board[row2-3][column2-3]=='Q' || board[row2-4][column2-4]=='Q' || // Check From Left-Up Queen 
				    board[row2-5][column2-5]=='Q' || board[row2-6][column2-6]=='Q' || board[row2-7][column2-7]=='Q')
				{
					if (board[row2-1][column2-1]=='Q')
					{	return true; }
					else if (board[row2-2][column2-2]=='Q' && board[row2-1][column2-1]==' ')
					{	return true; }
					else if (board[row2-3][column2-3]=='Q' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ')
					{	return true; }
					else if (board[row2-4][column2-4]=='Q' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ')
					{	return true; }
					else if (board[row2-5][column2-5]=='Q' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ' && board[row2-4][column2-4]==' ')
					{	return true; }
					else if (board[row2-6][column2-6]=='Q' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ' && board[row2-4][column2-4]==' ' && board[row2-5][column2-5]==' ')
					{	return true; }
					else if (board[row2-7][column2-7]=='Q' && board[row2-1][column2-1]==' ' && board[row2-2][column2-2]==' ' && 
					         board[row2-3][column2-3]==' ' && board[row2-4][column2-4]==' ' && board[row2-5][column2-5]==' ' && 
							 board[row2-6][column2-6]==' ')
					{	return true; }
				}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (board[row2+1][column2+2]=='N' || board[row2+2][column2+1]=='N' || board[row2-1][column2+2]=='N' || board[row2-2][column2+1]=='N' || // Check From Knight        
				    board[row2+1][column2-2]=='N' || board[row2+2][column2-1]=='N' || board[row2-1][column2-2]=='N' || board[row2-2][column2-1]=='N')
				{	return true; }
				if (board[row2+1][column2-1]=='P' || board[row2+1][column2+1]=='P')                                                                     // Check From Pawn  
				{	return true; }
				if (board[row2-1][column2]=='K' || board[row2-1][column2-1]=='K' || board[row2-1][column2+1]=='K' || board[row2][column2-1]=='K' ||     // Check From King
					board[row2][column2+1]=='K' || board[row2+1][column2-1]=='K' || board[row2+1][column2]=='K' || board[row2+1][column2+1]=='K') 
				{	return true; }
				else
					return false; 
			}
		}
	}
}
bool checkmate()                                                       // Checks For Checkmate
{
	
}
bool stalemate()                                                       // Checks For Stalemate
{
	
}
Well, that a bit too much of code.

Checking for checkmate is relatively simple: You need to check whether legal draws exist that could take the kings place and all places around him.

Stalemate is similar with the exception that the kings place is not taken by the opponent.

I'd suggest that each piece has its own function whether it can take a certain field or not.
closed account (48T7M4Gy)
Adding to that, checkmate is made up of the following parts:
1. The king must be in check.
2. The king has no legal move.
3. The attacking piece(s) cannot be blocked or taken.
4. Time limit has not expired.
( 5. There is no stalemate (fairly obvious). )
i have finished of with first 2 conditions now.
my game has no time limits.

now i need help with condition 3

current progress of checkmate is
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
bool checkmate()                                                       // Checks For Checkmate
{
	int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
	if(check(turn))
	{for(row=1; row<9; row++)
	 {for(column=1; column<9; column++)
	  {
		if(turn=='X' && board[row][column]=='K')                       // Checks For Checkmate Against White
		{
			x=board[row-1][column-1]; board[row-1][column-1]='K'; board[row][column]=' '; if(check(turn))a=1; board[row-1][column-1]=x; board[row][column]='K'; // Checks For Check
			x=board[row-1][column];   board[row-1][column]='K';   board[row][column]=' '; if(check(turn))b=1; board[row-1][column]=x;   board[row][column]='K'; // Checks For Check
			x=board[row-1][column+1]; board[row-1][column+1]='K'; board[row][column]=' '; if(check(turn))c=1; board[row-1][column+1]=x; board[row][column]='K'; // Checks For Check
			x=board[row][column-1];   board[row][column-1]='K';   board[row][column]=' '; if(check(turn))d=1; board[row][column-1]=x;   board[row][column]='K'; // Checks For Check
			x=board[row][column+1];   board[row][column+1]='K';   board[row][column]=' '; if(check(turn))e=1; board[row][column+1]=x;   board[row][column]='K'; // Checks For Check
			x=board[row+1][column-1]; board[row+1][column-1]='K'; board[row][column]=' '; if(check(turn))f=1; board[row+1][column-1]=x; board[row][column]='K'; // Checks For Check
			x=board[row+1][column];   board[row+1][column]='K';   board[row][column]=' '; if(check(turn))g=1; board[row+1][column]=x;   board[row][column]='K'; // Checks For Check
			x=board[row+1][column+1]; board[row+1][column+1]='K'; board[row][column]=' '; if(check(turn))h=1; board[row+1][column+1]=x; board[row][column]='K'; // Checks For Check
			if((board[row-1][column-1]=='R' || board[row-1][column-1]=='N' || board[row-1][column-1]=='B' ||
			    board[row-1][column-1]=='Q' || board[row-1][column-1]=='P' || board[row-1][column-1]=='/' || a==1) &&
			   (board[row-1][column+1]=='R' || board[row-1][column+1]=='N' || board[row-1][column+1]=='B' ||
			    board[row-1][column+1]=='Q' || board[row-1][column+1]=='P' || board[row-1][column+1]=='/' || c==1) &&
			   (board[row-1][column]=='R'   || board[row-1][column]=='N'   || board[row-1][column]=='B'   ||
			    board[row-1][column]=='Q'   || board[row-1][column]=='P'   || board[row-1][column]=='/'   || b==1) &&
			   (board[row+1][column-1]=='R' || board[row+1][column-1]=='N' || board[row+1][column-1]=='B' ||
			    board[row+1][column-1]=='Q' || board[row+1][column-1]=='P' || board[row+1][column-1]=='/' || f==1) &&
			   (board[row+1][column+1]=='R' || board[row+1][column+1]=='N' || board[row+1][column+1]=='B' ||
			    board[row+1][column+1]=='Q' || board[row+1][column+1]=='P' || board[row+1][column+1]=='/' || h==1) &&
			   (board[row+1][column]=='R'   || board[row+1][column]=='N'   || board[row+1][column]=='B'   ||
			    board[row+1][column]=='Q'   || board[row+1][column]=='P'   || board[row+1][column]=='/'   || g==1) &&
			   (board[row][column-1]=='R'   || board[row][column-1]=='N'   || board[row][column-1]=='B'   ||
			    board[row][column-1]=='Q'   || board[row][column-1]=='P'   || board[row][column-1]=='/'   || d==1) &&
			   (board[row][column+1]=='R'   || board[row][column+1]=='N'   || board[row][column+1]=='B'   ||
			    board[row][column+1]=='Q'   || board[row][column+1]=='P'   || board[row][column+1]=='/'   || e==1))
				return true;
			else
				return false;
		}
		else if(turn=='Y' && board[row][column]=='k')                  // Checks For Checkmate Against Black
		{
			x=board[row-1][column-1]; board[row-1][column-1]='k'; board[row][column]=' '; if(check(turn))a=1; board[row-1][column-1]=x; board[row][column]='k'; // Checks For Check
			x=board[row-1][column];   board[row-1][column]='k';   board[row][column]=' '; if(check(turn))b=1; board[row-1][column]=x;   board[row][column]='k'; // Checks For Check
			x=board[row-1][column+1]; board[row-1][column+1]='k'; board[row][column]=' '; if(check(turn))c=1; board[row-1][column+1]=x; board[row][column]='k'; // Checks For Check
			x=board[row][column-1];   board[row][column-1]='k';   board[row][column]=' '; if(check(turn))d=1; board[row][column-1]=x;   board[row][column]='k'; // Checks For Check
			x=board[row][column+1];   board[row][column+1]='k';   board[row][column]=' '; if(check(turn))e=1; board[row][column+1]=x;   board[row][column]='k'; // Checks For Check
			x=board[row+1][column-1]; board[row+1][column-1]='k'; board[row][column]=' '; if(check(turn))f=1; board[row+1][column-1]=x; board[row][column]='k'; // Checks For Check
			x=board[row+1][column];   board[row+1][column]='k';   board[row][column]=' '; if(check(turn))g=1; board[row+1][column]=x;   board[row][column]='k'; // Checks For Check
			x=board[row+1][column+1]; board[row+1][column+1]='k'; board[row][column]=' '; if(check(turn))h=1; board[row+1][column+1]=x; board[row][column]='k'; // Checks For Check
			if((board[row-1][column-1]=='r' || board[row-1][column-1]=='n' || board[row-1][column-1]=='b' ||
			    board[row-1][column-1]=='q' || board[row-1][column-1]=='p' || board[row-1][column-1]=='/' || a==1) &&
			   (board[row-1][column+1]=='r' || board[row-1][column+1]=='n' || board[row-1][column+1]=='b' ||
			    board[row-1][column+1]=='q' || board[row-1][column+1]=='p' || board[row-1][column+1]=='/' || c==1) &&
			   (board[row-1][column]=='r'   || board[row-1][column]=='n'   || board[row-1][column]=='b'   ||
			    board[row-1][column]=='q'   || board[row-1][column]=='p'   || board[row-1][column]=='/'   || b==1) &&
			   (board[row+1][column-1]=='r' || board[row+1][column-1]=='n' || board[row+1][column-1]=='b' ||
			    board[row+1][column-1]=='q' || board[row+1][column-1]=='p' || board[row+1][column-1]=='/' || f==1) &&
			   (board[row+1][column+1]=='r' || board[row+1][column+1]=='n' || board[row+1][column+1]=='b' ||
			    board[row+1][column+1]=='q' || board[row+1][column+1]=='p' || board[row+1][column+1]=='/' || h==1) &&
			   (board[row+1][column]=='r'   || board[row+1][column]=='n'   || board[row+1][column]=='b'   ||
			    board[row+1][column]=='q'   || board[row+1][column]=='p'   || board[row+1][column]=='/'   || g==1) &&
			   (board[row][column-1]=='r'   || board[row][column-1]=='n'   || board[row][column-1]=='b'   ||
			    board[row][column-1]=='q'   || board[row][column-1]=='p'   || board[row][column-1]=='/'   || d==1) &&
			   (board[row][column+1]=='r'   || board[row][column+1]=='n'   || board[row][column+1]=='b'   ||
			    board[row][column+1]=='q'   || board[row][column+1]=='p'   || board[row][column+1]=='/'   || e==1))
				return true;
			else
				return false;
		}
	  }
	 }
	}
}
closed account (48T7M4Gy)
For condition 3 you need to try every piece on the side being attacked and see whether it can be positioned to block the attack line.

Time is not a major consideration and is secondary to the other conditions. :)
Last edited on
can you give me any idea on how to write that
closed account (48T7M4Gy)
Hmm, look at the attacking piece and it's line of attack to the king. Can any of your pieces move to somewhere on that line. If there is no such piece then it is checkmate according to that particular rule. Of course you have to check all the other conditions.

This condition doesn't apply to knights - they can't be blocked.
Topic archived. No new replies allowed.
Pages: 12