?
istemitz schrieb:
Hallo, vielen Dank schonmal für eure Antworten aber ich habe mich entweder missverständlich ausgedrückt oder ich bin einfach zu unfähig eure Vorschläge umzusetzen.
Was ich vergessen habe zu erwähnen, jeder Index des Feldes ist bereits mit einer Schachfigur belegt, also die Standartaufstellung. Wo sich keine Figur befindet, dort ist ja glaub eine 0 eingetragen. Ich möchte mit meiner Eingabe eigentlich nur sagen wenn "a2a3" eingetragen wird, dass sich die Figur von a2 nach a3 bewegt.
Sozusagen das a2a3 bedeutet verschiebe den Inhalt von a2(spielfeld[6][0]) auf a3(spielfeld[6][0]).
So habe ich das auch verstanden.
Ich habe eigentlich nix mit C am Hut, habe aber mal versucht meinen Gedanken weiter zu denken:
#include <stdio.h>
static const char field_str[64][2] =
{
"a8","b8","c8","d8","e8","f8","g8","h8",
"a7","b7","c7","d7","e7","f7","g7","h7",
"a6","b6","c6","d6","e6","f6","g6","h6",
"a5","b5","c5","d5","e5","f5","g5","h5",
"a4","b4","c4","d4","e4","f4","g4","h4",
"a3","b3","c3","d3","e3","f3","g3","h3",
"a2","b2","c2","d2","e2","f2","g2","h2",
"a1","b1","c1","d1","e1","f1","g1","h1"
};
int idx(const char* field){
for(int i=0; i<64;++i)
if(field[0]==field_str[i][0] && field[1]==field_str[i][1])
return i;
return -1;
}
enum piece_t{NONE,K,Q,R,B,N,P} board[64] = {
R,N,B,Q,K,B,N,R,
P,P,P,P,P,P,P,P,
[64-16]=
P,P,P,P,P,P,P,P,
R,N,B,K,Q,B,N,R
};
void print(){
static const char* piece_str[] = { [NONE]=" ", [K]="K", [Q]="Q", [R]="R", [B]="B", [N]="N", [P]="P" };
for(int rank=0; rank<8; ++rank)
printf("%s %s %s %s %s %s %s %s\n",
piece_str[board[rank*8+0]], piece_str[board[rank*8+1]],
piece_str[board[rank*8+2]], piece_str[board[rank*8+3]],
piece_str[board[rank*8+4]], piece_str[board[rank*8+5]],
piece_str[board[rank*8+6]], piece_str[board[rank*8+7]]);
}
void move(const char* s){
static int count=0;
const int dst=idx(s+2);
const int src=idx(s);
printf("%d. %.4s\n", ++count, s);
board[dst] = board[src];
board[src]=NONE;
}
int main(void){
print();
move("e2e4"); move("e7e5");
move("g1f3"); move("g8f6");
print();
return 0;
}