boolean riders_check(vec_index_type kanf, vec_index_type kend, validator_id evaluate) { square const sq_target = move_generation_stack[CURRMOVE_OF_PLY(nbply)].capture; boolean result = false; TraceFunctionEntry(__func__); TraceSquare(sq_target); TraceFunctionParamListEnd(); ++observation_context; TraceEnumerator(Side,trait[nbply],"\n"); for (interceptable_observation[observation_context].vector_index1 = kanf; interceptable_observation[observation_context].vector_index1<= kend; ++interceptable_observation[observation_context].vector_index1) { square const sq_departure = find_end_of_line(sq_target,vec[interceptable_observation[observation_context].vector_index1]); TraceSquare(sq_departure);TraceEOL(); if (EVALUATE_OBSERVATION(evaluate,sq_departure,sq_target)) { result = true; break; } } --observation_context; TraceFunctionExit(__func__); TraceFunctionResult("%u",result); TraceFunctionResultEnd(); return result; }
int read_command() { int total_bytes_read = bytes_in_buffer; int bytes_read = 0; int last_read_byte_pos = 0; while (true) { int end_of_line = find_end_of_line(helper_buffer, last_read_byte_pos, total_bytes_read); if (end_of_line == -1) { if (total_bytes_read > MAX_LINE_LENGTH) { bytes_in_buffer = 0; if (helper_buffer[bytes_read - 1]) { clean_stdin(); } fprintf(stderr, "%s\n", SYNTAX_ERROR_STR); fflush(stderr); return 0; } } else { bytes_in_buffer = total_bytes_read - end_of_line - 1; if (end_of_line > MAX_LINE_LENGTH) { fprintf(stderr, "%s\n", SYNTAX_ERROR_STR); fflush(stderr); bytes_read = 0; } else { prepare_line_buffer(line_buffer, helper_buffer, end_of_line); bytes_read = end_of_line; } clean_helepr_buffer(helper_buffer, end_of_line + 1, bytes_in_buffer); return bytes_read; } bytes_read = read(STDIN_FILENO, helper_buffer + total_bytes_read, MAX_LINE_LENGTH + 1); if (bytes_read == 0) { was_end_of_file = true; return 0; } else if (bytes_read == -1) { bytes_read = 0; continue; } last_read_byte_pos = total_bytes_read; total_bytes_read += bytes_read; } }
static boolean reflecting_bishop_check_recursive(square intermediate_square, numvec k, int x, validator_id evaluate) { square const sq_target = move_generation_stack[CURRMOVE_OF_PLY(nbply)].capture; if (is_square_blocked(intermediate_square+k)) return false; else { numvec k1; square const sq_reflection = find_end_of_line(intermediate_square,k); piece_walk_type const p1 = get_walk_of_piece_on_square(sq_reflection); if (x && p1==Invalid) { square const sq_departure = sq_reflection-k; k1= 5; while (vec[k1]!=k) k1++; k1 *= 2; if (reflecting_bishop_check_recursive(sq_departure, angle_vectors[angle_90][k1], x-1, evaluate)) return true; k1--; if (reflecting_bishop_check_recursive(sq_departure, angle_vectors[angle_90][k1], x-1, evaluate)) return true; } else if (EVALUATE_OBSERVATION(evaluate,sq_reflection,sq_target)) return true; return false; } }
/* Generate moves for a chinese rider piece * @param kbeg start of range of vector indices to be used * @param kend end of range of vector indices to be used */ void chinese_rider_generate_moves(vec_index_type kbeg, vec_index_type kend) { vec_index_type k; for (k = kbeg; k<=kend; ++k) { numecoup const base = current_move[nbply]; square const sq_hurdle = generate_moves_on_line_segment(curr_generation->departure,k); /* avoid accidentally "inheriting" the hurdle from some previous move */ hoppers_clear_hurdles(base); if (!is_square_blocked(sq_hurdle)) { curr_generation->arrival = find_end_of_line(sq_hurdle,vec[k]); if (piece_belongs_to_opponent(curr_generation->arrival)) hoppers_push_move(k,sq_hurdle); } } }
static void parse_file (char * addr, int length, long * data, int max_size, int * num_integers) { char * line = addr; char * end = addr + length; char * eof = NULL; int pos = 0; do { eof = find_end_of_line (line, length); if (eof == NULL) break; *eof = '\0'; data[pos++] = atol(line); if (pos >= max_size) { *num_integers = max_size; return; } line = eof + 1; } while (line < end); *num_integers = pos; }