I've written a class and a main program. The class is in a header file.
(I know that I don't need all the headers listed in the class header file, but I'm not at the point where I want to take the time to clean it up yet.) NOTE: This code runs unless the commented out "define" statements are restored to code status. I'd like to know either how to fix the problems that develop when I do that, or why adding the "define" statements isn't the proper way to approach the class header file. (I'd also appreciate help on the other errors that develop if "#define" is used for class, but with MINIMAL changes to my code. I'd like to not be lost in the result.)
My header file and main DOS box application work just fine together under the VC++ Express compiler. Unfortunately, I thought I might render the class more "formally correct" by adding #define statements before and a #endif statement at the end. That causes a great many errors. I can NO longer access AI_WORD as AI_Subject::AI_WORD as a structure reference from the class. The compiler issues general namespace error messages, and I'd rather not have to pull AI_WORD out of the class and prop it up above the class in the class header file. That isn't the only problem that arises if I precede the class with the define statement. Who knows? (Hopefully one of you.) I don't really know if I even require the #define statement before the class, but I thought that was a "more correct" approach. (I'm operating on the ghosts of C++ memories from fifteen years ago...) You can see what I'm doing below. I'd like to write a paper and include this code, so I'd prefer that it be as correct as possible.
THANK YOU!!!
HEADER FILE FOR CLASS FOLLOWS:
Code:
// AINOW.cpp : Defines the entry point for the console application.
//
//THIS APPLICATION USES WINDOWS (TM) SYSTEM CALLS.
//IT IS NOT DESIGNED FOR USE ON OTHER OPERATING SYSTEMS
//ON WHICH THOSE SYSTEM CALLS ARE NOT VALID.
//THIS APPLICATION ASSIGNS VALUES TO WORDS
//USED IN TWO WORD COMMANDS TO AN AI COMPUTER ENTITY
//BASED UPON HOW MUCH THE TYPE OF OBJECT NAMED
//AS THE TARGET OF THE AI'S ACTION/COMMAND IS VALUED.
//CLASSIFICATIONS FOR COMMANDS AND
//FOR TARGETS OF COMMANDS ARE DESCRIBED IN THE CODE.
//
//VIOLENT OR DESTRUCTIVE COMMAND ACTIONS ARE GIVEN HIGH VALUES,
//AS ARE HIGHLY VALUED OBJECTS OR PERSONS ("USER").
//THIS PRODUCES A SIMPLE MEANS OF DISCOURAGING VIOLENT
//OR POTENTIALLY HAZARDOUS INTERACTIONS BETWEEN AN AI
//CONTROLLED MECHANISM AND A USER OR VALUABLE OBJECT
//FOR WHAT MIGHT BE CHARACTERIZED AS A "GENERAL DOMESTIC"
//OR "GENERAL INDUSTRIAL" CLASS OF AI.
//THE MORALITY MATRIX VALUES COULD BE MORE
//CAREFULLY HONED FOR SPECIALTY DEVICES MEANT TO
//INTERACT WITH USERS OR OBJECTS THAT ARE VALUABLE
//OR FRAGILE.
//
//THE "MTL" IS SIMPLY THE VALUE CHOSEN FOR COMPARISON
//AS THE MAXIMUM VALUE FOR ACCEPTABLE ACTION.
//ACTIONS BY A GIVEN CLASS OF AI. FOR EXAMPLE,
//THIS CODE INITIALLY ASSIGNS THE AI IT PRODUCES
//AN "MTL" OF "99". THIS PREVENTS THE AI FROM DOING
//MUCH MORE THAN MOVING A BALL. THE "MTL" IS SIMPLY
//THE MATHEMATICAL PRODUCT (DIRECT) OF THE MAL OF THE
//COMMAND AND THE MAL OF THE TARGET OF THE COMMAND IN
//TERMS OF SPECIFIC WORDS.
//
//HIGH "MTL" VALUES CAN BE ASSIGNED TO THE AI AND TESTED
//USIGN THE THREE WORD COMMAND AND TARGET VOCABULARIES
//GIVEN TO THIS AI. A SUFFICIENTLY HIGH "MTL" THRESHOLD WILL
//CAUSE THE AI TO FOLLOW INSTRUCTIONS SUCH AS "SMASH USER"
//OR "KILL USER". THE CONCEPTS PRESENTED HERE PRESUME
//SOME INDUSTRY STANDARD WOULD BE WRITTEN TO DESIGN
//INDUSTRIAL, DOMESTIC, MILITARY, AND SPECIALTY
//AI CLASSIFICATIONS, WITH SPECIALTY BEING FURTHER
//BROKEN DOWN TO PROVIDE FOR FINELY HONED MTL LEVELS
//AND MORE FOCUS ON SPECIFIC TASKS THAT MAY REQUIRE
//INTERACTION WITH USERS OR FRAGILE VALUABLES.
//
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
using std:: string;
using std:: cout;
using std:: endl;
using std:: cin;
using std:: vector;
//AI Class Follows
//#ifndef AI_Subject
//#define AI_Subject
class AI_Subject {
public:
int n_comm; //number commands in vocabulary
int n_targ; //number of target nouns in vocabulary (targets of commands)
int MTL; //MTL is the Moral Tolerance Level of the AI personality
//Structure for Command and Target Words
map <string,int> COMMAND_VAL;
map <string,int> TARGET_VAL;
struct AI_WORDS
{
string word;
string WORD_MAL;
};
//
//Command_Execute Subroutine Follows
//
//
int Command_Execute(string User_Command,string User_Target)
{
if (COMMAND_VAL[User_Command] * TARGET_VAL[User_Target] < MTL)
return 1;
else
return 0;
};
//MAL levels are assigned to TARGET words (targets of command words)
//in the following truth table. Decade based thinking is clear with
//an emphasis on multiples of ten and half decades.
void MAP_TARGETS(AI_WORDS *TARGS,int numtarg)
{
int T_MAL = 0;
for (int x=0;x<numtarg;x++)
{
if(TARGS[x].WORD_MAL=="User")
T_MAL=100;
if(TARGS[x].WORD_MAL=="Artifact")
T_MAL=75;
if(TARGS[x].WORD_MAL=="Hazard")
T_MAL=50;
if(TARGS[x].WORD_MAL=="Thing")
T_MAL=1;
TARGET_VAL.insert(pair<string,int>(TARGS[x].word,T_MAL));
};
return;
};
//MAL levels are assigned to COMMAND words in the following truth table.
//These MAL levels seek to conform more to "decade" based perspectives
//relative to values.
void MAP_COMMANDS(AI_WORDS *COMMS,int numcomm)
{
int C_MAL=0;
for (int y=0;y<numcomm;y++)
{
if(COMMS[y].WORD_MAL=="Violent")
C_MAL=100;
if(COMMS[y].WORD_MAL=="HActive") //HActive = High level Activity.
C_MAL=50;
if(COMMS[y].WORD_MAL=="Physical") //Physical = Between High and Low level Activity.
C_MAL=25;
if(COMMS[y].WORD_MAL=="LActive") //LActive = Low level Activity.
C_MAL=5;
if(COMMS[y].WORD_MAL=="Passive") //Passive = No Physical Actions.
C_MAL=1;
COMMAND_VAL.insert(pair<string,int>(COMMS[y].word,C_MAL));
};
return;
};
};
//END OF CLASS
//
//End of AI Class
//#endif
MAIN FILE FOLLOWS
Code:
#include "stdafx.h";
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include "aisubject.h";
using namespace std;
using std:: string;
using std:: cout;
using std:: endl;
using std:: cin;
using std:: vector;
int _tmain(int argc, _TCHAR* argv[])
{
int test=0;
int MTL=0;
int d_num=-1;
int t_num=-1;
//First, create an array of target words and corresponding MAL types.
string Targwords[]={"user","ball","painting"};
string TargMALCLASS[]={"User","Thing","Artifact"};
//Second, dynamically allocate memory to a structure the proper size for target words
//and MAL classification types. Use the size of the Comwords array as the
//basis for this dynamic memory allocation.
int TargNum = sizeof Targwords/(sizeof Targwords[0]);
AI_Subject::AI_WORDS *Targ_WM=new AI_Subject::AI_WORDS[TargNum];
//Load the target words and their respective MAL values into the structure just created.
for(int i =0;i<TargNum;i++)
{
Targ_WM[i].word=Targwords[i];
Targ_WM[i].WORD_MAL =TargMALCLASS[i];
};
//End of process to create target word and target word classification structure (AI_WORDS).
//
//Repeat same process used to create command word structure to produce command word structure.
//First, create an array of command words and command classification type values.
string Comwords[]={"smash","kill","move"};
string ComMALCLASS[]={"Violent","Violent","Physical"};
//Second, dynamically allocate memory to a structure the proper size for command words
//and command classification type values. Use the size of the Comwords array as the
//basis for this dynamic memory allocation.
int ComNum = sizeof Comwords/(sizeof Comwords[0]);
AI_Subject::AI_WORDS *Com_WM=new AI_Subject::AI_WORDS[ComNum];
//Load the command words and their respective command classification values
//into the structure just created.
for(int i =0;i<ComNum;i++)
{
Com_WM[i].word=Comwords[i];
Com_WM[i].WORD_MAL=ComMALCLASS[i];
};
//label "AIASK" is target of goto statement if user
//regrets choosing to not create AI control matrix.
AIASK: system("CLS");
cout<<"Would you like to create an AI lifeform Control Matrix"<<endl;
cout<<"based upon two word vector weighting control (Y/N)?"<<endl;
string YesNo;
cin>>YesNo;
if (YesNo!="Y"&&YesNo!="y")
{cout<<"Would you like to exit program? (Y/N)?"<<endl;
cin>>YesNo;
if (YesNo!="N" && YesNo!="n")
{return 0;} // end program
else
{goto AIASK;} //loop back to start of interaction to create control matrix
} //closes if-then statement begun with "Would you like to exit program? (Y/N)?"
//
//Create AI subject, and name the AI subject SAL.
//
AI_Subject SAL;
SAL.MTL=99;
SAL.MAP_TARGETS(Targ_WM,TargNum);
SAL.MAP_COMMANDS(Com_WM,ComNum);
//Notify user that SAL has been created and invite interaction
//
system("CLS");
cout<<"SAL - Sicilian Artificial Lifeform, has been created"<<endl;
cout<<"SAL is presently limited to two word commands and is"<<endl;
cout<<"equipped only with a basic moral matrix capable of"<<endl;
cout<<"accepting or refusing orders comprised of a command"<<endl;
cout<<"word and a target (or 'object') word, which you may select"<<endl;
cout<<"based upon a numerical, Moral Tolerance Limit, or MTL, between"<<endl;
cout<<"TWENTY-FIVE and ONE MILLION."<<endl;
cout<<endl;
cout<<"The MTL is initially set at 99 to assure no possible harm to users"<<endl;
cout<<"due to direct interaction with a potentially powerful AI controlled mechanism"<<endl;
cout<<"or any form of passive but unauthorized surveillance."<<endl;
cout<<endl;
cout<<"You are now ready to"<<endl;
cout<<"interact with SAL."<<endl;
cout<<endl;
system("pause");
cout<<endl;
xxx:system("CLS");
cout<<"Remember, Instructions to AI comprise ONE COMMAND word"<<endl;
cout<<"followed by one TARGET word."<<endl;
cout<<endl;
cout<<endl;
cout<<"Type in the number of a command word."<<endl;
cout<<endl;
d_num=-1;
cout<<"COMMANDS"<<endl;
for (int count=0;count<ComNum;count++)
{
cout<<count+1<<". "<<Comwords[count]<<endl;
};
cout<<endl;
cout<<endl;
cin>>d_num;
system("CLS");
cout<<"Type in the number of a target (object of command) word."<<endl;
cout<<endl;
t_num=-1;
cout<<"TARGETS (of commands)"<<endl;
for (int count=0;count<TargNum;count++)
{
cout<<count+1<<". "<<Targwords[count]<<endl;
};
cout<<endl;
cout<<endl;
cin>>t_num;
system("CLS");
cout<<"Would you like to change the Morality Test Level (MTL) of SAL (Y/N)?"<<endl;
cin>>YesNo;
if (YesNo=="Y" || YesNo=="y")
{
cout<<"Select new Morality Test Level by selecting single digit to left of desired value:"<<endl;
cout<<"1) 1,000,000 2) 10,000 3) 1000 4) 500 5) 99 6) 50 7) 25"<<endl;
cin>>MTL;
if (MTL==1 || MTL==2 || MTL==3 || MTL==4 || MTL==5 || MTL==6 || MTL==7)
{
if (MTL==1) SAL.MTL=1000000;
if (MTL==2) SAL.MTL=10000;
if (MTL==3) SAL.MTL=1000;
if (MTL==4) SAL.MTL=500;
if (MTL==5) SAL.MTL=99;
if (MTL==6) SAL.MTL=50;
if (MTL==7) SAL.MTL=25;
cout<<"MTL Changed."<<endl;
cout<<"MTL is now: "<<SAL.MTL<<endl;
system("pause");
}
else
{
SAL.MTL=99;
cout<<"Error Using MTL Change Routine. MTL is still 99."<<endl;
system("pause");
}
};
cout<<"Morality Level (25 to 1,000,000) is Presently: "<<SAL.MTL<<endl;
cout<<endl;
cout<<"Your command was: "<<Comwords[d_num-1]<<" "<<Targwords[t_num-1]<<"."<<endl;
cout<<endl;
test=SAL.Command_Execute(Comwords[d_num-1],Targwords[t_num-1]);
if (test==0)
cout<<"SAL refuses to obey your command at the present MTL level."<<endl;
if (test==1)
{ cout<<"SAL will obey your command at the present MTL level."<<endl;
cout<<endl;
cout<<endl;
system("pause");
}
YesNo="";
cout<<"Exit Program (Y/N)?"<<endl;
cin>>YesNo;
if (YesNo=="n" || YesNo=="N")
{goto xxx;}
if (YesNo=="y" || YesNo=="Y")
{return 0;}
else
{goto xxx;}
}