int* getinputlocation(chess *q, char *str) { int i = 0; int *locinput; locinput = (int*)malloc(sizeof(int) * 4); locinput[3] = NOKILL; while(str[i] != '\0') { switch(str[i]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': locinput[1] = converti(str[i]); break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': if(i == 0) { locinput[0] = PAWN; } locinput[2] = convertj(str[i]); break; case 'P': locinput[0] = PAWN; break; case 'R': locinput[0] = ROOK; break; case 'N': locinput[0] = KNIGHT; break; case 'B': locinput[0] = BISHOP; break; case 'Q': locinput[0] = QUEEN; break; case 'K': locinput[0] = KING; break; case 'x': case 'X': locinput[3] = KILL; break; default: mvprintw(18, 112, "Invalid input"); return NULL; } i++; } locinput = correctness(q, locinput); return locinput; }
new_list crea_lista_foglie(list l,int totcar){ new_list newl=NULL; el_type buf; int i; tree foglia[70]; // inizializzo le foglie for(i=0;i<totcar;i++){ buf=converti(l->value); foglia[i]=(tree)malloc(sizeof(NODO_TREE)); foglia[i]->value=buf; foglia[i]->right=NULL; foglia[i]->left=NULL; newl=new_constail(foglia[i],newl); l=l->next; } return newl; }
int* getinputlocationpr(chess *q, char *str, int *loc) { int i = 0; int *locinput; locinput = (int*)malloc(sizeof(int) * 4); locinput[3] = NOKILL; while(str[i] != '\0') { switch(str[i]) { case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': locinput[1] = converti(str[i]); break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': if(i == 0) { locinput[0] = PAWN; } locinput[2] = convertj(str[i]); break; case 'P': locinput[0] = PAWN; break; case 'R': locinput[0] = ROOK; break; case 'N': locinput[0] = KNIGHT; break; case 'B': locinput[0] = BISHOP; break; case 'Q': locinput[0] = QUEEN; break; case 'K': locinput[0] = KING; break; case 'x': case 'X': locinput[3] = KILL; break; default: mvprintw(25, 110, "Invalid input"); return NULL; } i++; } /* Now check for its correctness */ if(loc[0] != PAWN && loc[0] == locinput[0]) { i = match(q, locinput, loc); if(i == 1) {//valid i = barrier(q, locinput, loc, 0); if(i == 0) { return locinput; } } return NULL; } else if(loc[0] == PAWN && loc[0] == locinput[0]) { if((q->state == WHITE && loc[1] - locinput[1] == -1 || q->state == BLACK && loc[1] - locinput[1] == 1) && (loc[2] - locinput[2] == -1 || loc[2] - locinput[2] == 1)) { return locinput; } return NULL; } return NULL; }