-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveDiagonal.java
More file actions
106 lines (76 loc) · 2.99 KB
/
MoveDiagonal.java
File metadata and controls
106 lines (76 loc) · 2.99 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
// Nathan Hsiao
// this class checks if a move is Diagoanl
public interface MoveDiagonal{
// this method checks if the move is diagonal
public static boolean checkDiagonal( ChessPiece piece, int column, int row){
// this variable finds change in column
int newColumn = column - piece.getColumn();
// this variable finds the change in row
int newRow = row - piece.getRow();
// this variable finds the slope and sees if it is a whole number
double slope = (newColumn/ newRow);
// this if statement checks if the slope is a whole number
if ( slope % 1 == 0){
return true;
}
else
return false;
}
public static boolean checkDiagonal1(ChessPiece piece, int column, int row){
// this variable finds change in column
int newColumn = column - piece.getColumn();
// this variable finds the change in row
int newRow = row - piece.getRow();
// this variable finds the slope and sees if it is a whole number
double line = (newColumn/ newRow);
// this if statement checks if the slope is a whole number
if ( line % 1 == 0 && (line >0 || line <0)){
return true;
}
else
return false;
}
public static boolean checkDiagonalPiece(ChessPiece piece, int column, int row){
// this variable finds change in column
int newColumn = column - piece.getColumn();
// this variable finds the change in row
int newRow = row - piece.getRow();
// this variable finds the slope and sees if it is a whole number
double line = (newColumn/ newRow);
// this if statement checks if the slope is a whole number to see if it is on the same diagonal
//if ( line % 1 == 0 && (line >0 || line <0 )){
// loop checks if move northeast
for ( int i = piece.getColumn() +1 , b = piece.getRow()+1; i <= column && b <= row; i ++, b++){
if (piece.getChessBoard().hasPiece(b, i)){
return true;
}
else
return false;
}
// loop checks is move southeast
for ( int i = piece.getColumn() +1 , b = piece.getRow() -1 ; i <= column && b >= row; i ++, b--){
if (piece.getChessBoard().hasPiece(b, i)){
return true;
}
else
return false;
}
// loop checks if move south west
for ( int i = piece.getColumn() -1 , b = piece.getRow() -1 ; i >= column && b >= row; i --, b--){
if (piece.getChessBoard().hasPiece(b, i)){
return true;
}
else
return false;
}
// loop checks if move is northwest
for ( int i = piece.getColumn() -1, b = piece.getRow()+1; i <=column && b>=row; i--, b++){
if (piece.getChessBoard().hasPiece(b, i)){
return true;
}
else
return false;
}
return false;
}
}