VB icon

AI_Attempt

Email
Submitted on: 1/4/2015 11:40:00 PM
By: Donny Beals (from psc cd)  
Level: Advanced
User Rating: By 6 Users
Compatibility: Microsoft Visual C++
Views: 1092
 
     Attempts to simulate AI. This is my very first time trying to make an AI, so please vote.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :AI_Attempt
//**************************************
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: AI_Attempt
// Description:Attempts to simulate AI. This is my very first time trying to make an AI, so please vote.
// By: Donny Beals (from psc cd)
//
// Inputs:The enter button.
//
// Returns:The status of the AI.
//**************************************

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#include <time.h>
enum States{ Hungry = 0,Diseased,Wandering,Dead,Searching,Found=5};
class g_StateManager
{
public:
	char Current[35];
	States sCurrent;
	States Determiner;
}SM;
static int Count = -1;
void StateChange(States* Dtrmnr = &SM.Determiner);
void StateDisplay();
void DisplayDeadMessage();
int r;
int main()
{
	SM.sCurrent = Wandering;
	SM.Determiner = Wandering;
	while(SM.sCurrent != Dead)
	{
		StateChange();
		StateDisplay();
		getch();
	}
	return 0;
}
void StateChange(States* Dtrmnr)
{
	switch(*Dtrmnr)
	{
		case Hungry:
			srand((unsigned)time(NULL));
			r = rand() % 2;
			switch(r)
			{
			case 0:
				strcpy(SM.Current,"Searching for food...");
				SM.sCurrent = Searching;
				SM.Determiner = Searching;
				Count++;
				return;
				break;
			case 1:
				strcpy(SM.Current,"Dead");
				SM.sCurrent = Dead;
				SM.Determiner = Dead;
				Count++;
				return;
				break;
			}
			return;
			break;
		case Diseased:
			srand((unsigned)time(NULL));
			r = rand() % 2;
			switch(r)
			{
			case 0:
				strcpy(SM.Current,"Looking for cure...");
				SM.sCurrent = Searching;
				SM.Determiner = Searching;
				Count++;
				return;
				break;
			case 1:
				strcpy(SM.Current,"Dead");
				SM.sCurrent = Dead;
				SM.Determiner = Dead;
				Count++;
				return;
				break;
			}
			return;
			break;
		case Wandering:
			r = rand() % 2;
			switch(r)
			{
			case 0:
				strcpy(SM.Current,"I'm hungry...");
				SM.sCurrent = Hungry;
				SM.Determiner = Hungry;
				Count++;
				return;
				break;
			case 1:
				strcpy(SM.Current,"Now I have something to search for!");
				SM.sCurrent = Searching;
				SM.Determiner = Searching;
				Count++;
				return;
				break;
			}
			return;
			break;
		case Searching:
			srand((unsigned)time(NULL));
			r = rand() % 2;
			switch(r)
			{
			case 0:
				strcpy(SM.Current,"Still searching...");
				SM.sCurrent = Searching;
				SM.Determiner = Searching;
				Count++;
				return;
				break;
			case 1:
				strcpy(SM.Current,"Found it!");
				SM.sCurrent = Found;
				SM.Determiner = Found;
				Count++;
				return;
				break;
			}
			return;
			break;
		case Found:
			srand((unsigned)time(NULL));
			r = rand() % 2;
			switch(r)
			{
			case 0:
				strcpy(SM.Current,"I'm hungry!");
				SM.sCurrent = Hungry;
				SM.Determiner = Hungry;
				Count++;
				return;
				break;
			case 1:
				strcpy(SM.Current,"I don't feel so good!");
				SM.sCurrent = Diseased;
				SM.Determiner = Diseased;
				Count++;
				return;
				break;
			}
			break;
		default:
			strcpy(SM.Current,"Dead");
			SM.sCurrent = Dead;
			return;
			break;
	}
	return;
}
void StateDisplay()
{
	system("CLS");
	cout<<"Current state:"<<SM.Current<<endl;
	cout<<"Current state:"<<SM.sCurrent<<endl;
	cout<<"State changes:"<<Count<<endl;
	return;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.