Beispiel #1
0
static void reflecting_bishop_generate_moves_recursive(square in, numvec dir, unsigned int nr_remaining_reflections)
{
  curr_generation->arrival = in+dir;

  if (is_square_blocked(curr_generation->arrival))
    return;

  while (is_square_empty(curr_generation->arrival))
  {
    push_move();
    curr_generation->arrival += dir;
  }

  if (piece_belongs_to_opponent(curr_generation->arrival))
    push_move();
  else if (nr_remaining_reflections>0 && is_square_blocked(curr_generation->arrival))
  {
    square const sq_reflection = curr_generation->arrival-dir;

    vec_index_type const dir_index = find_vec_index(dir);
    vec_index_type const dir_reflected_index = dir_index*2;

    reflecting_bishop_generate_moves_recursive(sq_reflection,
                                               angle_vectors[angle_90][dir_reflected_index],
                                               nr_remaining_reflections-1);
    reflecting_bishop_generate_moves_recursive(sq_reflection,
                                               angle_vectors[angle_90][dir_reflected_index-1],
                                               nr_remaining_reflections-1);
  }
}
Beispiel #2
0
static void bouncy_nightrider_generate_moves_recursive(square step_departure)
{
  vec_index_type k;

  if (!NoEdge(step_departure))
    settraversed(step_departure);

  for (k= vec_knight_start; k<=vec_knight_end; k++)
  {
    curr_generation->arrival = step_departure+vec[k];

    while (is_square_empty(curr_generation->arrival))
    {
      push_move();
      if (!NoEdge(curr_generation->arrival) && !traversed(curr_generation->arrival))
      {
        bouncy_nightrider_generate_moves_recursive(curr_generation->arrival);
        break;
      }
      else
        curr_generation->arrival += vec[k];
    }

    if (piece_belongs_to_opponent(curr_generation->arrival))
      push_move();
  }
}
Beispiel #3
0
static void maooa_rider_lion_generate_moves(numvec to_passed, numvec to_arrival)
{
  square const sq_departure = curr_generation->departure;
  square sq_passed = sq_departure+to_passed;
  curr_generation->arrival = sq_departure+to_arrival;

  while (is_square_empty(sq_passed) && is_square_empty(curr_generation->arrival))
  {
    sq_passed += to_arrival;
    curr_generation->arrival += to_arrival;
  }

  if (!is_square_blocked(sq_passed) && !is_square_blocked(curr_generation->arrival))
  {
    if (!is_square_empty(sq_passed)
        && (is_square_empty(curr_generation->arrival)
            || piece_belongs_to_opponent(curr_generation->arrival)))
      push_move();
    if (is_square_empty(sq_passed) || is_square_empty(curr_generation->arrival))
    {
      sq_passed += to_arrival;
      curr_generation->arrival += to_arrival;
      while (is_square_empty(sq_passed) && is_square_empty(curr_generation->arrival))
      {
        push_move();
        sq_passed += to_arrival;
        curr_generation->arrival += to_arrival;
      }
    }

    if (is_square_empty(sq_passed)
        && piece_belongs_to_opponent(curr_generation->arrival))
      push_move();
  }
}
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void orthodox_mating_king_contact_generator_solve(slice_index si)
{
  Side const moving = SLICE_STARTER(si);
  Side const mated = advers(moving);
  square const sq_mated_king = being_solved.king_square[mated];

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  assert(solve_nr_remaining==slack_length+1);

  curr_generation->departure = being_solved.king_square[moving];

  if (curr_generation->departure!=sq_mated_king)
  {
    vec_index_type k;
    for (k = vec_queen_start; k<=vec_queen_end; k++)
    {
      curr_generation->arrival = curr_generation->departure+vec[k];
      if ((is_square_empty(curr_generation->arrival)
          || TSTFLAG(being_solved.spec[curr_generation->arrival],mated))
          && move_diff_code[abs(sq_mated_king-curr_generation->arrival)]<=1+1)
        push_move();
    }
  }

  pipe_solve_delegate(si);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #5
0
LSValue* LSValue::get_from_json(Json& json) {
	switch (json.type()) {
		case Json::value_t::null:
			return LSNull::get();
		case Json::value_t::boolean:
			return LSBoolean::get(json);
		case Json::value_t::number_integer:
		case Json::value_t::number_unsigned:
		case Json::value_t::number_float:
			return LSNumber::get(json);
		case Json::value_t::string:
			return new LSString(json);
		case Json::value_t::array: {
			auto array = new LSArray<LSValue*>();
			for (auto& v : json) {
				array->push_move(get_from_json(v));
			}
			return array;
		}
		case Json::value_t::object: {
			auto object = new LSObject();
			for (Json::iterator it = json.begin(); it != json.end(); ++it) {
				object->addField(it.key(), get_from_json(it.value()));
			}
			return object;
		}
		case Json::value_t::discarded:
			assert(false); // LCOV_EXCL_LINE
	}
	throw std::exception();
}
Beispiel #6
0
int tick() {
    // Handle user input
    Direction in = get_direction();
    if (in != NO_DIRECTION) {
        push_move(move_list, in);
    }
    
    // Handle snake movement
    update_direction(snake, move_list);
    move_snake(snake);

    // Draw everything
    draw_frame(snake, food_list);

    Collision collision = find_collision(snake, food_list, screen);
    switch(collision){
        case SNAKE:
        case SCREEN:
            return 0;
        
        case FOOD:
            grow_snake();
            new_food();
            break;

        case NONE:
            break;
    }
    
    snake_sleep();
    return 1;
}
Beispiel #7
0
/**
 * @brief       Performs move
 *
 * Performs a move on the board and adds it to the move history.
 *
 * @param[in]   color   Color of stone to move
 * @param[in]   i       Horizontal coordinate of move
 * @param[in]   j       Vertical coordinate of move
 * @return      Nothing
 * @sa          undo_move()
 */
void make_move( int color, int i, int j )
{
    int nr_of_removed_stones;
    int group_nr;
    int nr_of_liberties;
    int group_size;
    int captured_now[BOARD_SIZE_MAX * BOARD_SIZE_MAX][2];

    // Check for pass:
    if ( i == INVALID && j == INVALID ) {
        create_next_move();
        set_move_pass(color);
        push_move();

        return;
    }

    set_vertex( color, i, j );
    scan_board_1();
    nr_of_removed_stones = remove_stones( color * -1 );
    if ( nr_of_removed_stones > 0 ) {
        scan_board_1();
    }

    nr_of_removed_stones = get_captured_now(captured_now);

    create_next_move();
    set_move_vertex( color, i, j );
    set_move_captured_stones(captured_now);

    group_nr        = get_worm_nr( i, j );
    nr_of_liberties = get_nr_of_liberties(group_nr);
    group_size      = get_size_of_worm(group_nr);

    // Check if this move is a ko:
    if ( nr_of_removed_stones == 1 && group_size == 1 && nr_of_liberties == 1 ) {
        // If only one stone has been captured it must be the first in the
        // captured_now list:
        set_move_ko( captured_now[0][0], captured_now[0][1] );
    }

    push_move();

    return;
}
Beispiel #8
0
/* Generate moves for a chinese leaper 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_leaper_generate_moves(vec_index_type kbeg, vec_index_type kend)
{
  vec_index_type k;

  for (k = kbeg; k<=kend; ++k)
  {
    curr_generation->arrival = curr_generation->departure + vec[k];

    if (is_square_empty(curr_generation->arrival))
      push_move();
    else if (!is_square_blocked(curr_generation->arrival))
    {
      curr_generation->arrival += vec[k];
      if (piece_belongs_to_opponent(curr_generation->arrival))
        push_move();
    }
  }
}
Beispiel #9
0
static void bouncy_knight_generate_moves_recursive(square step_departure, int x)
{
  vec_index_type k;

  /* ATTENTION:   first call of grefcn: x must be 2 !!   */

  for (k = vec_knight_start; k<=vec_knight_end; ++k)
  {
    curr_generation->arrival = step_departure+vec[k];
    if (is_square_empty(curr_generation->arrival))
    {
      push_move();
      if (x>0 && !NoEdge(curr_generation->arrival))
        bouncy_knight_generate_moves_recursive(curr_generation->arrival,x-1);
    }
    else if (piece_belongs_to_opponent(curr_generation->arrival))
      push_move();
  }
}
Beispiel #10
0
/* Generate moves for a cat
 */
