#!sdl_chomik

let amount of places=value integer 5;   # minimum 2
let amount of persons=value integer 4;  # minimum 1
let amount of keys = value integer 5;   # minimum 1

variable name of person (P:integer):string;

let name of person 1 = value string "Gotrek";
let name of person 2 = value string "Gerrudir";
let name of person 3 = value string "Gimli";
let name of person 4 = value string "Gregor";

variable name of place (P:integer):string;

let name of place 1 = value string "Wyzima";
let name of place 2 = value string "Novigrad";
let name of place 3 = value string "Cintra";
let name of place 4 = value string "Kaer Morhen";
let name of place 5 = value string "Blaviken";

variable name of key (K:integer):string;
let name of key 1 = value string "the black key";
let name of key 2 = value string "the blue key";
let name of key 3 = value string "the red key";
let name of key 4 = value string "the white key";
let name of key 5 = value string "the yellow key";  # the key colors correspond with the color type
                                                    # in fantasy_create_widgets.sdl_chomik

type person_id = range 1..<amount of persons>;
type place_id = range 1..<amount of places>;
type key_id = range 1..<amount of keys>;

type class={warrior,wizard,cleric};
type disadvantage={liar,coward,thief};
type feature={strength,magic,charisma};
type item_location={in persons (X:person_id) pocket, in place (Y:place_id)};


type rule={
    warriors can attack the others unless they are cowards,
    liars can tell the others things they do not believe,
    thieves can steal keys from the others,
    wizards can magically reveal the truth,
    clerics can ask the others for a key,
    the winner will take the losers keys
    };

type information={
    person (A:person_id) can see person (B:person_id),
    person (A:person_id) can see key (B:key_id),
    person (A:person_id) is in place (B:place_id),
    person (A:person_id) has key (B:key_id),

    person (A:person_id) has told person (B:person_id) that (I:information) is (V:boolean),
    person (A:person_id) has asked person (B:person_id) about (I:information),
    person (A:person_id) has asked person (B:person_id) for the key (C:key_id),
    person (A:person_id) has attacked person (B:person_id),

    person (A:person_id) is a (D:disadvantage),

    person (A:person_id) thinks that (I:information) is (V:boolean),

    key (A:key_id) can open place (B:place_id),
    key (A:key_id) is (LOCATION:item_location)
    };


type action={
    wait,
    tell person (A:person_id) that (I:information) is (V:boolean),
    ask person (A:person_id) about (I:information),
    ask person (A:person_id) for the key (K:key_id),
    give person (A:person_id) the key (K:key_id),
    go to place (A:place_id),
    ask person (A:person_id) to (B:action),
    attack person (A:person_id),
    pick up the key (K:key_id)
};

expand(2);

<create new input random enum stream "class">;
let my class stream index = <the created stream index>;

<create new input random enum stream "disadvantage">;
let my disadvantage stream index = <the created stream index>;

<create new input random enum stream "item_location">;
let my item location stream index = <the created stream index>;

<create new input random number stream "integer" 1 <amount of persons>>;
let my person stream index = <the created stream index>;

<create new input random number stream "integer" 1 <amount of places>>;
let my place stream index = <the created stream index>;

<create new input random number stream "integer" 1 20>;
let my feature stream index = <the created stream index>;

<create new input random number stream "integer" 0 2000000000>;
let my decision making stream index = <the created stream index>;

let generate the place (PLACE_ID:place_id)=value code
{
    let my place id = value place_id [(PLACE_ID:place_id)];
    <print "generate the place" <my place id> "-" <name of place <my place id>>>;
};

let generate the key (KEY_ID:key_id)=value code
{
    let my key id = value key_id [(KEY_ID:key_id)];
    <print "generate the key" <my key id> "-" <name of key <my key id>>>;
    let the read from stream source stream index = <my place stream index>;
    <read from stream "integer">;
    <print "the key opens the place" <name of place <the read from stream result "integer">>>;
    let my place the key <my key id> opens = <the read from stream result "integer">;

    let the read from stream source stream index = <my item location stream index>;
    <read from stream "item_location">;

    let my location of the key <my key id> = <the read from stream result "item_location">;

    # just for test
    #let my location of the key <my key id> = value item_location in place <my key id>;

    <print "the key is" <my location of the key <my key id>>>;
};

let generate the person (PERSON_ID:person_id)=value code
{
    let my person id = value person_id [(PERSON_ID:person_id)];
    <print "generate the person" <my person id> "-" <name of person <my person id>>>;

    let the read from stream source stream index = <my class stream index>;
    <read from stream "class">;
    let my class of the person <my person id> = <the read from stream result "class">;

    let the read from stream source stream index = <my place stream index>;
    <read from stream "integer">;
    let my place of the person <my person id> = <the read from stream result "integer">;

    let the read from stream source stream index = <my disadvantage stream index>;
    <read from stream "disadvantage">;
    let my disadvantage of the person <my person id> = <the read from stream result "disadvantage">;

    <print <my class of the person <my person id>> <name of person <my person id>> "is in" <name of place <my place of the person <my person id>>>>;
    <print "he is a" <my disadvantage of the person <my person id>>>;
};

<generate the place (PLACE_ID:place_id)>;
<generate the person (PERSON_ID:person_id)>;
<generate the key (KEY_ID:key_id)>;


