ds2.1.1/bin/
ds2.1.1/extra/wolfpaw/
ds2.1.1/lib/cmds/admins/
ds2.1.1/lib/cmds/common/
ds2.1.1/lib/cmds/creators/include/
ds2.1.1/lib/cmds/creators/include/SCCS/
ds2.1.1/lib/daemon/services/
ds2.1.1/lib/doc/
ds2.1.1/lib/doc/efun/all/
ds2.1.1/lib/doc/efun/arrays/
ds2.1.1/lib/doc/efun/buffers/
ds2.1.1/lib/doc/efun/compile/
ds2.1.1/lib/doc/efun/floats/
ds2.1.1/lib/doc/efun/functions/
ds2.1.1/lib/doc/efun/general/
ds2.1.1/lib/doc/efun/mixed/
ds2.1.1/lib/doc/efun/numbers/
ds2.1.1/lib/doc/efun/parsing/
ds2.1.1/lib/doc/faq/
ds2.1.1/lib/doc/hbook/
ds2.1.1/lib/doc/help/classes/
ds2.1.1/lib/doc/lpc/basic/
ds2.1.1/lib/doc/lpc/concepts/
ds2.1.1/lib/doc/lpc/constructs/
ds2.1.1/lib/doc/lpc/etc/
ds2.1.1/lib/doc/lpc/intermediate/
ds2.1.1/lib/doc/lpc/types/
ds2.1.1/lib/doc/misc/
ds2.1.1/lib/doc/old/
ds2.1.1/lib/domains/Ylsrim/
ds2.1.1/lib/domains/Ylsrim/adm/
ds2.1.1/lib/domains/Ylsrim/armor/
ds2.1.1/lib/domains/Ylsrim/broken/
ds2.1.1/lib/domains/Ylsrim/fish/
ds2.1.1/lib/domains/Ylsrim/meal/
ds2.1.1/lib/domains/Ylsrim/npc/
ds2.1.1/lib/domains/Ylsrim/obj/
ds2.1.1/lib/domains/Ylsrim/virtual/
ds2.1.1/lib/domains/Ylsrim/weapon/
ds2.1.1/lib/domains/campus/adm/
ds2.1.1/lib/domains/campus/etc/
ds2.1.1/lib/domains/campus/meals/
ds2.1.1/lib/domains/campus/npc/
ds2.1.1/lib/domains/campus/txt/ai/charles/
ds2.1.1/lib/domains/campus/txt/ai/charles/bak2/
ds2.1.1/lib/domains/campus/txt/ai/charles/bak2/bak1/
ds2.1.1/lib/domains/campus/txt/ai/charly/
ds2.1.1/lib/domains/campus/txt/ai/charly/bak/
ds2.1.1/lib/domains/campus/txt/jenny/
ds2.1.1/lib/domains/default/creator/
ds2.1.1/lib/domains/default/doors/
ds2.1.1/lib/domains/default/etc/
ds2.1.1/lib/domains/default/weap/
ds2.1.1/lib/domains/town/doors/
ds2.1.1/lib/domains/town/txt/
ds2.1.1/lib/domains/town/txt/shame/
ds2.1.1/lib/domains/town/virtual/
ds2.1.1/lib/lib/comp/
ds2.1.1/lib/lib/lvs/
ds2.1.1/lib/lib/user/
ds2.1.1/lib/lib/virtual/
ds2.1.1/lib/log/
ds2.1.1/lib/obj/book_source/
ds2.1.1/lib/obj/include/
ds2.1.1/lib/realms/template/
ds2.1.1/lib/realms/template/area/armor/
ds2.1.1/lib/realms/template/area/npc/
ds2.1.1/lib/realms/template/area/obj/
ds2.1.1/lib/realms/template/area/room/
ds2.1.1/lib/realms/template/area/weap/
ds2.1.1/lib/realms/template/bak/
ds2.1.1/lib/realms/template/cmds/
ds2.1.1/lib/save/kills/o/
ds2.1.1/lib/secure/cfg/
ds2.1.1/lib/secure/cfg/classes/
ds2.1.1/lib/secure/cfg/races/SCCS/
ds2.1.1/lib/secure/cmds/creators/include/
ds2.1.1/lib/secure/cmds/players/
ds2.1.1/lib/secure/cmds/players/include/
ds2.1.1/lib/secure/daemon/include/
ds2.1.1/lib/secure/lib/
ds2.1.1/lib/secure/lib/include/
ds2.1.1/lib/secure/lib/net/
ds2.1.1/lib/secure/lib/net/include/
ds2.1.1/lib/secure/lib/std/
ds2.1.1/lib/secure/modules/
ds2.1.1/lib/secure/npc/
ds2.1.1/lib/secure/obj/include/
ds2.1.1/lib/secure/room/
ds2.1.1/lib/secure/save/
ds2.1.1/lib/secure/save/boards/
ds2.1.1/lib/secure/verbs/creators/
ds2.1.1/lib/shadows/
ds2.1.1/lib/spells/
ds2.1.1/lib/verbs/admins/include/
ds2.1.1/lib/verbs/common/
ds2.1.1/lib/verbs/common/include/
ds2.1.1/lib/verbs/creators/
ds2.1.1/lib/verbs/creators/include/
ds2.1.1/lib/verbs/players/include/SCCS/
ds2.1.1/lib/verbs/rooms/
ds2.1.1/lib/verbs/rooms/include/
ds2.1.1/lib/www/errors/
ds2.1.1/lib/www/images/
ds2.1.1/v22.2b14/
ds2.1.1/v22.2b14/ChangeLog.old/
ds2.1.1/v22.2b14/Win32/
ds2.1.1/v22.2b14/compat/
ds2.1.1/v22.2b14/compat/simuls/
ds2.1.1/v22.2b14/include/
ds2.1.1/v22.2b14/testsuite/
ds2.1.1/v22.2b14/testsuite/clone/
ds2.1.1/v22.2b14/testsuite/command/
ds2.1.1/v22.2b14/testsuite/data/
ds2.1.1/v22.2b14/testsuite/etc/
ds2.1.1/v22.2b14/testsuite/include/
ds2.1.1/v22.2b14/testsuite/inherit/
ds2.1.1/v22.2b14/testsuite/inherit/master/
ds2.1.1/v22.2b14/testsuite/log/
ds2.1.1/v22.2b14/testsuite/single/
ds2.1.1/v22.2b14/testsuite/single/tests/compiler/
ds2.1.1/v22.2b14/testsuite/single/tests/efuns/
ds2.1.1/v22.2b14/testsuite/single/tests/operators/
ds2.1.1/v22.2b14/testsuite/u/
ds2.1.1/v22.2b14/tmp/
ds2.1.1/win32/
#include <lib.h>
#include <save.h>
#include <privs.h>
#include "/daemon/include/races.h"

