-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhorse2
More file actions
40 lines (34 loc) · 1.47 KB
/
horse2
File metadata and controls
40 lines (34 loc) · 1.47 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
String[] x = {"1", "2", "3", "4", "5", "6", "7", "8"};
String[] y = {"A", "B", "C", "D", "E", "F", "G", "H"};
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
String[] values = input.split("-");
if ((input.length() != 5) || (input.charAt(2) != '-')) {
System.out.println("ERROR input");
}
int positionX1 = 0, positionY1 = 0;
int positionX2 = 0, positionY2 = 0;
int position1 = 0, position2 = 0;
int z[] = {6, -6, 10, -10, 15, -15, 17, -17};
int answer = 0;
for (int i = 0; i < 8; i++) {
if (values[0].contains(y[i])) positionY1 = i + 1;
if (values[1].contains(y[i])) positionY2 = i + 1;
if (values[0].contains(x[i])) positionX1 = i + 1;
if (values[1].contains(x[i])) positionX2 = i + 1;
position1 = (positionY1 * 8) - (8 - positionX1);
position2 = (positionY2 * 8) - (8 - positionX2);
}
for (int i = 0; i < 8; i++) {
if (position1 - position2 == z[i]) answer++;
if (position2 - position1 == z[i]) answer++;
}
if (answer == 2) System.out.println("Move correct");
else System.out.println("Move invalid");
}
}