-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElephant.cpp
More file actions
110 lines (103 loc) · 2.29 KB
/
Elephant.cpp
File metadata and controls
110 lines (103 loc) · 2.29 KB
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
#include "Elephant.h"
#include <iostream>
#include <conio.h>
using namespace std;
int error1Elephant = 0;
int error2Elephant = 0;
int Elephant::move(int board[8][8]) {
if (abs(startI - endI) == abs(startJ - endJ)) {
error1Elephant = checkShahMove(board, number, endI, endJ, startI, startJ, 1);
if (error1Elephant == 1) {
return error1Elephant;
}
if (error1Elephant == 0) {
error1Elephant = check(board);
if (error1Elephant == 1) {
return error1Elephant;
}
board[endI][endJ] = number;
if (startI % 2 != 0) {
if (startJ % 2 == 0) {
board[startI][startJ] = -1;//êëåòêè ïîëÿ
}
else {
board[startI][startJ] = 1;
}
}
else {
if (startJ % 2 != 0) {
board[startI][startJ] = -1;
}
else {
board[startI][startJ] = 1;
}
}
return error1Elephant;
}
else {
return error1Elephant;
}
}
else {
error1Elephant = 1;
return error1Elephant;
}
}
int Elephant::check(int board[8][8]) {
int startY = 0;
int endY = 0;
int startX = 0;
int endX = 0;
if (endI >= startI && endJ >= startJ) {//èäåò âíèç âïðàâî
while (startY < endI && startX < endJ) {
startY++;
startX++;
if (board[startY][startX] != -1 && board[startY][startX] != 1) {
error2Elephant = 1;
//cout << "1 d" << endl;
//int k = _getch();
break;
}
}
}
if (endI < startI && endJ <= startJ) {//èäåò ââåðõ âëåâî
while (startY > endI && startX > endJ) {
startY--;
startX--;
if (board[startY][startX] != -1 && board[startY][startX] != 1) {
error2Elephant = 1;
//cout << "2 d" << endl;
//int k = _getch();
break;
}
}
}
if (endI >= startI && endJ < startJ) {//èäåò âíèç âëåâî
while (startY < endI && startX > endJ) {
startY++;
startX--;
if (board[startY][startX] != -1 && board[startY][startX] != 1) {
error2Elephant = 1;
//cout << "3 d" << endl;
//int k = _getch();
break;
}
}
}
if (endI < startI && endJ >= startJ) {//èäåò ââåðõ âïðàâî
while (startY > endI && startX < endJ) {
startY--;
startX++;
if (board[startY][startX] != -1 && board[startY][startX] != 1) {
error2Elephant = 1;
//cout << "4 d" << endl;
//int k = _getch();
break;
}
}
}
//cout << "Ïðîâåðêà ïî äèàãîíàëè: " << endl;
//cout << error2Queen << endl;
//int k = _getch();
return error2Elephant;
}