Jump to content
  • Advertisement
Sign in to follow this  
SSJCORY

Is this considered AI?

This topic is 5459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Would this be considered a basic example of artificial intelligence? Specific section.
while(player1.isAlive() == true){
		for(int i = 0; i < monsters.size();i++){
			cout<<monsters.getName()<<" "<<monsters.getX()<<","<<monsters.getY()<<endl;
			if(monsters.getX() < player1.getX()){
				monsters.right();
			}
			if(monsters.getX() > player1.getX()){
				monsters.left();
			}
			if(monsters.getX() == player1.getX()){
				if(monsters.getY() < player1.getY()){
					monsters.up();
				}
				if(monsters.getY() > player1.getY()){
					monsters.down();
				}
			}
			if(monsters.getY() == player1.getY()){
				if(monsters.getX() == player1.getX()){
					player1.die();
					cout<<monsters.getName()<<endl;
					break;
				}
			}
		}
	}

FULL SOURCE
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class cMonster;
vector<cMonster> monsters;
class cMonster{
private:
	int x;
	int y;
	string name;
public:
	cMonster(string newname,int newx,int newy){
		name = newname;
		x = newx;
		y = newy;
	}
	int getX(){
		return x;
	}
	void setX(int newx){
		x = newx;
	}
	int getY(){
		return y;
	}
	void setY(int newy){
		y = newy;
	}
	string getName(){
		return name;
	}
	void up(){
		y++;
	}
	void down(){
		y--;
	}
	void left(){
		x--;
	}
	void right(){
		x++;
	}
};
class cPlayer{
private:
	int x;
	int y;
	bool alive;
	string name;
public:
	cPlayer(string newname,int newx, int newy){
		alive = true;
		name = newname;
		x = newx;
		y = newy;
	}	
	int getX(){
		return x;
	}
	int getY(){
		return y;
	}
	void setX(int newx){
		x = newx;
	}
	void setY(int newy){
		y = newy;
	}
	void die(){
		cout<<"You have been killed by ";
		alive = false;
	}
	bool isAlive(){
		return alive;
	}
};
int main(){
	string pname = "";
	monsters.push_back(cMonster("Alex",10,10));
	monsters.push_back(cMonster("Raymond",5,5));
	cout<<"What is your name?";
	cin>>pname;
	cPlayer player1(pname,5,10);
	while(player1.isAlive() == true){
		for(int i = 0; i < monsters.size();i++){
			cout<<monsters.getName()<<" "<<monsters.getX()<<","<<monsters.getY()<<endl;
			if(monsters.getX() < player1.getX()){
				monsters.right();
			}
			if(monsters.getX() > player1.getX()){
				monsters.left();
			}
			if(monsters.getX() == player1.getX()){
				if(monsters.getY() < player1.getY()){
					monsters.up();
				}
				if(monsters.getY() > player1.getY()){
					monsters.down();
				}
			}
			if(monsters.getY() == player1.getY()){
				if(monsters.getX() == player1.getX()){
					player1.die();
					cout<<monsters.getName()<<endl;
					break;
				}
			}
		}
	}
	return 0;
}


The way the monster tracks the player down. Is that ai?

Share this post


Link to post
Share on other sites
Advertisement
i dont know at which point you can speak of AI but i would say its a veeery basic AI. the enemy always walks to the player no matter what. (maybe i'm wrong i just scrolled through your code.) its not really intelligent but i think AI is a very general term... i wouldnt speak of ai when an enemy does only x++ but i dont know where stupid ends and intelligence begins... maybe someone knows the exact definition... i would be interested, too... for my tictactoe concole game i had a function called uberAI()... i wonder if this function deserved that name :)

Share this post


Link to post
Share on other sites
So if he had to make a decision of wether to go left or right to get to a player if there were roadblocks would that be ai?

Share this post


Link to post
Share on other sites
i would say yes... but i'm not an expert.. i'm still waiting for someone to show up and give us the exact definition of ai... maybe i should try to use google but i'm lazy and i should go learn physics because i was stupid enough to agree that i would be a tutor for the new 1st semester ppl :/
i'm still wondering why we have to learn physics as software engineers.... but thats off topic...
AI... i would call something AI as soon as it reacts on things and choses from different options according to the things that happen.

Share this post


Link to post
Share on other sites
Quote:
Original post by BiGF00T
i would say yes... but i'm not an expert.. i'm still waiting for someone to show up and give us the exact definition of ai...
I wouldn't be surprised that if someone did suggest a definition, a debate would start over it. There tends to be a division often times on subjects like this between those who are more "academic", and those who are more "real world". (Note that I put quotes around those 'cause I don't mean them to be as literal as they sound. But they get the idea across.) From a standard ol' run-of-the-mill game programmer's perspective, I'd say, sure, it's AI. It's simple, but it does fill the role of AI.

Share this post


Link to post
Share on other sites
It's a start though. I'd call it a strategy (2d homing strategy) rather than an AI. Next aim towards an AI which has several strategies available (homing, retreating, resting, etc.) and have your AI select what to do based on the world info and the monsters disposition (nearly dead, angry, etc.).

Share this post


Link to post
Share on other sites
OH cool I see what your saying. Add health and if the monsters healths are low they run away from you. If they are mad they chase you. If they are REALLY PISSED or REALLY NASTY monsters then they chase you twice as fast. If they are smart they communicate with other monsters to trap you. Like that? ALso maybe like include battle experience the more experienced monsters will attack more often than the non-experienced ones.

Share this post


Link to post
Share on other sites
Exactly. Try to seperate the strategies into functions that all monsters can call, such as Homing, RunningAway, etc. Then each monster needs to work out which strategy to apply (i.e. function to call) based on its own state. I'll leave you to work out how to do that on your own.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!