void cat_generate_moves(void)
{
  /* generate moves of a CAT */
  vec_index_type k;

  for (k= vec_knight_start; k<=vec_knight_end; k++)
  {
    curr_generation->arrival = curr_generation->departure+vec[k];
    if (piece_belongs_to_opponent(curr_generation->arrival))
      push_move();
    else
    {
      while (is_square_empty(curr_generation->arrival))
      {
        push_move();
        curr_generation->arrival += cat_vectors[k];
      }

      if (piece_belongs_to_opponent(curr_generation->arrival))
        push_move();
    }
  }
}
Beispiel #11
0
/* Try to solve in solve_nr_remaining half-moves.
 * @param si slice index
 * @note assigns solve_result the length of solution found and written, i.e.:
 *            previous_move_is_illegal the move just played is illegal
 *            this_move_is_illegal     the move being played is illegal
 *            immobility_on_next_move  the moves just played led to an
 *                                     unintended immobility on the next move
 *            <=n+1 length of shortest solution found (n+1 only if in next
 *                                     branch)
 *            n+2 no solution found in this branch
 *            n+3 no solution found in next branch
 *            (with n denominating solve_nr_remaining)
 */
void black_checks_null_move_generator_solve(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",si);
  TraceFunctionParamListEnd();

  assert(trait[nbply]==Black);

  curr_generation->departure = nullsquare;
  curr_generation->arrival = nullsquare;
  push_move();
  pipe_solve_delegate(si);

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Beispiel #12
0
/* Generate moves to the square on a line segment
 * @param sq_base first square of line segment
 * @param k vector index indicating the direction of the line segment
 */
square generate_moves_on_line_segment(square sq_base, vec_index_type k)
{
  TraceFunctionEntry(__func__);
  TraceSquare(sq_base);
  TraceFunctionParamListEnd();

  curr_generation->arrival = sq_base+vec[k];

  while (is_square_empty(curr_generation->arrival))
  {
    push_move();
    curr_generation->arrival += vec[k];
  }

  TraceFunctionExit(__func__);
  TraceSquare(curr_generation->arrival);
  TraceFunctionResultEnd();
  return curr_generation->arrival;
}
Beispiel #13
0
static void marine_leaper_generate_moves(vec_index_type kanf, vec_index_type kend)
{
    vec_index_type k;

    TraceFunctionEntry(__func__);
    TraceFunctionParamListEnd();

    for (k = kanf; k<=kend; ++k)
    {
        numvec const dir = vec[k];
        curr_generation->arrival = curr_generation->departure+dir;
        if (is_square_empty(curr_generation->arrival))
            push_move();
        else
            generate_locust_capture(curr_generation->arrival,dir);
    }

    TraceFunctionExit(__func__);
    TraceFunctionResultEnd();
}
Beispiel #14
0
/* Generate moves for a 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 rider_generate_moves(vec_index_type kbeg, vec_index_type kend)
{
  /* generate rider moves from vec[kbeg] to vec[kend] */
  vec_index_type k;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",kbeg);
  TraceFunctionParam("%u",kend);
  TraceFunctionParamListEnd();

  for (k = kbeg; k<=kend; ++k)
  {
    curr_generation->arrival = generate_moves_on_line_segment(curr_generation->departure,k);
    if (piece_belongs_to_opponent(curr_generation->arrival))
      push_move();
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}