You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.9 KiB
74 lines
1.9 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
char** Schachbrett_erstellen() {
|
|
|
|
int R = 8; //Reihen
|
|
int Z = 8; //zeilen
|
|
|
|
//Dynamisch Platz zuweisen für schachbrett
|
|
char** Brett = (char**)malloc(R * sizeof(char*));
|
|
|
|
if (Brett == NULL) {
|
|
// Fehler bei speicherzuweißung
|
|
return NULL;
|
|
}
|
|
for (int i = 0; i < R; i++) {
|
|
Brett[i] = (char*)malloc(Z * sizeof(char));
|
|
if (Brett[i] == NULL) {
|
|
// Speicherfehlerbehbung
|
|
for (int j = 0; j < i; j++) {
|
|
free(Brett[j]);
|
|
}
|
|
free(Brett);
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
// Spielbrett befüllen, groß und kleinschreibung unterschiedlich um schwarz/weiß zu trennen
|
|
char Aufbau[8][8] = {
|
|
{ 'R' , 'N' , 'B' , 'Q' , 'K' , 'B' , 'N' , 'R' },
|
|
{ 'P' , 'P' , 'P' , 'P' , 'P' , 'P' , 'P' , 'P' },
|
|
{ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' },
|
|
{ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' },
|
|
{ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' },
|
|
{ ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' },
|
|
{ 'p' , 'p' , 'p' , 'p' , 'p' , 'p' , 'p' , 'p' },
|
|
{ 'r' , 'n' , 'b' , 'q' , 'k' , 'b' , 'n' , 'r' }
|
|
};
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
for (int j = 0; j < 8; j++) {
|
|
Brett[i][j] = Aufbau[i][j];
|
|
}
|
|
}
|
|
|
|
return Brett;
|
|
}
|
|
|
|
void print_Schachfeld(char** Brett) {
|
|
int counter = 1;
|
|
printf(" - 1 2 3 4 5 6 7 8 \n");
|
|
for (int i = 0; i < 8; i++) {
|
|
printf(" %d " , counter);
|
|
counter++;
|
|
for (int j = 0; j < 8; j++) {
|
|
printf(" %c ", Brett[i][j]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
printf("\n");
|
|
printf("\n");
|
|
}
|
|
|
|
void Schachbrettspeicher_freigeben(char** Brett) {
|
|
if (Brett == NULL) {
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
free(Brett[i]);
|
|
}
|
|
|
|
free(Brett);
|
|
}
|