示例#1
0
static void alloc_reci_end(slice_index proxy_nonreci,
                           slice_index proxy_reci,
                           slice_index proxy_to_nonreci,
                           slice_index proxy_to_reci)
{
    TraceFunctionEntry(__func__);
    TraceFunctionParam("%u",proxy_nonreci);
    TraceFunctionParam("%u",proxy_reci);
    TraceFunctionParam("%u",proxy_to_nonreci);
    TraceFunctionParam("%u",proxy_to_reci);
    TraceFunctionParamListEnd();

    {
        slice_index const branch_nonreci = alloc_help_branch(2,2);
        slice_index const branch_reci = alloc_help_branch(1,1);

        help_branch_set_end_goal(branch_nonreci,proxy_to_nonreci,1);
        link_to_branch(proxy_nonreci,branch_nonreci);

        help_branch_set_end_goal(branch_reci,proxy_to_reci,1);
        link_to_branch(proxy_reci,branch_reci);
    }

    TraceFunctionExit(__func__);
    TraceFunctionResultEnd();
}
示例#2
0
static char *ParseHelpDia(char *tok,
                          slice_index start,
                          slice_index proxy,
                          slice_index proxy_next,
                          play_length_type play_length)
{
    char *result;

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParam("%u",start);
    TraceFunctionParam("%u",proxy);
    TraceFunctionParam("%u",proxy_next);
    TraceFunctionParam("%u",play_length);
    TraceFunctionParamListEnd();

    result = ParseGoal(tok,start,proxy_next);
    if (result!=0)
    {
        stip_length_type length;
        stip_length_type min_length;
        result = ParseHelpLength(result,&length,&min_length,play_length);
        if (result!=0)
        {
            link_to_branch(proxy,alloc_help_branch(length,min_length));
            select_output_mode(proxy,output_mode_line);
            help_branch_set_end_goal(proxy,proxy_next,1);
        }
    }

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",result);
    TraceFunctionResultEnd();
    return result;
}
示例#3
0
static slice_index make_cagecirce_noncapture_finder(Side side)
{
  slice_index result;

  if (circe_variant.determine_rebirth_square==circe_determine_rebirth_square_cage
      || anticirce_variant.determine_rebirth_square==circe_determine_rebirth_square_cage)
  {
    slice_index const proxy_branch = alloc_proxy_slice();
    slice_index const help = alloc_help_branch(slack_length+1,slack_length+1);
    slice_index const proxy_goal = alloc_proxy_slice();
    slice_index const system = alloc_goal_capture_reached_tester_system();
    link_to_branch(proxy_goal,system);

    {
      slice_index const tester = branch_find_slice(STGoalReachedTester,
                                                   proxy_goal,
                                                   stip_traversal_context_intro);
      assert(tester!=no_slice);
      pipe_append(SLICE_NEXT2(tester),alloc_not_slice());
      SLICE_U(tester).goal_handler.goal.type = goal_negated;
      help_branch_set_end_goal(help,proxy_goal,1);
      link_to_branch(proxy_branch,help);
      result = alloc_conditional_pipe(STCageCirceNonCapturingMoveFinder,proxy_branch);
      solving_impose_starter(result,side);
    }
  }
  else
    result = alloc_proxy_slice();

  return result;
}
示例#4
0
static slice_index make_ultra_mummer_length_measurer(Side side)
{
  slice_index result;
  slice_index const proxy_branch = alloc_proxy_slice();
  slice_index const help = alloc_help_branch(slack_length+1,slack_length+1);
  slice_index const proxy_goal = alloc_proxy_slice();
  slice_index const system = alloc_goal_any_reached_tester_system();
  link_to_branch(proxy_goal,system);
  help_branch_set_end_goal(help,proxy_goal,1);
  link_to_branch(proxy_branch,help);
  result = alloc_conditional_pipe(STUltraMummerMeasurerFork,proxy_branch);
  solving_impose_starter(result,side);
  return result;
}
示例#5
0
static slice_index make_castling_intermediate_move_legality_tester(Side side)
{
  slice_index result;
  slice_index const proxy_branch = alloc_proxy_slice();
  slice_index const help = alloc_help_branch(slack_length+1,slack_length+1);
  slice_index const proxy_goal = alloc_proxy_slice();
  slice_index const system = alloc_goal_any_reached_tester_system();
  link_to_branch(proxy_goal,system);
  help_branch_set_end_goal(help,proxy_goal,1);
  link_to_branch(proxy_branch,help);
  result = alloc_conditional_pipe(STCastlingIntermediateMoveLegalityTester,proxy_branch);
  solving_impose_starter(result,side);

  return result;
}
示例#6
0
static slice_index make_circe_take_make_rebirth_squares_finder(Side side)
{
  slice_index result;
  slice_index const proxy_branch = alloc_proxy_slice();
  slice_index const help = alloc_help_branch(slack_length+1,slack_length+1);
  slice_index const prototype = alloc_pipe(STTakeMakeCirceCollectRebirthSquares);
  slice_index const executing = alloc_pipe(STExecutingKingCapture);
  link_to_branch(proxy_branch,help);
  help_branch_insert_slices(help,&prototype,1);
  slice_insertion_insert(help,&executing,1);
  result = alloc_conditional_pipe(STTakeMakeCirceCollectRebirthSquaresFork,proxy_branch);
  solving_impose_starter(result,side);

  return result;
}
示例#7
0
static slice_index make_brunner_check_defense_finder(Side side)
{
  slice_index result;
  slice_index const proxy_branch = alloc_proxy_slice();
  slice_index const help = alloc_help_branch(slack_length+1,slack_length+1);
  slice_index const proxy_goal = alloc_proxy_slice();
  slice_index const system = alloc_goal_any_reached_tester_system();
  slice_index const executing = alloc_pipe(STExecutingKingCapture);
  link_to_branch(proxy_goal,system);
  help_branch_set_end_goal(help,proxy_goal,1);
  slice_insertion_insert(help,&executing,1);
  link_to_branch(proxy_branch,help);
  result = alloc_conditional_pipe(STBrunnerDefenderFinder,proxy_branch);
  solving_impose_starter(result,side);
  return result;
}
示例#8
0
/* Make an "hh branch"
 * @param min_length minimum length indicated by the user (0 if (s)he didn't)
 * @param max_length maximum length indicated by the user
 * @return identifier of branch entry slice
 */
