author | Markus Bröker <mbroeker@largo.homelinux.org> |
Sun, 10 May 2009 16:04:42 +0200 | |
changeset 7 | 93fe1f21e0d8 |
parent 5 | 42da09368d71 |
child 11 | 1afe167876fb |
permissions | -rw-r--r-- |
0
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
1 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
2 |
* $Id: ChessBoard.java 152 2008-04-27 02:04:31Z mbroeker $ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
3 |
* $URL: http://localhost/svn/eclipse/Schachspiel/trunk/org/homelinux/largo/games/board/chessboard/ChessBoard.java $ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
4 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
5 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
6 |
package org.homelinux.largo.games.board.chessboard; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
7 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
8 |
import java.awt.Image; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
9 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
10 |
import org.homelinux.largo.games.board.Board; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
11 |
import org.homelinux.largo.games.board.Piece; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
12 |
import org.homelinux.largo.utils.ImgComponent; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
13 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
14 |
public class ChessBoard extends Board { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
15 |
static final long serialVersionUID = 140208; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
16 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
17 |
static final int ROOK = 1; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
18 |
static final int KNIGHT = 2; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
19 |
static final int BISHOP = 3; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
20 |
static final int QUEEN = 4; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
21 |
static final int KING = 5; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
22 |
static final int PAWN = 6; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
23 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
24 |
final Piece white_queen = new Piece(new ImgComponent("images/white_queen.png").getImage(), |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
25 |
"white", QUEEN, 90); |
5
42da09368d71
Platform Independend Newlines
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
0
diff
changeset
|
26 |
final Piece black_queen = new Piece(new ImgComponent("images/black_queen.png").getImage(), |
0
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
27 |
"black", QUEEN, 90); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
28 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
29 |
boolean white_rochades_small; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
30 |
boolean white_rochades_big; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
31 |
boolean black_rochades_small; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
32 |
boolean black_rochades_big; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
33 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
34 |
void initBoard () { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
35 |
add (new ImgComponent ("images/black_rook.png").getImage (), 0, "black", ROOK); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
36 |
add (new ImgComponent ("images/black_knight.png").getImage (), 1, "black", KNIGHT); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
37 |
add (new ImgComponent ("images/black_bishop.png").getImage (), 2, "black", BISHOP); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
38 |
add (new ImgComponent ("images/black_queen.png").getImage (), 3, "black", QUEEN); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
39 |
add (new ImgComponent ("images/black_king.png").getImage (), 4, "black", KING); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
40 |
add (new ImgComponent ("images/black_bishop.png").getImage (), 5, "black", BISHOP); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
41 |
add (new ImgComponent ("images/black_knight.png").getImage (), 6, "black", KNIGHT); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
42 |
add (new ImgComponent ("images/black_rook.png").getImage (), 7, "black", ROOK); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
43 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
44 |
for (int i = 0; i < 8; i++) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
45 |
add (new ImgComponent ("images/black_pawn.png").getImage (), 8 + i, "black", PAWN); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
46 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
47 |
add (new ImgComponent ("images/white_rook.png").getImage (), 56, "white", ROOK); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
48 |
add (new ImgComponent ("images/white_knight.png").getImage (), 57, "white", KNIGHT); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
49 |
add (new ImgComponent ("images/white_bishop.png").getImage (), 58, "white", BISHOP); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
50 |
add (new ImgComponent ("images/white_queen.png").getImage (), 59, "white", QUEEN); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
51 |
add (new ImgComponent ("images/white_king.png").getImage (), 60, "white", KING); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
52 |
add (new ImgComponent ("images/white_bishop.png").getImage (), 61, "white", BISHOP); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
53 |
add (new ImgComponent ("images/white_knight.png").getImage (), 62, "white", KNIGHT); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
54 |
add (new ImgComponent ("images/white_rook.png").getImage (), 63, "white", ROOK); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
55 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
56 |
for (int i = 0; i < 8; i++) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
57 |
add (new ImgComponent ("images/white_pawn.png").getImage (), 55 - i, "white", PAWN); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
58 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
59 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
60 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
61 |
* The init method initializes a complete chess board with figures and a history. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
62 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
63 |
public void init() { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
64 |
super.init(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
65 |
initBoard(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
66 |
board_pieces = getPieces(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
67 |
repaint(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
68 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
69 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
70 |
public ChessBoard (int w, int h) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
71 |
super(w, h); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
72 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
73 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
74 |
void add (Image img, int i, String c, int t) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
75 |
int v = 0; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
76 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
77 |
switch (t) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
78 |
case ROOK: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
79 |
v = 40; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
80 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
81 |
case KNIGHT: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
82 |
v = 30; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
83 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
84 |
case BISHOP: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
85 |
v = 30; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
86 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
87 |
case QUEEN: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
88 |
v = 90; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
89 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
90 |
case KING: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
91 |
v = 500; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
92 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
93 |
case PAWN: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
94 |
v = 10; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
95 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
96 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
97 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
98 |
setPiece(i, new Piece(img, c, t, v)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
99 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
100 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
101 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
102 |
* returns true, when the white king is at pieces[i] |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
103 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
104 |
public boolean isWhiteKing(int i) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
105 |
if ( isWhite(i) && getType(i) == KING) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
106 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
107 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
108 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
109 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
110 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
111 |
* returns true, when the black king is at pieces[i] |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
112 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
113 |
public boolean isBlackKing(int i) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
114 |
if ( isBlack(i) && getType(i) == KING) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
115 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
116 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
117 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
118 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
119 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
120 |
* Returns the score of the current position |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
121 |
* Every field controlled by [color] gives one point |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
122 |
* A King, controlled by [color], gives 10 extra points |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
123 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
124 |
public int controls(String color) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
125 |
int t, o; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
126 |
int value = 0; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
127 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
128 |
for ( o=0;o<64;o++) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
129 |
if (color.equals(getColor(o))) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
130 |
for (t=0;t<64;t++) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
131 |
if(validMove(t, o)) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
132 |
if ( getType(t) == KING ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
133 |
value+=10; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
134 |
value++; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
135 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
136 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
137 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
138 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
139 |
return value; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
140 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
141 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
142 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
143 |
* Checks, wether this move is possible or not. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
144 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
145 |
public boolean validMove (int t, int o) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
146 |
int steps; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
147 |
int rows; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
148 |
int dx; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
149 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
150 |
/* Must be here */ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
151 |
white_rochades_small = false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
152 |
white_rochades_big = false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
153 |
black_rochades_small = false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
154 |
black_rochades_big = false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
155 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
156 |
if ( t == o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
157 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
158 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
159 |
if (isSamePiece(t, o)) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
160 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
161 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
162 |
if (getType(o) == EMPTY) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
163 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
164 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
165 |
/* |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
166 |
* 00 01 02 03 04 05 06 07 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
167 |
* 08 09 10 11 12 13 14 15 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
168 |
* 16 17 18 19 20 21 22 23 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
169 |
* 24 25 26 27 28 29 30 31 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
170 |
* 32 33 34 35 36 37 38 39 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
171 |
* 40 41 42 43 44 45 46 47 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
172 |
* 48 49 50 51 52 53 54 55 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
173 |
* 56 57 58 59 60 61 62 63 |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
174 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
175 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
176 |
steps = Math.abs(t-o); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
177 |
rows = Math.abs(t/8 - o/8); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
178 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
179 |
switch( getType(o) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
180 |
case ROOK: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
181 |
if (steps < 8 && rows == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
182 |
if(t>o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
183 |
for ( dx = o+1; dx < t; dx++ ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
184 |
if ( getColor(dx) != null ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
185 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
186 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
187 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
188 |
else |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
189 |
for ( dx = o-1; dx > t; dx-- ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
190 |
if ( getColor(dx) != null ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
191 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
192 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
193 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
194 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
195 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
196 |
if (steps % 8 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
197 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
198 |
for ( dx = o+8; dx < t; dx+=8 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
199 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
200 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
201 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
202 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
203 |
for ( dx = o-8; dx > t; dx-=8 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
204 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
205 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
206 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
207 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
208 |
if (steps == 8 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
209 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
210 |
if (steps == 16 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
211 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
212 |
if (steps == 24 && rows == 3) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
213 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
214 |
if (steps == 32 && rows == 4) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
215 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
216 |
if (steps == 40 && rows == 5) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
217 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
218 |
if (steps == 48 && rows == 6) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
219 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
220 |
if (steps == 56 && rows == 7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
221 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
222 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
223 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
224 |
case KNIGHT: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
225 |
/* works fine */ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
226 |
if (steps == 6 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
227 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
228 |
if (steps == 10 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
229 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
230 |
if (steps == 15 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
231 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
232 |
if (steps == 17 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
233 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
234 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
235 |
case BISHOP: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
236 |
if (steps % 7 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
237 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
238 |
for ( dx = o+7; dx < t; dx+=7 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
239 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
240 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
241 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
242 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
243 |
for ( dx = o-7; dx > t; dx-=7 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
244 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
245 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
246 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
247 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
248 |
if (steps == 7 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
249 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
250 |
if (steps == 14 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
251 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
252 |
if (steps == 21 && rows == 3) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
253 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
254 |
if (steps == 28 && rows == 4) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
255 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
256 |
if (steps == 35 && rows == 5) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
257 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
258 |
if (steps == 42 && rows == 6) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
259 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
260 |
if (steps == 49 && rows == 7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
261 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
262 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
263 |
if (steps % 9 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
264 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
265 |
for ( dx = o+9; dx < t; dx+=9 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
266 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
267 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
268 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
269 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
270 |
for ( dx = o-9; dx > t; dx-=9 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
271 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
272 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
273 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
274 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
275 |
if (steps == 9 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
276 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
277 |
if (steps == 18 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
278 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
279 |
if (steps == 27 && rows == 3) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
280 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
281 |
if (steps == 36 && rows == 4) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
282 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
283 |
if (steps == 45 && rows == 5) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
284 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
285 |
if (steps == 54 && rows == 6) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
286 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
287 |
if (steps == 63 && rows == 7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
288 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
289 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
290 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
291 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
292 |
case QUEEN: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
293 |
if (steps < 8 && rows == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
294 |
if(t>o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
295 |
for ( dx = o+1; dx < t; dx++ ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
296 |
if ( getColor(dx) != null ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
297 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
298 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
299 |
else |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
300 |
for ( dx = o-1; dx > t; dx-- ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
301 |
if ( getColor(dx) != null ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
302 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
303 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
304 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
305 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
306 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
307 |
if (steps % 8 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
308 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
309 |
for ( dx = o+8; dx < t; dx+=8 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
310 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
311 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
312 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
313 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
314 |
for ( dx = o-8; dx > t; dx-=8 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
315 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
316 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
317 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
318 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
319 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
320 |
if (steps == 8 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
321 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
322 |
if (steps == 16 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
323 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
324 |
if (steps == 24 && rows == 3) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
325 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
326 |
if (steps == 32 && rows == 4) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
327 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
328 |
if (steps == 40 && rows == 5) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
329 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
330 |
if (steps == 48 && rows == 6) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
331 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
332 |
if (steps == 56 && rows == 7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
333 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
334 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
335 |
if (steps % 7 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
336 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
337 |
for ( dx = o+7; dx < t; dx+=7 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
338 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
339 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
340 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
341 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
342 |
for ( dx = o-7; dx > t; dx-=7 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
343 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
344 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
345 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
346 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
347 |
if (steps == 7 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
348 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
349 |
if (steps == 14 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
350 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
351 |
if (steps == 21 && rows == 3) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
352 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
353 |
if (steps == 28 && rows == 4) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
354 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
355 |
if (steps == 35 && rows == 5) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
356 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
357 |
if (steps == 42 && rows == 6) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
358 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
359 |
if (steps == 49 && rows == 7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
360 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
361 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
362 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
363 |
if (steps % 9 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
364 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
365 |
for ( dx = o+9; dx < t; dx+=9 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
366 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
367 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
368 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
369 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
370 |
for ( dx = o-9; dx > t; dx -=9 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
371 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
372 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
373 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
374 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
375 |
if (steps == 9 && rows == 1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
376 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
377 |
if (steps == 18 && rows == 2) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
378 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
379 |
if (steps == 27 && rows == 3) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
380 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
381 |
if (steps == 36 && rows == 4) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
382 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
383 |
if (steps == 45 && rows == 5) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
384 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
385 |
if (steps == 54 && rows == 6) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
386 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
387 |
if (steps == 63 && rows == 7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
388 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
389 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
390 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
391 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
392 |
case KING: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
393 |
if ( (steps == 1) && (rows == 0) ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
394 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
395 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
396 |
if ( (steps == 8) && (rows == 1) ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
397 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
398 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
399 |
if ( (steps == 7) && (rows == 1) ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
400 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
401 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
402 |
if ( (steps == 9) && (rows == 1) ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
403 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
404 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
405 |
if ( (steps == 2) && (rows == 0) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
406 |
if ( isWhiteKing(o) ) { /* White: Rochade */ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
407 |
if ( isWhiteKing(60) && isEmpty(61) && isEmpty(62) && (t==62) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
408 |
if ( (getType(63) == ROOK) && isWhite(63) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
409 |
white_rochades_small = true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
410 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
411 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
412 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
413 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
414 |
if ( isWhiteKing(60) && isEmpty(59) && isEmpty(58) && isEmpty(57) && (t==58) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
415 |
if ( (getType(56) == ROOK) && isWhite(56) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
416 |
white_rochades_big = true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
417 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
418 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
419 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
420 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
421 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
422 |
if ( isBlackKing(o) ) { /* Black: Rochade */ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
423 |
if ( isBlackKing(4) && isEmpty(5) && isEmpty(6) && (t==6) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
424 |
if ( (getType(7) == ROOK) && isBlack(7) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
425 |
black_rochades_small = true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
426 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
427 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
428 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
429 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
430 |
if ( isBlackKing(4) && isEmpty(3) && isEmpty(2) && isEmpty(1) && (t==2) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
431 |
if ( (getType(0) == ROOK) && isBlack(0) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
432 |
black_rochades_big = true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
433 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
434 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
435 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
436 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
437 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
438 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
439 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
440 |
case PAWN: |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
441 |
if (getColor(o).equals("white")) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
442 |
if (steps == 7 && rows == 1 && isEnemy(t, o) && t<o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
443 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
444 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
445 |
if (steps == 9 && rows == 1 && isEnemy(t, o) && t<o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
446 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
447 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
448 |
if (steps == 7 && rows == 1 && isEnemy(t, o) && t>o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
449 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
450 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
451 |
if (steps == 9 && rows == 1 && isEnemy(t, o) && t>o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
452 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
453 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
454 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
455 |
if (steps % 8 == 0 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
456 |
if ( t>o ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
457 |
for ( dx = o+8; dx <= t; dx+=8 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
458 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
459 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
460 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
461 |
} else { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
462 |
for ( dx = o-8; dx >= t; dx-=8 ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
463 |
if (getColor(dx) != null) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
464 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
465 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
466 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
467 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
468 |
if (steps == 8 && rows == 1) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
469 |
if ( getColor(o).equals("white") && t < o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
470 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
471 |
if ( getColor(o).equals("black") && t > o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
472 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
473 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
474 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
475 |
if (steps == 16 && rows == 2 && (o>= 8 && o <=15) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
476 |
if ( getColor(o).equals("white") && t < o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
477 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
478 |
if ( getColor(o).equals("black") && t > o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
479 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
480 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
481 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
482 |
if (steps == 16 && rows == 2 && (o>=48 && o <=55) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
483 |
if ( getColor(o).equals("white") && t < o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
484 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
485 |
if ( getColor(o).equals("black") && t > o ) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
486 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
487 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
488 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
489 |
break; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
490 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
491 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
492 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
493 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
494 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
495 |
* This method must be called immediately after isValidMove(t, o) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
496 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
497 |
boolean rochade() { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
498 |
if (white_rochades_small) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
499 |
setPiece(61, getPiece(63)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
500 |
setPiece(63, new Piece(null, null, EMPTY, 0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
501 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
502 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
503 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
504 |
if (white_rochades_big) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
505 |
setPiece(59, getPiece(56)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
506 |
setPiece(56, new Piece(null, null, EMPTY, 0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
507 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
508 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
509 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
510 |
if (black_rochades_small) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
511 |
setPiece(5, getPiece(7)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
512 |
setPiece(7, new Piece(null, null, EMPTY, 0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
513 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
514 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
515 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
516 |
if (black_rochades_big) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
517 |
setPiece(3, getPiece(0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
518 |
setPiece(0, new Piece(null, null, EMPTY, 0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
519 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
520 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
521 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
522 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
523 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
524 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
525 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
526 |
* checks, whether color is in check or not. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
527 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
528 |
public boolean isCheck(String color) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
529 |
int i; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
530 |
int wking; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
531 |
int bking; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
532 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
533 |
wking = bking = -1; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
534 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
535 |
for (i=0;i<64;i++) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
536 |
if (isWhiteKing(i)) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
537 |
wking = i; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
538 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
539 |
if (isBlackKing(i)) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
540 |
bking = i; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
541 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
542 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
543 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
544 |
// returns 64 false positives |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
545 |
if (wking == -1 || bking == -1) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
546 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
547 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
548 |
if (color.equals("white")) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
549 |
for (i=0;i<64;i++) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
550 |
if (validMove(wking, i)) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
551 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
552 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
553 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
554 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
555 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
556 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
557 |
if (color.equals("black")) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
558 |
for (i=0;i<64;i++) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
559 |
if (validMove(bking, i)) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
560 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
561 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
562 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
563 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
564 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
565 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
566 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
567 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
568 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
569 |
* simulates a "valid" move or returns false. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
570 |
* all changes are relative to pieces and will not be painted. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
571 |
* This method sets internal variables for the rochade() method, which will be overwritten. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
572 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
573 |
public boolean simulateMove(int t, int o) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
574 |
if ( !validMove(t, o) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
575 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
576 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
577 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
578 |
push(getPiece(t), t, getPiece(o), o); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
579 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
580 |
if ( getType(o) == PAWN ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
581 |
if(isBlack(o) && t >=56) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
582 |
setPiece(o, new Piece(black_queen)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
583 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
584 |
if(isWhite(o) && t <=7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
585 |
setPiece(o, new Piece(white_queen)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
586 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
587 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
588 |
setPiece(t, new Piece(getPiece(o))); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
589 |
setPiece(o, new Piece(null, null, EMPTY, 0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
590 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
591 |
if (isCheck(getColor(t))) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
592 |
/* restore current position */ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
593 |
if(UNDO_DEBUG) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
594 |
print("UNDO", t, o, 0); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
595 |
undo(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
596 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
597 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
598 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
599 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
600 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
601 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
602 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
603 |
* performs a "valid" move or returns false. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
604 |
* all changes are relative to board_pieces and will be painted. |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
605 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
606 |
public boolean doMove(int t, int o) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
607 |
if ( !validMove(t, o) ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
608 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
609 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
610 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
611 |
push(getPiece(t), t, getPiece(o), o); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
612 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
613 |
if ( getType(o) == PAWN ) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
614 |
if(isBlack(o) && t >=56) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
615 |
setPiece(o, new Piece(black_queen)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
616 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
617 |
if(isWhite(o) && t <=7) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
618 |
setPiece(o, new Piece(white_queen)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
619 |
} |
5
42da09368d71
Platform Independend Newlines
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
0
diff
changeset
|
620 |
|
0
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
621 |
setPiece(t, new Piece(getPiece(o))); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
622 |
setPiece(o, new Piece(null, null, EMPTY, 0)); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
623 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
624 |
if (rochade()) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
625 |
System.out.println("Rochade"); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
626 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
627 |
if (isCheck(getColor(t))) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
628 |
// restore current positions |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
629 |
if(UNDO_DEBUG) |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
630 |
print("UNDO", t, o, 0); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
631 |
undo(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
632 |
return false; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
633 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
634 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
635 |
board_pieces = getPieces(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
636 |
repaint(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
637 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
638 |
moveNr = stack.size(); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
639 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
640 |
return true; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
641 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
642 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
643 |
/** |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
644 |
* converts the internal representation into normal chess notation and writes it to stdout |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
645 |
*/ |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
646 |
public void print(String s, int t, int o, int value) { |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
647 |
int row1, col1, row2, col2; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
648 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
649 |
row1 = o/8; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
650 |
col1 = o-(8*row1); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
651 |
|
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
652 |
row2 = t/8; |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
653 |
col2 = t-(8*row2); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
654 |
|
5
42da09368d71
Platform Independend Newlines
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
0
diff
changeset
|
655 |
System.out.printf("%s: %C%d-%c%d = %3d%n", s, |
0
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
656 |
('A')+col1, 8-row1, |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
657 |
('A')+col2, 8-row2, value); |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
658 |
} |
e0dbaef72362
svn copy of the chess engine
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff
changeset
|
659 |
} |