Inform - Support - Source

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing parserm.h

Adjudicate (lines 2305-2535)

2305  !  The Adjudicate routine tries to see if there is an obvious choice, when
2306  !  faced with a list of objects (the match_list) each of which matches the
2307  !  player's specification equally well.
2308  !
2309  !  To do this it makes use of the context (the token type being worked on).
2310  !  It counts up the number of obvious choices for the given context
2311  !  (all to do with where a candidate is, except for 6 (animate) which is to
2312  !  do with whether it is animate or not);
2313  !
2314  !  if only one obvious choice is found, that is returned;
2315  !
2316  !  if we are in indefinite mode (don't care which) one of the obvious choices
2317  !    is returned, or if there is no obvious choice then an unobvious one is
2318  !    made;
2319  !
2320  !  at this stage, we work out whether the objects are distinguishable from
2321  !    each other or not: if they are all indistinguishable from each other,
2322  !    then choose one, it doesn't matter which;
2323  !
2324  !  otherwise, 0 (meaning, unable to decide) is returned (but remember that
2325  !    the equivalence classes we've just worked out will be needed by other
2326  !    routines to clear up this mess, so we can't economise on working them
2327  !    out).
2328  !
2329  !  Returns -1 if an error occurred
2330  ! ----------------------------------------------------------------------------
2331  Constant SCORE__CHOOSEOBJ = 1000;
2332  Constant SCORE__IFGOOD = 500;
2333  Constant SCORE__UNCONCEALED = 100;
2334  Constant SCORE__BESTLOC = 60;
2335  Constant SCORE__NEXTBESTLOC = 40;
2336  Constant SCORE__NOTCOMPASS = 20;
2337  Constant SCORE__NOTSCENERY = 10;
2338  Constant SCORE__NOTACTOR = 5;
2339  Constant SCORE__GNA = 1;
2340  Constant SCORE__DIVISOR = 20;
2341   
2342  [ Adjudicate context i j k good_flag good_ones last n flag offset sovert;
2343   
2344  #ifdef DEBUG;
2345    if (parser_trace>=4)
2346    {   print "   [Adjudicating match list of size ", number_matched,
2347            " in context ", context, "^";
2348        print "   ";
2349        if (indef_mode)
2350        {   print "indefinite type: ";
2351            if (indef_type & OTHER_BIT)  print "other ";
2352            if (indef_type & MY_BIT)     print "my ";
2353            if (indef_type & THAT_BIT)   print "that ";
2354            if (indef_type & PLURAL_BIT) print "plural ";
2355            if (indef_type & LIT_BIT)    print "lit ";
2356            if (indef_type & UNLIT_BIT)  print "unlit ";
2357            if (indef_owner ~= 0) print "owner:", (name) indef_owner;
2358            new_line;
2359            print "   number wanted: ";
2360            if (indef_wanted == 100) print "all"; else print indef_wanted;
2361            new_line;
2362            print "   most likely GNAs of names: ", indef_cases, "^";
2363        }
2364        else print "definite object^";
2365    }
2366  #endif;
2367   
2368    j=number_matched-1; good_ones=0; last=match_list-->0;
2369    for (i=0:i<=j:i++)
2370    {   n=match_list-->i;
2371        match_scores-->i = 0;
2372   
2373        good_flag = false;
2374   
2375        switch(context) {
2376            HELD_TOKEN, MULTIHELD_TOKEN:
2377                if (parent(n)==actor) good_flag = true;
2378            MULTIEXCEPT_TOKEN:
2379                if (advance_warning == -1) {
2380                    good_flag = true;
2381                } else {
2382                    if (n ~= advance_warning) good_flag = true;
2383                }
2384            MULTIINSIDE_TOKEN:
2385                if (advance_warning == -1) {
2386                    if (parent(n) ~= actor) good_flag = true;
2387                } else {
2388                    if (n in advance_warning) good_flag = true;
2389                }
2390            CREATURE_TOKEN: if (CreatureTest(n)==1) good_flag = true;
2391            default: good_flag = true;
2392        }
2393   
2394        if (good_flag) {
2395            match_scores-->i = SCORE__IFGOOD;
2396            good_ones++; last = n;
2397        }
2398    }
2399    if (good_ones==1) return last;
2400   
2401    ! If there is ambiguity about what was typed, but it definitely wasn't
2402    ! animate as required, then return anything; higher up in the parser
2403    ! a suitable error will be given.  (This prevents a question being asked.)
2404    !
2405    if (context==CREATURE_TOKEN && good_ones==0) return match_list-->0;
2406   
2407    if (indef_mode==0) indef_type=0;
2408   
2409    ScoreMatchL(context);
2410    if (number_matched == 0) return -1;
2411   
2412    if (indef_mode == 0)
2413    {   !  Is there now a single highest-scoring object?
2414        i = SingleBestGuess();
2415        if (i >= 0)
2416        {   
2417  #ifdef DEBUG;
2418            if (parser_trace>=4)
2419                print "   Single best-scoring object returned.]^";
2420  #endif;
2421            return i;
2422        }
2423    }
2424   
2425    if (indef_mode==1 && indef_type & PLURAL_BIT ~= 0)
2426    {   if (context ~= MULTI_TOKEN or MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN
2427                       or MULTIINSIDE_TOKEN)
2428        {   etype=MULTI_PE; return -1; }
2429        i=0; offset=multiple_object-->0; sovert = -1;
2430        for (j=BestGuess():j~=-1 && i<indef_wanted
2431             && i+offset<63:j=BestGuess())
2432        {   flag=0;
2433            if (j hasnt concealed && j hasnt worn) flag=1;
2434            if (sovert == -1) sovert = bestguess_score/SCORE__DIVISOR;
2435            else {
2436                if (indef_wanted == 100
2437                    && bestguess_score/SCORE__DIVISOR < sovert) flag=0;
2438            }
2439            if (context==MULTIHELD_TOKEN or MULTIEXCEPT_TOKEN
2440                && parent(j)~=actor) flag=0;
2441            if (action_to_be == ##Take or ##Remove && parent(j)==actor) flag=0;
2442            k=ChooseObjects(j,flag);
2443            if (k==1) flag=1; else { if (k==2) flag=0; }
2444            if (flag==1)
2445            {   i++; multiple_object-->(i+offset) = j;
2446  #ifdef DEBUG;
2447                if (parser_trace>=4) print "   Accepting it^";
2448  #endif;
2449            }
2450            else
2451            {   i=i;
2452  #ifdef DEBUG;
2453                if (parser_trace>=4) print "   Rejecting it^";
2454  #endif;
2455            }
2456        }
2457        if (i<indef_wanted && indef_wanted<100)
2458        {   etype=TOOFEW_PE; multi_wanted=indef_wanted;
2459            multi_had=i;
2460            return -1;
2461        }
2462        multiple_object-->0 = i+offset;
2463        multi_context=context;
2464  #ifdef DEBUG;
2465        if (parser_trace>=4)
2466            print "   Made multiple object of size ", i, "]^";
2467  #endif;
2468        return 1;
2469    }
2470   
2471    for (i=0:i<number_matched:i++) match_classes-->i=0;
2472   
2473    n=1;
2474    for (i=0:i<number_matched:i++)
2475        if (match_classes-->i==0)
2476        {   match_classes-->i=n++; flag=0;
2477            for (j=i+1:j<number_matched:j++)
2478                if (match_classes-->j==0
2479                    && Identical(match_list-->i, match_list-->j)==1)
2480                {   flag=1;
2481                    match_classes-->j=match_classes-->i;
2482                }
2483            if (flag==1) match_classes-->i = 1-n;
2484        }
2485    n--; number_of_classes = n;
2486   
2487  #ifdef DEBUG;
2488    if (parser_trace>=4)
2489    {   print "   Grouped into ", n, " possibilities by name:^";
2490        for (i=0:i<number_matched:i++)
2491            if (match_classes-->i > 0)
2492                print "   ", (The) match_list-->i,
2493                    " (", match_list-->i, ")  ---  group ",
2494                    match_classes-->i, "^";
2495    }
2496  #endif;
2497   
2498    if (indef_mode == 0)
2499    {   if (n > 1)
2500        {   k = -1;
2501            for (i=0:i<number_matched:i++)
2502            {   if (match_scores-->i > k)
2503                {   k = match_scores-->i;
2504                    j = match_classes-->i; j=j*j;
2505                    flag = 0;
2506                }
2507                else
2508                if (match_scores-->i == k)
2509                {   if ((match_classes-->i) * (match_classes-->i) ~= j)
2510                        flag = 1;
2511                }
2512            }
2513            if (flag)
2514            {
2515  #ifdef DEBUG;
2516                if (parser_trace>=4)
2517                    print "   Unable to choose best group, so ask player.]^";
2518  #endif;
2519                return 0;
2520            }
2521  #ifdef DEBUG;
2522            if (parser_trace>=4)
2523                print "   Best choices are all from the same group.^";
2524  #endif;          
2525        }
2526    }
2527   
2528  !  When the player is really vague, or there's a single collection of
2529  !  indistinguishable objects to choose from, choose the one the player
2530  !  most recently acquired, or if the player has none of them, then
2531  !  the one most recently put where it is.
2532   
2533    if (n==1) dont_infer = true;
2534    return BestGuess();
2535  ];


Last updated 27 February 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.