-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrook.java
More file actions
105 lines (100 loc) · 2.14 KB
/
rook.java
File metadata and controls
105 lines (100 loc) · 2.14 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
public class rook extends piece
{
rook(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];
if(row!=r && colm!=c)
return 0;
int row_i =r,colm_i =c;
while(row_i!= row)
{
if(row>r)
row_i++;
else
row_i--;
if(row_i!= row)
{
if(board.pic[row_i][colm].status== true)
return 0;
}
else
{
if(board.pic[row_i][colm].status== false)
return 1;
else
return 2;
}
}
while(colm_i!= colm)
{
if(colm>c)
colm_i++;
else
colm_i--;
if(colm_i!= colm)
{
if(board.pic[row][colm_i].status== true)
return 0;
}
else
{
if(board.pic[row][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;
}
}