-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathking.java
More file actions
79 lines (76 loc) · 2.07 KB
/
king.java
File metadata and controls
79 lines (76 loc) · 2.07 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
public class king extends piece
{
king(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 position_status_move = check_position_move(row,colm);
if(position_status_move== 1 && board.pic[row][colm].status == false)
return 1;
if(position_status_move == 1 && board.pic[row][colm].status == true)
return 2;
else
return 0;
}
int check_position_move(int row,int colm)
{
int r = position[0];
int c = position[1];
if((row==r+1 && colm==c-1) || (row==r+1 && colm==c) || (row==r+1 && colm==c+1))
return 1;
if((row==r-1 && colm==c-1) || (row==r-1 && colm==c) || (row==r-1 && colm==c+1))
return 1;
if((row==r && colm==c-1) || (row==r && colm==+c+1))
return 1;
else
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;
}
}