| 2 | 1 | 1 | 0 | 0 | 2 | 2 |
| 1 | 1 | 2 | 0 | 2 | 1 | 2 |
| 2 | 2 | 2 | 1 | 2 | 1 | 1 |
| 1 | 2 | 1 | 2 | 1 | 1 | 2 |
| 2 | 1 | 2 | 1 | 1 | 2 | 2 |
| 1 | 1 | 2 | 2 | 1 | 1 | 2 |
Oben stehendes Drei(!) Gewinnt-Spielfeld ist in folgendem Programmcode enthalten:
public class DreiGewinnt {
static int[][] feld = new int[7][6];
static int gewonnen() {
for (int y = 0; y <= 5; y++) {
for (int x = 0; x <= 4; x++) {
int s = feld[x][y];
if (s != 0 && s == feld[x + 1][y] && s == feld[x + 2][y]) {
return s;
}
}
}
return 0;
};
public static void main(String[] args) {
String[] zeile = new String[6];
zeile[5]="2110022";
zeile[4]="1120212";
zeile[3]="2221211";
zeile[2]="1212112";
zeile[1]="2121122";
zeile[0]="1122112";
for (int y = 0; y <= 5; y++) {
for (int x = 0; x <= 6; x++) {
if (zeile[y].charAt(x) == '0') {
feld[x][y] = 0;
}
if (zeile[y].charAt(x) == '1') {
feld[x][y] = 1;
}
if (zeile[y].charAt(x) == '2') {
feld[x][y] = 2;
}
}
}
System.out.println(gewonnen());
}
}1 ausgegeben
wird?gewonnen() im Rahmen
des Spiels Drei Gewinnt?2 ist.main-Methode das Spielfeld so, dass
die Ausgabe
1 oder0 ist.1110222 lautet. Erkläre anhand des Programmcodes,
warum die Ausgabe bei 2 bleibt.gewonnen() so, dass aus diesem
Drei Gewinnt ein (übliches) Vier Gewinnt wird.gewonnen() eine so genannte
Vertikalprüfung hinzu. Das heißt, dass auch Vierer in einer
Spalte erkannt werden sollen.