-
Notifications
You must be signed in to change notification settings - Fork 0
/
bishup.java
120 lines (115 loc) · 2.53 KB
/
bishup.java
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
112
113
114
115
116
117
118
119
120
public class bishup extends piece
{
bishup(int row,int colm,char c)
{
this.status=true;
this.position[0]=row;
this.position[1]=colm;
this.colour = c;
}
public int move(int row,int colm) //Return 1 when Move Successfully else 0
{
int result = check_move(row,colm);
if(result==0)
{
System.out.printf("Invalid Move, Try Another\n");
return 0;
}
else if(result==1)
{
board.store_i=board.pic[position[0]][position[1]];
board.store_f=board.pic[row][colm];
board.pic[row][colm]=board.pic[position[0]][position[1]];
board.pic[row][colm].position[0]=row;
board.pic[row][colm].position[1]=colm;
return 1;
}
else
{
board.store_i=board.pic[position[0]][position[1]];
board.store_f=board.pic[row][colm];
board.pic[row][colm].status=false;
System.out.println("Capture!!!");
board.pic[row][colm]=board.pic[position[0]][position[1]];
board.pic[row][colm].position[0]=row;
board.pic[row][colm].position[1]=colm;
return 1;
}
}
int check_move(int row,int colm)
{
if(board.pic[row][colm].status == true && board.pic[row][colm].colour == this.colour)
return 0;
int r = position[0];
int c = position[1];
int mod_r=0,mod_c=0;
mod_r = Math.abs(row-r);
mod_c = Math.abs(colm-c);
if(mod_r != mod_c)
return 0;
int row_i =r,colm_i =c;
while(((row-r)>0 && (colm-c)>0) || ((row-r)<0 && (colm-c)<0))
{
if((row-r)>0 && (colm-c)>0)
{
row_i++;
colm_i++;
}
else if((row-r)<0 && (colm-c)<0)
{
row_i--;
colm_i--;
}
if(row_i!=row && colm_i!=colm)
{
if(board.pic[row_i][colm_i].status== true)
return 0;
}
else
{
if(board.pic[row_i][colm_i].status== false)
return 1;
else
return 2;
}
}
while(((row-r)>0 && (colm-c)<0) || ((row-r)<0 && (colm-c)>0))
{
if((row-r)>0 && (colm-c)<0)
{
row_i++;
colm_i--;
}
else if((row-r)<0 && (colm-c)>0)
{
row_i--;
colm_i++;
}
if(row_i!=row && colm_i!=colm)
{
if(board.pic[row_i][colm_i].status== true)
return 0;
}
else
{
if(board.pic[row_i][colm_i].status== false)
return 1;
else
return 2;
}
}
return 0;
}
public String class_name()
{
String name= this.getClass().getSimpleName();
return name;
}
public int move_check(int row,int colm) //Return 1 when Kill Successfully else 0
{
if(status==false)
return 0;
int result = check_move(row,colm);
return result;
}
}