-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpawn.java
More file actions
182 lines (178 loc) · 5.34 KB
/
pawn.java
File metadata and controls
182 lines (178 loc) · 5.34 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import java.awt.*;
import java.util.*;
class pawn extends goti
{
static Point enpassantloc=null;
static int validenpassantturn=-1;
static pawn inEnPassant=null;
static int valueOfIt=100;
public pawn(Point ubi,Color teamCol)
{
super(goti.pyada,ubi,teamCol);
if(teamCol.equals(goti.colWhit))
FENvalue='P';
else
FENvalue='p';
value=100;
}
@Override
public stepstaken movedTo(Point p)
{
stepstaken steps=new stepstaken(this);
steps.setPrevBoardLoc(this.getLocation());
if(this.lop.containsKey(p))
{
goti already=gotiAt(p);
if(already!=null)
{
already.killed(this);
steps.killed(already);
}
Point i=this.getLocation();
if(enpassantloc!=null)
{
if(enpassantloc.equals(p))
{
if(validenpassantturn==game.turnNumber)
{
inEnPassant.killed(this);
steps.killed(inEnPassant);
}
}
}
if(subject==game.pisse)
{
if(Math.abs(i.y-p.y)==2)
{
enpassantloc=new Point(i.x,(i.y+p.y)/2);
validenpassantturn=game.turnNumber+1;
inEnPassant=this;
}
else
{
enpassantloc=null;
validenpassantturn=-1;
inEnPassant=null;
}
}
goti.halfmovecount=0;
this.setLocation(p);
steps.movedTo(this.getLocation());
String send=this.promotionCheck();
steps.toNetSend(send);
callbackparent(steps);
}
else
{
//turn was flop
steps.state(false);
}
this.lop=null;
return steps;
}
public String promotionCheck()// finally returns type of goti chosen to revive and its color
{
int y=this.getLocation().y;
String got="";
if(subject!=game.pisse)
return "";
if( ((y==7 && this.teamCol.equals(goti.colWhit)) || (y==0 && this.teamCol.equals(goti.colBlak)) ) && this.statOfAct==true)
{
got=game.nowturnof.getRevivalCandidate();
if(got.equals(goti.rani))
{
subject.set(subject.indexOf(this),new queen((pawn)this));
}
if(got.equals(goti.hathi))
{
subject.set(subject.indexOf(this),new rook((pawn)this));
}
if(got.equals(goti.ghora))
{
subject.set(subject.indexOf(this),new knight((pawn)this));
}
if(got.equals(goti.mandir))
{
subject.set(subject.indexOf(this),new bishop((pawn)this));
}
}
return got;
}
ArrayList<Point> possibleLocations()
{
Point currL=this.getLocation();
int x=(int)currL.getX();
int y=(int)currL.getY();
ArrayList<Point> l=new ArrayList<Point>();
if(this.teamCol.equals(goti.colWhit))
{
if(gotiAt(new Point(x,y+1))==null)
{
l.add(new Point(x,y+1));
if( y==1 && gotiAt(new Point(x,y+2))==null )
l.add(new Point(x,y+2));
}
}
if(this.teamCol.equals(goti.colBlak))
{
if(gotiAt(new Point(x,y-1))==null)
{
l.add(new Point(x,y-1));
if( y==6 && gotiAt(new Point(x,y-2))==null )
l.add(new Point(x,y-2));
}
}
killableLox(l);
Point p=getEnPassant();
if(p!=null)
l.add(p);
return l;
}
ArrayList<Point> killableLox(ArrayList<Point> l)
{
Point currL=this.getLocation();
int x=(int)currL.getX();
int y=(int)currL.getY();
if(this.teamCol.equals(goti.colWhit))
{
goti dummy1=gotiAt(new Point(x+1,y+1));
if(dummy1!=null)
l.add(new Point(x+1,y+1));
goti dummy2=gotiAt(new Point(x-1,y+1));
if(dummy2!=null)
l.add(new Point(x-1,y+1));
}
if(this.teamCol.equals(goti.colBlak))
{
goti dummy1=gotiAt(new Point(x+1,y-1));
if(dummy1!=null)
l.add(new Point(x+1,y-1));
goti dummy2=gotiAt(new Point(x-1,y-1));
if(dummy2!=null)
l.add(new Point(x-1,y-1));
}
return l;
}
public Point getEnPassant()
{
if(validenpassantturn==game.turnNumber)
{
if(this.teamCol.equals(inEnPassant.teamCol)==false)
{
if(Math.abs(this.getLocation().x-inEnPassant.getLocation().x)==1 && this.getLocation().y==inEnPassant.getLocation().y)
{
return enpassantloc;
}
}
}
return null;
}
@Deprecated
public int getRank()
{
if(this.teamCol.equals(goti.colWhit))
return (this.getLocation().y+1);
else
return (8-this.getLocation().y);
}
}