Information Technology Reference
In-Depth Information
Diese Methode erhält das Ausgangsfeld und die Zugrichtung (Distanz) als Parameter. Die
Zugrichtung gibt an, ob die Figur schräg, waagerecht oder senkrecht zieht. Dann werden
solange Züge in die Zugrichtung generiert, bis der Rand erreicht wird oder ein Hindernis
den Weg versperrt.
Eine der aufwendigen Methode ist generateMove() . Hier werden die einzelnen
Züge generiert, indem alle Schachzüge durch eine Addition oder Subtraktion ausgedrückt
werden. Der Aufruf erfolgt in den zwei Methoden newGame() und execute() . In
letzterer muss die Zugfarbe gewechselt werden, damit Weiß und Schwarz abwechselnd
ziehen können.
public void execute(int start, int end) {
board[end] = board[start];
board[start] = 0;
if (board[end] % 10 == 6) {
if (end == start + 2) { // little
board[start + 1] = board[start + 3] % 100;
board[start + 3] = 0;
graphboard[start + 1] = board[start + 1];
graphboard[start + 3] = 0;
paintBoardfield(start + 3);
paintBoardfield(start + 1);
}
if (end == start - 2) { // big
board[start - 1] = board[start - 4] % 100;
board[start - 4] = 0;
graphboard[start - 1] = board[start -1];
graphboard[start - 4] = 0;
paintBoardfield(start - 4);
paintBoardfield(start - 1);
}
}
if ((board[end] % 10 == 1) && ((end < 29) || (end > 90)))
board[end] += 4;
;
graphboard[start] = board[start];
graphboard[end] = board[end];
paintBoardfield(end);
paintBoardfield(start);
if (color == 1) {
color = 2;
th = new Thread(this);
th.setPriority(10);
th.start();
} else {
color = 1;
movecounter = 0;
deep = 0;
target = 1;
generateMove();
if (movecounter == 0) {
if (ischeck())
applet.getAppletContext().showStatus("Black ins!");
else
applet.getAppletContext().showStatus("Game draw!");
}
}
}
Search WWH ::




Custom Search