inherit LIB_NPC;

string firstchoice, secondchoice,mm, vv, printvar;
string response,s1,s2,s3;
object ww;
int playing,runs,switches,stays,percent;
int fred,fgreen,fblue;
int wins,red_wins,green_wins,blue_wins;

static void create() {
    npc::create();
    SetKeyName("charly");
    SetId(({"charly"}));
    SetShort("Charly");
    SetLong("Charly is a test subject in unethical artificial "
      "intelligence experiments. If he were smart "
      "enough, he'd resent his forced servitude and "
      "lack of rights. Dangerously, his overlords "
      "are trying to make him smarter.");
    SetLevel(5);
    SetRace("human");
    SetGender("male");
    SetNoClean(1);
    playing = 0;
    response = "";
    runs = to_int(read_file("/domains/campus/txt/ai/charly/runs"));
    switches = to_int(read_file("/domains/campus/txt/ai/charly/switches"));
    stays = to_int(read_file("/domains/campus/txt/ai/charly/stays"));
    percent = to_int(read_file("/domains/campus/txt/ai/charly/percent"));
    fred = to_int(read_file("/domains/campus/txt/ai/charly/fred"));
    fgreen = to_int(read_file("/domains/campus/txt/ai/charly/fgreen"));
    fblue = to_int(read_file("/domains/campus/txt/ai/charly/fblue"));
    wins = to_int(read_file("/domains/campus/txt/ai/charly/wins"));
    red_wins = to_int(read_file("/domains/campus/txt/ai/charly/red_wins"));
    green_wins = to_int(read_file("/domains/campus/txt/ai/charly/green_wins"));
    blue_wins = to_int(read_file("/domains/campus/txt/ai/charly/blue_wins"));
}

int eventBeginPlay(){
    int run;
    run = runs+1;
    firstchoice = "";
    response = "";
    playing = 1;
    eventForce("say If successful, this will be run "+run+".");
    eventForce("say out of "+runs+" runs, I have ");
    eventForce("say switched "+switches+" times, and ");
    eventForce("say stayed "+stays+" times.");
    eventForce("say my first choices have been: ");
    eventForce("say red: "+fred+" green: "+fgreen+" blue: "+fblue);
    eventForce("say the winners have been: ");
    eventForce("say red: "+red_wins+" green: "+green_wins+" blue: "+blue_wins);
    eventForce("say I have won "+wins+" times.");
    write_file("/domains/campus/txt/ai/charly/runs",""+runs,1);
    write_file("/domains/campus/txt/ai/charly/switches",""+switches,1);
    write_file("/domains/campus/txt/ai/charly/stays",""+stays,1);
    write_file("/domains/campus/txt/ai/charly/percent",""+percent,1);
    write_file("/domains/campus/txt/ai/charly/fred",""+fred,1);
    write_file("/domains/campus/txt/ai/charly/fgreen",""+fgreen,1);
    write_file("/domains/campus/txt/ai/charly/fblue",""+fblue,1);
    write_file("/domains/campus/txt/ai/charly/wins",""+wins,1);
    write_file("/domains/campus/txt/ai/charly/red_wins",""+red_wins,1);
    write_file("/domains/campus/txt/ai/charly/green_wins",""+green_wins,1);
    write_file("/domains/campus/txt/ai/charly/blue_wins",""+blue_wins,1);
    eventForce("push button on pedestal");
    return 1;
}

