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.
133 lines
3.5 KiB
133 lines
3.5 KiB
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <ctype.h>
|
|
#include "spieler.h"
|
|
#include "Moving.h"
|
|
#include "Koenig.h"
|
|
|
|
bool GreiftBauerAn(char** Brett, int x, int y, Player player) {
|
|
// Checke für weißen Bauer
|
|
if (player == PLAYER_BLACK) {
|
|
if (y > 0 && x > 0 && Brett[y - 1][x - 1] == 'P') { // Linke Diagonale
|
|
return true;
|
|
}
|
|
if (y > 0 && x < 7 && Brett[y - 1][x + 1] == 'P') { // Rechte Diagonale
|
|
return true;
|
|
}
|
|
}
|
|
// Checke für schwarzen Bauer
|
|
if (player == PLAYER_WHITE) {
|
|
if (y < 7 && x > 0 && Brett[y + 1][x - 1] == 'p') { // Linke Diagonale
|
|
return true;
|
|
}
|
|
if (y < 7 && x < 7 && Brett[y + 1][x + 1] == 'p') { // Rechte Diagonale
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool GreiftTurmAn(char** Brett, int x, int y, Player player) {
|
|
char Turm = player == PLAYER_WHITE ? 'r' : 'R';
|
|
|
|
// Check Vertikal Hoch
|
|
for (int i = y - 1; i >= 0; i--) {
|
|
if (Brett[i][x] != ' ') {
|
|
if (Brett[i][x] == Turm) {
|
|
return true;
|
|
}
|
|
break; // Stoppt wenn irgendeine Figur gefunden wird
|
|
}
|
|
}
|
|
|
|
// Vertikal Runter
|
|
for (int i = y + 1; i < 8; i++) {
|
|
if (Brett[i][x] != ' ') {
|
|
if (Brett[i][x] == Turm) {
|
|
return true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Horizontal Links
|
|
for (int j = x - 1; j >= 0; j--) {
|
|
if (Brett[y][j] != ' ') {
|
|
if (Brett[y][j] == Turm) {
|
|
return true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Horizontal Rechts
|
|
for (int j = x + 1; j < 8; j++) {
|
|
if (Brett[y][j] != ' ') {
|
|
if (Brett[y][j] == Turm) {
|
|
return true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool GreiftSpringerAn(char** Brett, int x, int y, Player player) {
|
|
int Springerzüge[8][2] = {
|
|
{2, 1}, {1, 2}, {-1, 2}, {-2, 1},
|
|
{-2, -1}, {-1, -2}, {1, -2}, {2, -1}
|
|
};
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
int neuX = x + Springerzüge[i][0];
|
|
int neuY = y + Springerzüge[i][1];
|
|
if (neuX >= 0 && neuX < 8 && neuY >= 0 && neuY < 8) {
|
|
char Figur = Brett[neuY][neuX];
|
|
if (player == PLAYER_WHITE && Figur == 'n') {
|
|
return true;
|
|
} else if (player == PLAYER_BLACK && Figur == 'N') {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
bool istFeldUnsicher(char** Brett, int x, int y, Player player) {
|
|
|
|
if (GreiftSpringerAn(Brett, x, y, player)) {
|
|
return true;
|
|
}
|
|
if (GreiftBauerAn(Brett, x, y, player)) {
|
|
return true;
|
|
}
|
|
if (GreiftTurmAn(Brett, x, y, player)) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool istzugerlaubt_Koenig(char** Brett, int startX, int startY, int endX, int endY, Player player) {
|
|
// Schauen ob der zug auf dem Spielbrett passiert
|
|
if (endX < 0 || endX >= 8 || endY < 0 || endY >= 8)
|
|
return false;
|
|
|
|
// Berechnung des unterschieds der start und endpositionen
|
|
int dx = abs(endX - startX);
|
|
int dy = abs(endY - startY);
|
|
|
|
// Schauen ob sich nur ein feld bewegt wird
|
|
if (dx > 1 || dy > 1) return false;
|
|
|
|
// Nicht auf befreundete Figuren bewegen
|
|
char endPosition = Brett[endY][endX];
|
|
if (player == PLAYER_WHITE && isupper(endPosition))
|
|
return false;
|
|
if (player == PLAYER_BLACK && islower(endPosition))
|
|
return false;
|
|
|
|
// mehr checks noch benötigt
|
|
|
|
return true;
|
|
}
|