static slice_index ParseStructuredStip_make_branch_h(stip_length_type min_length,
                                                     stip_length_type max_length)
{
  slice_index result;

  TraceFunctionEntry(__func__);
  TraceFunctionParam("%u",min_length);
  TraceFunctionParam("%u",max_length);
  TraceFunctionParamListEnd();

  if (min_length==0)
    min_length = max_length%2;
  else if (min_length>max_length)
    min_length = max_length;

  result = alloc_help_branch(max_length,min_length);

  TraceFunctionExit(__func__);
  TraceFunctionResult("%u",result);
  TraceFunctionResultEnd();
  return result;
}
示例#9
0
static char *ParseHelp(char *tok,
                       slice_index start,
                       slice_index proxy,
                       slice_index proxy_goal,
                       play_length_type play_length,
                       boolean shorten)
{
    char *result;

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParam("%u",start);
    TraceFunctionParam("%u",proxy);
    TraceFunctionParam("%u",proxy_goal);
    TraceFunctionParam("%u",play_length);
    TraceFunctionParam("%u",shorten);
    TraceFunctionParamListEnd();

    result = ParseGoal(tok,start,proxy_goal);
    if (result!=0)
    {
        stip_length_type length;
        stip_length_type min_length;
        result = ParseHelpLength(result,&length,&min_length,play_length);
        if (result!=0)
        {
            slice_index const branch = alloc_help_branch(length,min_length);
            if (shorten)
                help_branch_shorten(branch);
            attach_help_branch(length,proxy,branch);
            select_output_mode(proxy,output_mode_line);
        }
    }

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",result);
    TraceFunctionResultEnd();
    return result;
}
示例#10
0
static char *ParsePlay(char *tok,
                       slice_index start,
                       slice_index proxy,
                       play_length_type play_length)
{
    /* seriesmovers with introductory moves */
    char *result = 0;
    char *arrowpos;
    slice_index const proxy_next = alloc_proxy_slice();

    TraceFunctionEntry(__func__);
    TraceFunctionParam("%s",tok);
    TraceFunctionParam("%u",start);
    TraceFunctionParam("%u",proxy);
    TraceFunctionParamListEnd();

    if (token_starts_with("exact-",tok))
    {
        play_length = play_length_exact;
        tok += 6;
    }

    arrowpos = strstr(tok,"->");
    if (arrowpos!=0)
    {
        char *end;
        unsigned long const intro_len= strtoul(tok,&end,10);
        if (intro_len<1 || tok==end || end!=arrowpos)
            output_plaintext_input_error_message(WrongInt, 0);
        else
        {
            result = ParsePlay(arrowpos+2,start,proxy_next,play_length);
            if (result!=0 && SLICE_NEXT1(proxy_next)!=no_slice)
            {
                /* >=1 move of starting side required */
                slice_index const branch = alloc_series_branch(2*intro_len-1,1);
                help_branch_set_end(branch,proxy_next,1);
                link_to_branch(proxy,branch);
                select_output_mode(proxy,output_mode_line);
            }
        }
    }

    else if (token_starts_with("ser-reci-h",tok))
    {
        /* skip over "ser-reci-h" */
        tok = ParseReciEnd(tok+10,start,proxy_next);
        if (tok!=0 && SLICE_NEXT1(proxy_next)!=no_slice)
        {
            stip_length_type length;
            stip_length_type min_length;
            result = ParseSeriesLength(tok,&length,&min_length,play_length);
            if (result!=0)
            {
                slice_index const branch = alloc_series_branch(length-1,min_length+1);
                help_branch_set_end(branch,proxy_next,1);
                link_to_branch(proxy,branch);

                solving_impose_starter(proxy_next,Black);
                select_output_mode(proxy,output_mode_line);
            }
        }
    }

    else if (token_starts_with("ser-hs",tok))
    {
        tok = ParseGoal(tok+6,start,proxy_next); /* skip over "ser-hs" */
        if (tok!=0)
        {
            stip_length_type length;
            stip_length_type min_length;
            result = ParseSeriesLength(tok,&length,&min_length,play_length);
            if (result!=0)
            {
                slice_index const defense_branch = MakeEndOfSelfPlay(proxy_next);

                /* in ser-hs, the series is 1 half-move longer than in usual
                 * series play! */
                if (length==0)
                    pipe_link(proxy,defense_branch);
                else
                {
                    slice_index const series = alloc_series_branch(length,min_length);

                    slice_index const help_proxy = alloc_proxy_slice();
                    slice_index const help = alloc_help_branch(1,1);
                    link_to_branch(help_proxy,help);
                    help_branch_set_end_forced(help_proxy,defense_branch,1);
                    help_branch_set_end(series,help_proxy,1);
                    link_to_branch(proxy,series);
                }

                solving_impose_starter(proxy_next,White);
                select_output_mode(proxy,output_mode_line);
            }
        }
    }

    else if (token_starts_with("ser-h",tok))
    {
        result = ParseSeries(tok+5,start,proxy,proxy_next,play_length); /* skip over "ser-h" */
        if (result!=0)
        {
            slice_index const help = alloc_help_branch(1,1);
            help_branch_set_end_goal(help,proxy_next,1);
            help_branch_set_end(proxy,help,1);

            {
                slice_index const next = SLICE_NEXT1(proxy_next);
                assert(next!=no_slice);
                if (SLICE_TYPE(next)==STGoalReachedTester
                        && SLICE_U(next).goal_handler.goal.type==goal_proofgame)
                    solving_impose_starter(proxy_next,White);
                else
                    solving_impose_starter(proxy_next,Black);
            }
        }
    }

    else if (token_starts_with("ser-s",tok))
    {
        result = ParseSeries(tok+5,start,proxy,proxy_next,play_length); /* skip over "ser-s" */
        if (result!=0)
        {
            help_branch_set_end_forced(proxy,MakeEndOfSelfPlay(proxy_next),1);
            solving_impose_starter(proxy_next,White);
        }
    }

    else if (token_starts_with("ser-r",tok))
    {
        result = ParseSeries(tok+5,start,proxy,proxy_next,play_length); /* skip over "ser-r" */
        if (result!=0)
        {
            slice_index const proxy_semi = MakeSemireflexBranch(proxy_next);
            help_branch_set_end_forced(proxy,proxy_semi,1);
            series_branch_insert_constraint(proxy,MakeReflexBranch(proxy_semi));
            solving_impose_starter(proxy_next,White);
        }
    }

    else if (token_starts_with("ser-",tok))
    {
        result = ParseSeries(tok+4,start,proxy,proxy_next,play_length); /* skip over "ser-" */
        if (result!=0)
        {
            help_branch_set_end_goal(proxy,proxy_next,1);
            solving_impose_starter(proxy_next,Black);
        }
    }

    else if (token_starts_with("phser-r",tok))
    {
        boolean const shorten = true;
        result = ParseHelp(tok+7, /* skip over phser-r */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            slice_index const proxy_semi = MakeSemireflexBranch(proxy_next);
            help_branch_set_end_forced(proxy,proxy_semi,1);
            if (help_branch_insert_constraint(proxy,MakeReflexBranch(proxy_semi),0))
            {
                help_branch_insert_check_zigzag(proxy);
                solving_impose_starter(proxy_next,White);
            }
            else
                result = 0;
        }
    }

    else if (token_starts_with("phser-s",tok))
    {
        boolean const shorten = true;
        result = ParseHelp(tok+7, /* skip over phser-s */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            help_branch_set_end_forced(proxy,MakeEndOfSelfPlay(proxy_next),1);
            help_branch_insert_check_zigzag(proxy);
            solving_impose_starter(proxy_next,White);
        }
    }

    else if (token_starts_with("phser-",tok))
    {
        boolean const shorten = true;
        result = ParseHelp(tok+6, /* skip over phser- */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            help_branch_set_end_goal(proxy,proxy_next,1);
            help_branch_insert_check_zigzag(proxy);
            solving_impose_starter(proxy_next,Black);
        }
    }

    else if (token_starts_with("pser-hs",tok))
    {
        tok = ParseGoal(tok+7,start,proxy_next); /* skip over "ser-hs" */
        if (tok!=0)
        {
            stip_length_type length;
            stip_length_type min_length;
            result = ParseSeriesLength(tok,&length,&min_length,play_length);
            if (result!=0)
            {
                slice_index const series = alloc_help_branch(length,min_length);
                slice_index const help_proxy = alloc_proxy_slice();
                slice_index const help = alloc_help_branch(1,1);
                slice_index const defense_branch = MakeEndOfSelfPlay(proxy_next);
                link_to_branch(help_proxy,help);
                help_branch_set_end_forced(help_proxy,defense_branch,1);
                help_branch_set_end(series,help_proxy,1);
                link_to_branch(proxy,series);
                help_branch_insert_check_zigzag(proxy);
                solving_impose_starter(proxy_next,White);
                select_output_mode(proxy,output_mode_line);
            }
        }
    }

    else if (token_starts_with("pser-h",tok))
    {
        boolean const shorten = true;
        result = ParseHelp(tok+6, /* skip over pser-h */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            slice_index const to_goal = SLICE_NEXT1(proxy_next);
            slice_index const nested = alloc_help_branch(1,1);
            help_branch_set_end_goal(nested,proxy_next,1);
            help_branch_set_end(proxy,nested,1);
            help_branch_insert_check_zigzag(proxy);
            if (SLICE_TYPE(to_goal)==STGoalReachedTester
                    && SLICE_U(to_goal).goal_handler.goal.type==goal_proofgame)
                solving_impose_starter(proxy_next,White);
            else
                solving_impose_starter(proxy_next,Black);
        }
    }

    else if (token_starts_with("pser-r",tok))
    {
        boolean const ends_on_defense = false;
        result = ParseBattle(tok+6, /* skip over pser-r */
                             start,
                             proxy,proxy_next,
                             play_length,ends_on_defense);
        if (result!=0)
        {
            slice_index const proxy_semi = MakeSemireflexBranch(proxy_next);
            battle_branch_insert_end_of_branch_forced(proxy,proxy_semi);
            battle_branch_insert_attack_constraint(proxy,MakeReflexBranch(proxy_semi));
            battle_branch_insert_defense_check_zigzag(proxy);
            select_output_mode(proxy,output_mode_line);
            solving_impose_starter(proxy_next,White);
        }
    }

    else if (token_starts_with("pser-s",tok))
    {
        boolean const ends_on_defense = false;
        result = ParseBattle(tok+6, /* skip over pser-s */
                             start,
                             proxy,proxy_next,
                             play_length,ends_on_defense);
        if (result!=0)
        {
            battle_branch_insert_direct_end_of_branch(proxy,
                    MakeEndOfSelfPlay(proxy_next));
            solving_impose_starter(proxy_next,Black);
            select_output_mode(proxy,output_mode_line);
            battle_branch_insert_defense_check_zigzag(proxy);
        }
    }

    else if (token_starts_with("pser-",tok))
    {
        boolean const ends_on_defense = false;
        result = ParseBattle(tok+5, /* skip over pser- */
                             start,
                             proxy,proxy_next,
                             play_length,ends_on_defense);
        if (result!=0)
        {
            select_output_mode(proxy,output_mode_line);
            battle_branch_insert_direct_end_of_branch_goal(proxy,proxy_next);
            battle_branch_insert_defense_check_zigzag(proxy);
        }
    }

    else if (token_starts_with("reci-h",tok))
    {
        char * const tok2 = ParseReciEnd(tok+6, /* skip over "reci-h" */
                                         start,proxy_next);
        if (tok2!=0 && SLICE_NEXT1(proxy_next)!=no_slice)
        {
            stip_length_type length;
            stip_length_type min_length;
            result = ParseHelpLength(tok2,&length,&min_length,play_length);

            if (length==1)
            {
                /* at least 2 half moves requried for a reciprocal stipulation */
                output_plaintext_input_error_message(StipNotSupported,0);
                result = 0;
            }

            if (result!=0)
            {
                if (length==2)
                {
                    pipe_link(proxy,SLICE_NEXT1(proxy_next));
                    dealloc_slice(proxy_next);
                }
                else
                {
                    stip_length_type const min_length2 = (min_length<2
                                                          ? min_length
                                                          : min_length-2);
                    slice_index const branch = alloc_help_branch(length-2,min_length2);
                    help_branch_set_end(branch,proxy_next,1);
                    attach_help_branch(length,proxy,branch);
                }

                solving_impose_starter(proxy_next,Black);
                select_output_mode(proxy,output_mode_line);
            }
        }
    }

    else if (token_starts_with("dia",tok))
    {
        result = ParseHelpDia(tok,start,proxy,proxy_next,play_length);
        if (result!=0)
            solving_impose_starter(proxy,White);
    }
    else if (token_starts_with("a=>b",tok))
    {
        result = ParseHelpDia(tok,start,proxy,proxy_next,play_length);
        if (result!=0)
            solving_impose_starter(proxy,Black);
    }

    else if (token_starts_with("hs",tok))
    {
        boolean const shorten = true;
        result = ParseHelp(tok+2, /* skip over "hs" */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            help_branch_set_end_forced(proxy,MakeEndOfSelfPlay(proxy_next),1);
            solving_impose_starter(proxy_next,White);
        }
    }

    else if (token_starts_with("hr",tok))
    {
        boolean const shorten = true;
        result = ParseHelp(tok+2, /* skip over "hr" */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            slice_index const proxy_semi = MakeSemireflexBranch(proxy_next);
            help_branch_set_end_forced(proxy,proxy_semi,1);
            if (help_branch_insert_constraint(proxy,MakeReflexBranch(proxy_semi),0))
                solving_impose_starter(proxy_next,White);
            else
                result = 0;
        }
    }

    else if (token_starts_with("h",tok))
    {
        boolean const shorten = false;
        result = ParseHelp(tok+1, /* skip over "h" */
                           start,
                           proxy,proxy_next,
                           play_length,shorten);
        if (result!=0)
        {
            help_branch_set_end_goal(proxy,proxy_next,1);
            solving_impose_starter(proxy_next,Black);
        }
    }

    else if (token_starts_with("semi-r",tok))
    {
        boolean const ends_on_defense = false;
        result = ParseBattle(tok+6, /* skip over "semi-r" */
                             start,
                             proxy,proxy_next,
                             play_length,ends_on_defense);
        if (result!=0)
        {
            battle_branch_insert_end_of_branch_forced(proxy,
                    MakeSemireflexBranch(proxy_next));
            select_output_mode(proxy,output_mode_tree);
            solving_impose_starter(proxy_next,White);
        }
    }

    else if (token_starts_with("s",tok))
    {
        boolean const ends_on_defense = true;
        result = ParseBattle(tok+1, /* skip over 's' */
                             start,
                             proxy,proxy_next,
                             play_length,ends_on_defense);
        if (result!=0)
        {
            select_output_mode(proxy,output_mode_tree);
            battle_branch_insert_self_end_of_branch_goal(proxy,proxy_next);
        }
    }

    else if (token_starts_with("r",tok))
    {
        boolean const ends_on_defense = false;
        result = ParseBattle(tok+1, /* skip over 'r' */
                             start,
                             proxy,proxy_next,
                             play_length,ends_on_defense);
        if (result!=0)
        {
            slice_index const proxy_semi = MakeSemireflexBranch(proxy_next);
            battle_branch_insert_end_of_branch_forced(proxy,proxy_semi);
            battle_branch_insert_attack_constraint(proxy,MakeReflexBranch(proxy_semi));
            select_output_mode(proxy,output_mode_tree);
            solving_impose_starter(proxy_next,White);
        }
    }

    else
    {
        boolean const ends_on_defense = false;
        result = ParseBattle(tok,start,proxy,proxy_next,play_length,ends_on_defense);
        if (result!=0)
        {
            select_output_mode(proxy,output_mode_tree);
            battle_branch_insert_direct_end_of_branch_goal(proxy,proxy_next);
        }
    }

    if (result==0)
        dealloc_slices(proxy_next);

    TraceFunctionExit(__func__);
    TraceFunctionResult("%s",result);
    TraceFunctionResultEnd();
    return result;
}