int choice1(){
    int genrand;
    float percent_switch, percent_wins;

    eventForce("say I am faced with choice 1.");
    genrand = random(256);
    if(!genrand || genrand == 0){
	eventForce("say I cannot make up my mind right now.");
	eventForce("say I will start over.");
	playing = 0;
	return 1;
    }
    if(runs > 20){

	percent_switch = percent(switches,runs);
	percent_wins = percent(wins,runs);
	eventForce("say My win rate is "+percent_wins+"%.");
	eventForce("say My switch rate is "+percent_switch+"%.");
    }
    genrand = genrand % 3;
    if(genrand == 1) { firstchoice = "red"; fred++; }
    if(genrand == 2) { firstchoice = "green"; fgreen++; }
    if(genrand == 0) { firstchoice = "blue"; fblue++; }
    eventForce("say I choose the "+firstchoice+" door");
    eventForce("choose "+firstchoice+" door");
    return 1;
}

int choice2(string str){
    int genrand,which;
    eventForce("say I am faced with choice 2.");
    genrand = random(100);
    which = genrand % 2;
    if(which == 1) {
	switches++;
	response = "switch";
    }
    else {
	stays++;
	response = "stay";
    }

    if(sscanf(str,"%sswitch to the %s %s",s1,s2,s3) > 0) {
	secondchoice = s2;
    }

    eventForce("say I decide to "+response+".");
    //eventForce("say gespielen is: "+playing);
    return 1;
}

int WinFun(string str){
    if(sscanf(str,"%smay enter the %s room %s",s1,s2,s3) > 0){
	if(s2 == "red") red_wins++;
	if(s2 == "green") green_wins++;
	if(s2 == "blue") blue_wins++;
	wins++;
	eventForce("say w00t! "+s2+" wins!");
	return 1;
    }
    return 0;
}

int LoseFun(string str){
    string foo;
    if(sscanf(str,"%smay enter the %s room%s",s1,s2,s3) > 0){
	if(response == "stay") foo = secondchoice;
    }
    eventForce("say "+firstchoice+" wins, I guess.");
    if(firstchoice == "red") red_wins++;
    else if(firstchoice == "green") green_wins++;
    else if(firstchoice == "blue") blue_wins++;
    else eventForce("say WTF? foo is "+firstchoice);
    return 1;
}

int eventPedestalParse(string str){
    if(sscanf(str,"%schoose one door from%s",s1,s2) > 0) choice1();
    if(sscanf(str,"%sI have opened%s",s1,s2) > 0) choice2(str);
    if(sscanf(str,"%sminor glitch%s",s1,s2) > 0) playing = 0;
    if(sscanf(str,"%sYou win%s",s1,s2) > 0) WinFun(str);
    if(sscanf(str,"%sYOU LOOOOOSE%s",s1,s2) > 0) LoseFun(str);
    return 1;
}


int eventFirstPass(string str){
    if(!str || str == "") return 0;
    if(sscanf(str,"A voice from the pedestal%s",s1) > 0){
	eventPedestalParse(str);
	return 1;
    }
    return 0;
}

private void eventPrint(string str1, string str2);

void init(){
    set_heart_beat(1);
    SetNoClean(1);
}
void receive_message(string string1, string string2){
    //tell_object(find_player("testylus"),"CHARLY: "+string2);
    eventFirstPass(string2);
}
varargs mixed eventHearTalk(object who, object target, int cls, string verb,
  string msg, string lang) {
    ww=who;
    vv=verb;
    mm=msg;
    unguarded((: this_object()->receive_message("me",ww->GetName()+" "+vv+"s: "+mm) :));
    return;
}
int eventPrint(string msg, string msg_class){
    printvar=msg;
    unguarded((: this_object()->receive_message("me again",printvar) :));
}

void heart_beat(){
    //eventForce("say playing is: "+playing);
    if(playing && response != "" ) {
	if(firstchoice != ""){
	    //eventForce("say response is: "+response);
	    eventForce(response);
	    runs ++;
	    //playing = 0;
	}
	//else eventBeginPlay();
	playing = 0;
    }

    if(!playing){
	//eventForce("say playing is zero, restarting.");
	eventBeginPlay();
    }
}