static void manual_move( char **last, char *dice ) { const char *p = strtok_r( NULL, DELIM, last ); unsigned int move; move = CSA2Internal( p ); if( move == MOVE_NULL ) { out(" Invalid Move\n"); return; } if( is_mated() == 1 ) history_dice( 0 ); else { if( dice == NULL || strcmp( dice, "1" ) < 0 || strcmp( dice, "6" ) > 0 ) { out(" Invalid Number\n"); return; } history_dice( atoi( dice ) ); } char str_move[8]; str_CSA_move( str_move, move ); out("%s\n", str_move); MAKE_MOVE( move ); out_position(); }
void move_set_attr(board_t *b, move_t *move) { int check, mated; board_t board = *b; if (move_is_capture(b, move)) move->type = CAPTURE; else move->type = NORMAL; if (PIECE(b->square[move->source]) == KING) { int hor = move->destination % 8 - move->source % 8; if (hor > 1) move->type = KINGSIDE_CASTLE; else if (hor < -1) move->type = QUEENSIDE_CASTLE; } make_move(&board, move); check = in_check(&board, board.turn); mated = is_mated(&board, board.turn); if (check && mated) move->state = MOVE_CHECKMATE; else if (check) move->state = MOVE_CHECK; else if (mated) move->state = MOVE_STALEMATE; else move->state = MOVE_NORMAL; }
int cmd_prompt(){ /* ret = 0: continue -1: exit */ char buf[256]; const char *token; char *last, *last2; int count_byte, ret = 0; if( TURN ) { out("Black %d> ", N_PLY +1 ); } else { out("White %d> ", N_PLY +1 ); } memset( buf, 0, sizeof(buf) ); fgets( buf, sizeof( buf ), stdin ); count_byte = strlen( buf ); if( !strcmp( buf, "\n") ) { return 0; } buf[count_byte-1] = '\0'; token = strtok_r( buf, DELIM, &last ); last = strtok_r( last, DELIM, &last2 ); if( token == NULL ) { return 0; } if( !strcmp( token, "quit" ) ) { return -1; } else if( !strcmp( token, "board" ) ) { out_position(); } else if( !strcmp( token, "back" ) ) { back(); } else if( !strcmp( token, "move" ) ) { manual_move( &last, last2 ); } else if( !strcmp( token, "dice" ) || !strcmp( token, "d" ) ) { shake_dice(); } else if( !strcmp( token, "search" ) || !strcmp( token, "s" ) ) { if( is_mated() == 1 ) search_start( 0 ); else if( last == NULL || strcmp( last, "1" ) < 0 || strcmp( last, "6" ) > 0 ) { out(" Invalid Number\n"); return 1; } else search_start( atoi( last ) ); } else if( !strcmp( token, "ds" ) ) { if( is_mated() == 1 ) search_start( 0 ); else search_start( shake_dice() ); } else if( !strcmp( token, "new" ) ) { new_game(); } else if( !strcmp( token, "record" ) ) { out_record( 1 ); } else { ret = -1; } if( ret == -1 ) out(" Invalid command\n"); return 0; }