-
Notifications
You must be signed in to change notification settings - Fork 0
/
king.java
106 lines (105 loc) · 2.81 KB
/
king.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
import java.awt.*;
import java.util.*;
class king extends goti
{
boolean castlable;
CastleProperty cp;
public king(Point ubi,Color teamCol)
{
super(goti.raja,ubi,teamCol);
castlable=true;
this.cp=null;
if(teamCol.equals(goti.colWhit))
FENvalue='K';
else
FENvalue='k';
value=650;
}
@Override
public stepstaken movedTo(Point p)
{
stepstaken steps=new stepstaken(this);
steps.setPrevBoardLoc(this.getLocation());
if(this.lop.containsKey(p))
{
goti already=gotiAt(p);
CastleProperty c;
if((c=this.getCastleProperty())!=null && c.isValid()==true)
{
Object[] cpset=c.getCastlePropertySet(p);
if(cpset[0].equals(p))
{
rook r=(rook)cpset[2];
steps.castlecontent=new Object[]{r,r.getLocation()};
r.setLocation((Point)cpset[1]);
}
this.removeCastleProperty();
}
if(already!=null)
{
already.killed(this);
goti.halfmovecount=0;
steps.killed(already);
}
else
{
goti.halfmovecount++;
}
this.setLocation(p);
if(this.teamCol.equals(goti.colWhit))
{
if(steps.prevloc.equals(new Point(4,0)))
{
whitecastlableQ='-';
whitecastlableK='-';
}
}
else
{
if(steps.prevloc.equals(new Point(4,7)))
{
blackcastlableq='-';
blackcastlablek='-';
}
}
this.castlable=false;
steps.movedTo(this.getLocation());
callbackparent(steps);
}
else
{
//turn was flop
steps.state(false);
}
this.lop=null;
return steps;
}
public void setCastleProperty(CastleProperty k)
{
this.cp=k;
}
public void removeCastleProperty()
{
this.cp=null;
}
public CastleProperty getCastleProperty()
{
return this.cp;
}
ArrayList<Point> possibleLocations()
{
Point currL=this.getLocation();
int x=(int)currL.getX();
int y=(int)currL.getY();
ArrayList<Point> l=new ArrayList<Point>();
l.add(new Point(x+1,y));
l.add(new Point(x+1,y+1));
l.add(new Point(x,y+1));
l.add(new Point(x-1,y+1));
l.add(new Point(x-1,y));
l.add(new Point(x-1,y-1));
l.add(new Point(x,y-1));
l.add(new Point(x+1,y-1));
return l;
}
}