-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.java
145 lines (125 loc) · 4.78 KB
/
Board.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
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
public class Board {
private Item[][] Taslar = new Item[8][8];
public Board() {
setBoard();
}
public Item[][] getTaslar(){
return Taslar;
}
public int moveTo(int fromX, int fromY, int toX, int toY){
Item tempItem = Taslar[toX][toY];
Taslar[toX][toY] = Taslar[fromX][fromY];
Taslar[fromX][fromY] = null;
if(tempItem != null)
return tempItem.getPoint();
return 0;
}
public void setBoard() {
for (int i = 0; i < 8; i = i + 7) {
for (int j = 0; j < 8; j++) {
if (i == 0)
Taslar[i][j] = new Piyon(0);
else
Taslar[i][j] = new Piyon(1);
}
}
Taslar[1][0] = new Kale(0);
Taslar[1][7] = new Kale(0);
Taslar[6][0] = new Kale(1);
Taslar[6][7] = new Kale(1);
Taslar[1][1] = new At(0);
Taslar[1][6] = new At(0);
Taslar[6][1] = new At(1);
Taslar[6][6] = new At(1);
Taslar[1][2] = new Fil(0);
Taslar[1][5] = new Fil(0);
Taslar[6][2] = new Fil(1);
Taslar[6][5] = new Fil(1);
Taslar[1][3] = new Vezir(0);
Taslar[6][3] = new Vezir(1);
Taslar[1][4] = new Sah(0);
Taslar[6][4] = new Sah(1);
}
public void displayBoard() {
System.out.println(" 1 2 3 4 5 6 7 8");
for (int xBoard = 0; xBoard < 8; xBoard++) {
System.out.print((char)(xBoard + 97)+" ");
for (int yBoard = 0; yBoard < 8; yBoard++) {
if (Taslar[xBoard][yBoard] == null)
System.out.print("- ");
else {
if (Taslar[xBoard][yBoard] instanceof Piyon) {
Piyon p = (Piyon) Taslar[xBoard][yBoard];
if (p.getColorNo() == 0)
System.out.print("P ");
else
System.out.print("p ");
} else if (Taslar[xBoard][yBoard] instanceof At) {
At p = (At) Taslar[xBoard][yBoard];
if (p.getColorNo() == 0)
System.out.print("A ");
else
System.out.print("a ");
} else if (Taslar[xBoard][yBoard] instanceof Vezir) {
Vezir p = (Vezir) Taslar[xBoard][yBoard];
if (p.getColorNo() == 0)
System.out.print("V ");
else
System.out.print("v ");
} else if (Taslar[xBoard][yBoard] instanceof Sah) {
Sah p = (Sah) Taslar[xBoard][yBoard];
if (p.getColorNo() == 0)
System.out.print("S ");
else
System.out.print("s ");
} else if (Taslar[xBoard][yBoard] instanceof Kale) {
Kale p = (Kale) Taslar[xBoard][yBoard];
if (p.getColorNo() == 0)
System.out.print("K ");
else
System.out.print("k ");
} else if (Taslar[xBoard][yBoard] instanceof Fil) {
Fil p = (Fil) Taslar[xBoard][yBoard];
if (p.getColorNo() == 0)
System.out.print("F ");
else
System.out.print("f ");
} else
System.out.print("x ");
}
}
System.out.println();
}
}
public boolean isPlayable(int fromX,int fromY,int toX,int toY,int turn){
if(Taslar[fromX][fromY]==null || Taslar[fromX][fromY].getColorNo() != turn)
return false;
if(Taslar[toX][toY]!=null && Taslar[toX][toY].getColorNo() == turn )
return false;
if(outOfBounds(toX, toY))
return false;
if(!Taslar[fromX][fromY].isPlayable( fromX, fromY, toX, toY, Taslar))
return false;
return true;
}
public boolean outOfBounds(int toX, int toY) {
if (toX < 8 && toX >= 0 &&
toY < 8 && toY >= 0)
return false;
return true;
}
public boolean isEmpty(int toX, int toY) {
if (Taslar[toX][toY] == null)
return true;
return false;
}
public void tabloyuSolaKaydir(){
Item[][] tempTaslar = new Item[8][8];
for(int i = 0; i < 8 ; i++){
for(int j = 0; j < 8 ; j++){
tempTaslar[i][j] = Taslar[i][(j+1)%8];
}
}
Taslar = tempTaslar;
}
}