Archived

This topic is now archived and is closed to further replies.

Capture the Flag AI

This topic is 4960 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

Does anyone have any ideas on how to help me with AI for my capture the falag game made with the vcl in borland c++ builder. I could just go off and do it, but I want to see if anyone has a better idea on how to do this, because I have never made an actual AI before that is not random and that has many different difficulty levels...can someone help me out...the game is 2d, not 3d and someone who has made games with the borland vcl should know that its not the greatest, but hey, could ya let me know how to mkae ai in borland c++ builder....im a beginner at ai, so I kinda need some help.. C++ Programmer AIM - GT70sgt Lead Guitar in Distorted Play

Share this post


Link to post
Share on other sites
well, the way i would attempt it is map out 3 paths for each level, and evertime a enemy spawns it randomly chooses a path.
Paths:
1.Recon: Goes out to get flag, doesnt initiate conflift with user, but if attacked and hit more then once stops running, fires at user, and continues towards flag. Then obviously runs back to base once flag is obtained, without stopping even if in firefight.
2.Defensive: Stays within certain radius of flag, and fires at opposite team on sight.
3.Freelance: goes out and hunts other team,

now it would also be prudent to make 2 more paths for each individual path, depending on the amount of NPC''s...

Hoped this helped.!

www.darkism.8m.com

Share this post


Link to post
Share on other sites
that is how I was thinking about going at it, but then I dont know the best way to code this, if you could show me, it might take some typing tho....uhh, do you have an example that i can understand...??

C++ Programmer

AIM - GT70sgt

Lead Guitar in Distorted Play

Share this post


Link to post
Share on other sites
I could try to just go at it, thanks for the help tho, I wasnt thinking exactally that, but something like it, thanks...

C++ Programmer

AIM - GT70sgt

Lead Guitar in Distorted Play

Share this post


Link to post
Share on other sites
First up, developing AI code is no different to developing any other sort of code, in that it is just code. It's what's IN the code that counts. This means, that AI is, in general, independent of the language or compiler used to develop it. C++ will suffice for many forms of game AI that you may want to implement... but ultimately, it depends on the algorithm and data structures you choose.

Anyway, on to the AI discussion...

There are a couple of basic problems that you need to solve in order to implement a game AI.

1) You need to be able to store and retreive the current state of your computer agents.

2) You need a way of updating the state of your computer agents given events that occur in the world (like being shot, falling under gravity, hitting a wall).

3) You need a way of updating the state of your computer agents given their actions (changing weapon, shooting their weapon, getting into a vehicle).

4) You need a way of choosing actions for your computer agents. This can either be done on a per agent basis, or by a 'director' agent that tells every agent where to go and what to do.

5) You need a way for your agents to trigger their decision making. This is generally a combination of observing states and events in the world, observing their own state and wanting to fulfil their desires/drives.


At this stage, I would suggest that you go and acquire some literature on AI and more specifically game AI. You would probably find Alex Champandard's book gives a good coverage of the problems you will face in developing agent's for your game... and plenty of solutions too! Check it out!

Good luck,

Timkin

[edited by - Timkin on May 18, 2004 9:53:51 PM]

Share this post


Link to post
Share on other sites
this is hard, I can't seem to get it. I can get the guy to go to the flag and capture it and go through it again, but he doesnt dodge enemies, or the players bullets, I really need some help with this, wow, its a lot harder than I thought it would be, i guess it just needs practice, and I need some help with that, anyone got any advice...??

if someone here understands borland, here is my source, and my header below

SOURCE CODE

//---------------------------------------------------------------------------


#include <vcl.h>
#pragma hdrstop

#include "capture.h"
//---------------------------------------------------------------------------

#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//declaration globals

struct players {
int points;
bool firing;
int kills;
int deaths;
int direction[4];
bool HasFlag;
bool FField;
int move_speed;
int fire_speed;
int pos[2];
};
players pl_blue;
players pl_red;
players computer;
TPanel* Walls[12];
TImage* Enemies[4];
TImage* Spawn[4];
int enemy_speed = 4, game_type = 0; //<<<might need to change

int EMove[4] = {-1,-1,-1,-1}, type = 0;
int wallcount = 0, ECount = 0, ECollCount = 0;
int difficulty = 0, call = 0;
int GamePoints = 0, counter = 0, s = 0;
bool winner = 0;
//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//bufferes the game **gets rid of flickering**

DoubleBuffered = true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
//set points to lables

blue_points -> Caption = pl_blue.points;
red_points -> Caption = pl_red.points;
blue_deaths -> Caption = pl_blue.deaths;
red_deaths -> Caption = pl_red.deaths;
blue_kills -> Caption = pl_blue.kills;
red_kills -> Caption = pl_red.kills;
//set the forms color

Form1 -> Color = clBlack;
//call to declare function

Declare();
//set pointers for the wall loops

//outside walls

Walls[0] = wall_top;
Walls[1] = wall_bottom;
Walls[2] = wall_right;
Walls[3] = wall_left;
//blue colored walls

Walls[4] = blue_wall_top;
Walls[5] = blue_wall_bottom;
Walls[6] = blue_wall_right;
Walls[7] = blue_wall_left;
//red colored walls

Walls[8] = red_wall_top;
Walls[9] = red_wall_bottom;
Walls[10] = red_wall_right;
Walls[11] = red_wall_left;
//declares the enemy loops

Enemies[0] = enemy_one;
Enemies[1] = enemy_two;
Enemies[2] = enemy_three;
Enemies[3] = enemy_four;
//declares loops arrays for enemy spawn points

Spawn[0] = spawn_base_one;
Spawn[1] = spawn_base_two;
Spawn[2] = spawn_base_three;
Spawn[3] = spawn_base_four;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::movement_timerTimer(TObject *Sender)
{
//call to functions for collison

bullet_coll();
player_coll();
flag_follow();
flag_coll();
extras_coll();
//update the points

blue_points -> Caption = pl_blue.points;
red_points -> Caption = pl_red.points;
blue_deaths -> Caption = pl_blue.deaths;
red_deaths -> Caption = pl_red.deaths;
blue_kills -> Caption = pl_blue.kills;
red_kills -> Caption = pl_red.kills;
//check to see if somebody won the game

GameCheck();
//player blue movement and wall collision

if(GetAsyncKeyState(VK_LEFT)){
player_blue -> Picture -> LoadFromFile("player_blue_left.bmp");
pl_blue.direction[0] = 1;
pl_blue.direction[1] = 0;
if(!HasCollided(player_blue, wall_left)){
if(!HasCollided(player_blue, red_wall_right)){
if(!HasCollided(player_blue, blue_wall_right)){
player_blue -> Left -= pl_blue.move_speed;
}}}}
if(GetAsyncKeyState(VK_RIGHT)){
player_blue -> Picture -> LoadFromFile("player_blue_right.bmp");
pl_blue.direction[1] = 1;
pl_blue.direction[0] = 0;
if(!HasCollided(player_blue, wall_right)){
if(!HasCollided(player_blue, red_wall_left)){
if(!HasCollided(player_blue, blue_wall_left)){
player_blue -> Left += pl_blue.move_speed;
}}}}
if(GetAsyncKeyState(VK_UP)){
if(!HasCollided(player_blue, wall_top)){
if(!HasCollided(player_blue, red_wall_bottom)){
if(!HasCollided(player_blue, blue_wall_bottom)){
player_blue -> Top -= pl_blue.move_speed;
}}}}
if(GetAsyncKeyState(VK_DOWN)){
if(!HasCollided(player_blue, wall_bottom)){
if(!HasCollided(player_blue, red_wall_top)){
if(!HasCollided(player_blue, blue_wall_top)){
player_blue -> Top += pl_blue.move_speed;
}}}}

//player red movement and wall collision

if(game_type == 2){
if(GetAsyncKeyState(65)){
player_red -> Picture -> LoadFromFile("player_red_left.bmp");
pl_red.direction[0] = 1;
pl_red.direction[1] = 0;
if(!HasCollided(player_red, wall_left)){
if(!HasCollided(player_red, red_wall_right)){
if(!HasCollided(player_red, blue_wall_right)){
player_red -> Left -= pl_red.move_speed;
}}}}
if(GetAsyncKeyState(68)){
player_red -> Picture -> LoadFromFile("player_red_right.bmp");
pl_red.direction[1] = 1;
pl_red.direction[0] = 0;
if(!HasCollided(player_red, wall_right)){
if(!HasCollided(player_red, red_wall_left)){
if(!HasCollided(player_red, blue_wall_left)){
player_red -> Left += pl_red.move_speed;
}}}}
if(GetAsyncKeyState(87)){
if(!HasCollided(player_red, wall_top)){
if(!HasCollided(player_red, red_wall_bottom)){
if(!HasCollided(player_red, blue_wall_bottom)){
player_red -> Top -= pl_red.move_speed;
}}}}
if(GetAsyncKeyState(83)){
if(!HasCollided(player_red, wall_bottom)){
if(!HasCollided(player_red, red_wall_top)){
if(!HasCollided(player_red, blue_wall_top)){
player_red -> Top += pl_red.move_speed;
}}}}
}

//firing for player blue

if(GetAsyncKeyState(17)){
if(player_blue -> Visible == true){
if(pl_blue.firing == false){
pl_blue.firing = true;
if(pl_blue.direction[0] == 1){
pl_blue.direction[2] = 1;
pl_blue.direction[3] = 0;
blue_bullet -> Left = player_blue -> Left + (player_blue -> Width / 2 - (blue_bullet -> Width));
blue_bullet -> Top = player_blue -> Top + (player_blue -> Height / 2);
blue_bullet -> Visible = true;
}
else if(pl_blue.direction[1] == 1){
pl_blue.direction[2] = 0;
pl_blue.direction[3] = 1;
blue_bullet -> Left = player_blue -> Left + (player_blue -> Width / 2);
blue_bullet -> Top = player_blue -> Top + (player_blue -> Height / 2);
blue_bullet -> Visible = true;
}
}
}
}
//moving the bullets for player blue

if(pl_blue.firing == true){
if(pl_blue.direction[2] == 1){
blue_bullet -> Left -= pl_blue.fire_speed;}
else if(pl_blue.direction[3] == 1){
blue_bullet -> Left += pl_blue.fire_speed;}
}

//firing bullets for player red

if(game_type == 2){
if(GetAsyncKeyState(16)){
if(player_red -> Visible == true){
if(pl_red.firing == false){
pl_red.firing = true;
if(pl_red.direction[0] == 1){
pl_red.direction[2] = 1;
pl_red.direction[3] = 0;
red_bullet -> Left = player_red -> Left + (player_red -> Width / 2 - (red_bullet -> Width));
red_bullet -> Top = player_red -> Top + (player_red -> Height / 2);
red_bullet -> Visible = true;
}
else if(pl_red.direction[1] == 1){
pl_red.direction[2] = 0;
pl_red.direction[3] = 1;
red_bullet -> Left = player_red -> Left + (player_red -> Width / 2);
red_bullet -> Top = player_red -> Top + (player_red -> Height / 2);
red_bullet -> Visible = true;
}
}
}
}
//moving the bullets for player red

if(pl_red.firing == true){
if(pl_red.direction[2] == 1){
red_bullet -> Left -= pl_red.fire_speed;}
else if(pl_red.direction[3] == 1){
red_bullet -> Left += pl_red.fire_speed;}
}
}

//movement and wall collision for Bomber Enemies

if(difficulty == 2){
for(ECount = 0; ECount < 4; ECount++){
if(EMove[ECount] == 0){
if(!HasCollided(Enemies[ECount], wall_left)){
if(!HasCollided(Enemies[ECount], red_wall_right)){
if(!HasCollided(Enemies[ECount], blue_wall_right)){
Enemies[ECount] -> Left -= enemy_speed;
}}}}
else if(EMove[ECount] == 1){
if(!HasCollided(Enemies[ECount], wall_right)){
if(!HasCollided(Enemies[ECount], red_wall_left)){
if(!HasCollided(Enemies[ECount], blue_wall_left)){
Enemies[ECount] -> Left += enemy_speed;
}}}}
else if(EMove[ECount] == 2){
if(!HasCollided(Enemies[ECount], wall_top)){
if(!HasCollided(Enemies[ECount], red_wall_bottom)){
if(!HasCollided(Enemies[ECount], blue_wall_bottom)){
Enemies[ECount] -> Top -= enemy_speed;
}}}}
else if(EMove[ECount] == 3){
if(!HasCollided(Enemies[ECount], wall_bottom)){
if(!HasCollided(Enemies[ECount], red_wall_top)){
if(!HasCollided(Enemies[ECount], blue_wall_top)){
Enemies[ECount] -> Top += enemy_speed;
}}}}
}
}
}
//---------------------------------------------------------------------------

bool __fastcall TForm1::HasCollided(TControl* C1, TControl* C2)
{
/*function that check for collision between C1 and C2
speficy C1 and C2 as TControl* as any two objects
that you want to check for collision*/

if(C1 -> Left + C1 -> Width > C2 -> Left &&
C1 -> Top + C1 -> Height > C2 -> Top &&
C1 -> Left < C2 -> Left + C2 -> Width &&
C1 -> Top < C2 -> Top + C2 -> Height)return true;
else return false;
}
//---------------------------------------------------------------------------

void TForm1::bullet_coll()
{
//collision checking for blue bullets

for(wallcount = 0; wallcount < 12; wallcount++){
if(HasCollided(blue_bullet, Walls[wallcount]) ||
blue_bullet -> Left >= wall_right -> Left){
blue_bullet -> Visible = false;
pl_blue.firing = false;
}
}
//collsion checking for red bullets

for(wallcount = 0; wallcount < 12; wallcount++){
if(HasCollided(red_bullet, Walls[wallcount]) ||
red_bullet -> Left >= wall_right -> Left){
red_bullet -> Visible = false;
pl_red.firing = false;
}
}
}
//---------------------------------------------------------------------------

void TForm1::Player_coll()
{
//check for bullet collision and player collison

//blue bullets hitting player red

if(HasCollided(blue_bullet, player_red)){
if(player_red -> Visible == true &&
blue_bullet -> Visible == true){
blue_bullet -> Visible = false;
pl_blue.firing = false;
player_red -> Visible = false;
if(pl_red.HasFlag == true){
blue_flag -> Left = player_red -> Left;
blue_flag -> Top = player_red -> Top;
}
pl_red.deaths++;
pl_red.move_speed = 4;
pl_red.fire_speed = 15;
pl_blue.points += 3;
pl_blue.kills++;
red_respawn_timer -> Enabled = true;
}
}

//red bullets hitting player blue

if(HasCollided(red_bullet, player_blue)){
if(player_blue -> Visible == true &&
red_bullet -> Visible == true){
red_bullet -> Visible = false;
pl_red.firing = false;
player_blue -> Visible = false;
if(pl_blue.HasFlag == true){
red_flag -> Left = player_blue -> Left;
red_flag -> Top = player_blue -> Top;
}
pl_blue.deaths++;
pl_blue.move_speed = 4;
pl_blue.fire_speed = 15;
pl_red.points += 3;
pl_red.kills++;
blue_respawn_timer -> Enabled = true;
}
}
//collision for player red and enemies

for(ECollCount = 0; ECollCount < 4; ECollCount++){
if(HasCollided(player_red, Enemies[ECollCount])){
if(Enemies[ECollCount] -> Visible == true){
if(player_red -> Visible == true){
player_red -> Visible = false;
if(pl_red.HasFlag == true){
blue_flag -> Left = player_red -> Left;
blue_flag -> Top = player_red -> Top;
}
pl_red.deaths++;
pl_red.move_speed = 4;
pl_red.fire_speed = 15;
red_respawn_timer -> Enabled = true;
}
}
}
}
//collision for player blue and enemies

for(ECollCount = 0; ECollCount < 4; ECollCount++){
if(HasCollided(player_blue, Enemies[ECollCount])){
if(Enemies[ECollCount] -> Visible == true){
if(player_blue -> Visible == true){
player_blue -> Visible = false;
if(pl_blue.HasFlag == true){
red_flag -> Left = player_blue -> Left;
red_flag -> Top = player_blue -> Top;
}
pl_blue.deaths++;
pl_blue.move_speed = 4;
pl_blue.fire_speed = 15;
blue_respawn_timer -> Enabled = true;
}
}
}
}
//checking for bullets hitting enemies

for(ECollCount = 0; ECollCount < 4; ECollCount++){
if(HasCollided(blue_bullet, Enemies[ECollCount]) ||
HasCollided(red_bullet, Enemies[ECollCount])){
if(Enemies[ECollCount] -> Visible == true){
int q = rand()%4;
Enemies[ECollCount] -> Visible = false;
Enemies[ECollCount] -> Left = Spawn[q] -> Left;
Enemies[ECollCount] -> Top = Spawn[q] -> Top;
Enemies[ECollCount] -> Visible = true;
}
}
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::red_respawn_timerTimer(TObject *Sender)
{
player_red -> Left = 56;
player_red -> Top = 280;
pl_red.direction[0] = 0;
pl_red.direction[1] = 1;
player_red -> Visible = true;
pl_red.HasFlag = false;
red_respawn_timer -> Enabled = false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::blue_respawn_timerTimer(TObject *Sender)
{
player_blue -> Left = 712;
player_blue -> Top = 280;
pl_blue.direction[0] = 0;
pl_blue.direction[1] = 1;
player_blue -> Visible = true;
pl_blue.HasFlag = false;
blue_respawn_timer -> Enabled = false;
}
//---------------------------------------------------------------------------

void TForm1::flag_coll()
{
//when player blue get red flag

if(HasCollided(player_blue, red_flag)){
if(pl_blue.HasFlag == false){
pl_blue.HasFlag = true;
pl_red.FField = true;
pl_blue.points += 1;
}
}
//when player red gets blue flag

if(HasCollided(player_red, blue_flag)){
if(pl_red.HasFlag == false){
pl_red.HasFlag = true;
pl_blue.FField = true;
pl_red.points += 1;
}
}
//when player blue returns his flag

if(HasCollided(player_blue, blue_flag)){
if(pl_red.HasFlag == false){
if(pl_blue.FField == true){
blue_flag -> Left = 755;
blue_flag -> Top = 280;
pl_blue.FField = false;
}
}
}
//when player red returns his flag

if(HasCollided(player_red, red_flag)){
if(pl_blue.HasFlag == false){
if(pl_red.FField == true){
red_flag -> Left = 35;
red_flag -> Top = 280;
pl_red.FField = false;
}
}
}
//when blue captures red flag

if(HasCollided(player_blue, blue_base)){
if(pl_blue.HasFlag == true){
if(difficulty == 1){
pl_blue.points += 5;
pl_blue.HasFlag = false;
red_flag -> Left = 35;
red_flag -> Top = 280;
pl_red.FField = false;
}
else if(difficulty == 2){
if(pl_blue.FField == false){
pl_blue.points += 5;
pl_blue.HasFlag = false;
red_flag -> Left = 35;
red_flag -> Top = 280;
pl_red.FField = false;
}
}
}
}
//when red captures blue flag

if(HasCollided(player_red, red_base)){
if(pl_red.HasFlag == true){
if(difficulty == 1){
pl_red.points += 5;
pl_red.HasFlag = false;
blue_flag -> Left = 755;
blue_flag -> Top = 280;
pl_blue.FField = false;
}
else if(difficulty == 2){
if(pl_red.FField == false){
pl_red.points += 5;
pl_red.HasFlag = false;
blue_flag -> Left = 755;
blue_flag -> Top = 280;
pl_blue.FField = false;
}
}
}
}
}
//---------------------------------------------------------------------------

void TForm1::flag_follow()
{
//getting the flag to follow the player who has it

//when player blue has the flag

if(pl_blue.HasFlag == true){
if(player_blue -> Visible == true){
red_flag -> Left = player_blue -> Left;
red_flag -> Top = player_blue -> Top;
}
}
//when player red has the flag

if(pl_red.HasFlag == true){
if(player_red -> Visible == true){
blue_flag -> Left = player_red -> Left;
blue_flag -> Top = player_red -> Top;
}
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
//get game type

if(RadioGroup3 -> ItemIndex == 0){
cpu_timer -> Enabled = true;
game_type = 1;
}
else if(RadioGroup3 -> ItemIndex == 1){
game_type = 2;
}
//get difficulty

if(RadioGroup1 -> ItemIndex == 0){
red_respawn_timer -> Interval = 800;
blue_respawn_timer -> Interval = 800;
difficulty = 1;
}
else if(RadioGroup1 -> ItemIndex == 1){
difficulty = 2;
red_respawn_timer -> Interval = 300;
blue_respawn_timer -> Interval = 300;
enemy_move_timer -> Enabled = true;
enemy_one -> Visible = true;
enemy_two -> Visible = true;
enemy_three -> Visible = true;
enemy_four -> Visible = true;
spawn_base_one -> Visible = true;
spawn_base_two -> Visible = true;
spawn_base_three -> Visible = true;
spawn_base_four -> Visible = true;
}
//get points to win the game

if(RadioGroup2 -> ItemIndex == 0){
GamePoints = 50;
}
else if(RadioGroup2 -> ItemIndex == 1){
GamePoints = 100;
}
else if(RadioGroup2 -> ItemIndex == 2){
GamePoints = 500;
}
else if(RadioGroup2 -> ItemIndex == 3){
GamePoints = -1;
}
//make player red and red stuff visible

player_red -> Visible = true;
red_flag -> Visible = true;
red_base -> Visible = true;
//make player blue and blue stuff visible

player_blue -> Visible = true;
blue_flag -> Visible = true;
blue_base -> Visible = true;
//make points visible

Label3 -> Visible = true;
blue_points -> Visible = true;
Label1 -> Visible = true;
red_points -> Visible = true;
blue_deaths -> Visible = true;
red_deaths -> Visible = true;
blue_kills -> Visible = true;
red_kills -> Visible = true;
Label4 -> Visible = true;
Label6 -> Visible = true;
Label8 -> Visible = true;
Label10 -> Visible = true;
//make colored wall visible

red_wall_left -> Visible = true;
red_wall_right -> Visible = true;
red_wall_top -> Visible = true;
red_wall_bottom -> Visible = true;
blue_wall_left -> Visible = true;
blue_wall_right -> Visible = true;
blue_wall_top -> Visible = true;
blue_wall_bottom -> Visible = true;
//enable the timer

movement_timer -> Enabled = true;
extras_timer -> Interval = 10000;
extras_timer -> Enabled = true;
//make other items invisible

Memo1 -> Visible = false;
Button1 -> Visible = false;
Label2 -> Visible = false;
RadioGroup1 -> Visible = false;
RadioGroup2 -> Visible = false;
RadioGroup3 -> Visible = false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::enemy_move_timerTimer(TObject *Sender)
{
randomize();
EMove[0] = rand()%4;
EMove[1] = rand()%4;
EMove[2] = rand()%4;
EMove[3] = rand()%4;
}
//---------------------------------------------------------------------------

void TForm1::GameCheck()
{
if(GamePoints != -1){
if(pl_blue.points >= GamePoints){
player_red -> Visible = false;
player_blue -> Visible = true;
winner_logo -> Caption = "BLUE WINS!!!";
winner_logo -> Font -> Color = clBlue;
Label5 -> Font -> Color = clBlue;
winner = true;
}
else if(pl_red.points >= GamePoints){
player_blue -> Visible = false;
player_red -> Visible = true;
winner_logo -> Caption = "RED WINS!!!";
winner_logo -> Font -> Color = clRed;
Label5 -> Font -> Color = clRed;
winner = true;
}
if(winner == true){
enemy_move_timer -> Enabled = false;
blue_respawn_timer -> Enabled = false;
red_respawn_timer -> Enabled = false;
extras_timer -> Enabled = false;
extra_powerup -> Visible = false;
enemy_one -> Visible = false;
enemy_two -> Visible = false;
enemy_three -> Visible = false;
enemy_four -> Visible = false;
spawn_base_one -> Visible = false;
spawn_base_two -> Visible = false;
spawn_base_three -> Visible = false;
spawn_base_four -> Visible = false;
winner_logo -> Visible = true;
Label5 -> Visible = true;
if(GetAsyncKeyState(VK_F1)){
Declare();
movement_timer -> Enabled = false;
winner_logo -> Visible = false;
Label5 -> Visible = false;
Memo1 -> Visible = true;
RadioGroup1 -> Visible = true;
RadioGroup2 -> Visible = true;
Button1 -> Visible = true;
player_blue -> Visible = false;
player_red -> Visible = false;
blue_base -> Visible = false;
red_base -> Visible = false;
blue_flag -> Visible = false;
red_flag -> Visible = false;
winner = false;
}
}
}

}
//---------------------------------------------------------------------------

void TForm1::Declare()
{
//declarations for player blue

pl_blue.points = 0;
pl_blue.firing = false;
pl_blue.kills = 0;
pl_blue.deaths = 0;
pl_blue.direction[0] = 1;
pl_blue.direction[1] = 0;
pl_blue.HasFlag = false;
pl_blue.FField = false;
pl_blue.move_speed = 4;
pl_blue.fire_speed = 15;
player_blue -> Left = 712;
player_blue -> Top = 280;
blue_flag -> Left = 755;
blue_flag -> Top = 280;
//declarations for player red

pl_red.points = 0;
pl_red.firing = false;
pl_red.kills = 0;
pl_red.deaths = 0;
pl_red.direction[0] = 0;
pl_red.direction[1] = 1;
pl_red.HasFlag = false;
pl_red.FField = false;
pl_red.move_speed = 4;
pl_red.fire_speed = 15;
player_red -> Left = 56;
player_red -> Top = 280;
red_flag -> Left = 35;
red_flag -> Top = 280;
//enemy speed

enemy_speed = 4;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::extras_timerTimer(TObject *Sender)
{
extra_powerup -> Visible = true;
extras_timer -> Interval = 500;
if(counter == 5){
counter = 0;
}
switch (counter){
case 0:
extra_powerup -> Picture -> LoadFromFile("extra_point.bmp");
break;
case 1:
case 4:
extra_powerup -> Picture -> LoadFromFile("enemy_speed.bmp");
break;
case 2:
extra_powerup -> Picture -> LoadFromFile("bullet_powerup.bmp");
break;
case 3:
extra_powerup -> Picture -> LoadFromFile("speed_powerup.bmp");
break;
}
counter++;
}
//---------------------------------------------------------------------------

void TForm1::extras_coll()
{
if(HasCollided(player_blue, extra_powerup)){
if(extra_powerup -> Visible == true){
counter -= 1;
extra_powerup -> Visible = false;
extras_timer -> Enabled = false;
extras_timer -> Interval = 10000;
extras_timer -> Enabled = true;
switch (counter){
case 0:
pl_blue.points += 10;
break;
case 1:
case 4:
enemy_speed = 10;
break;
case 2:
pl_blue.fire_speed = 20;
break;
case 3:
pl_blue.move_speed = 8;
break;
}
}
}
if(HasCollided(player_red, extra_powerup)){
if(extra_powerup -> Visible == true){
counter -= 1;
extra_powerup -> Visible = false;
extras_timer -> Enabled = false;
extras_timer -> Interval = 10000;
extras_timer -> Enabled = true;
switch (counter){
case 0:
pl_red.points += 10;
break;
case 1:
case 4:
enemy_speed = 10;
break;
case 2:
pl_red.fire_speed = 20;
break;
case 3:
pl_red.move_speed = 8;
break;
}
}
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::RadioGroup3Click(TObject *Sender)
{
if(RadioGroup3 -> ItemIndex == 1){
Button1 -> Top = 480;
}
else if(RadioGroup3 -> ItemIndex == 0){
Button1 -> Top = 440;
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::cpu_timerTimer(TObject *Sender)
{
/* ////ARTIFICIAL INTELLIGENCE\\\ This crap is so HARD I hate it ugh!!!!
*/

}
//---------------------------------------------------------------------------



HEADER

//---------------------------------------------------------------------------


#ifndef captureH
#define captureH
//---------------------------------------------------------------------------

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------

class TForm1 : public TForm
{
__published: // IDE-managed Components

TPanel *wall_top;
TPanel *wall_bottom;
TPanel *wall_left;
TPanel *wall_right;
TImage *player_red;
TImage *red_base;
TImage *red_flag;
TImage *player_blue;
TImage *blue_base;
TImage *blue_flag;
TPanel *red_bullet;
TPanel *blue_bullet;
TPanel *red_wall_left;
TPanel *red_wall_right;
TPanel *red_wall_top;
TPanel *red_wall_bottom;
TImage *extra_powerup;
TLabel *Label1;
TLabel *red_points;
TLabel *Label3;
TLabel *blue_points;
TLabel *winner_logo;
TTimer *movement_timer;
TTimer *red_respawn_timer;
TTimer *blue_respawn_timer;
TMemo *Memo1;
TRadioGroup *RadioGroup1;
TButton *Button1;
TLabel *Label2;
TRadioGroup *RadioGroup2;
TImage *enemy_one;
TImage *enemy_two;
TImage *enemy_three;
TImage *enemy_four;
TImage *bomb_one;
TImage *bomb_two;
TImage *bomb_three;
TImage *bomb_four;
TTimer *enemy_move_timer;
TLabel *Label4;
TLabel *red_deaths;
TLabel *Label6;
TLabel *red_kills;
TLabel *Label8;
TLabel *blue_deaths;
TLabel *Label10;
TLabel *blue_kills;
TLabel *Label5;
TTimer *extras_timer;
TImage *spawn_base_one;
TPanel *blue_wall_left;
TPanel *blue_wall_top;
TPanel *blue_wall_bottom;
TPanel *blue_wall_right;
TImage *spawn_base_two;
TImage *spawn_base_three;
TImage *spawn_base_four;
TTimer *cpu_timer;
TRadioGroup *RadioGroup3;
void __fastcall FormCreate(TObject *Sender);
void __fastcall movement_timerTimer(TObject *Sender);
void __fastcall red_respawn_timerTimer(TObject *Sender);
void __fastcall blue_respawn_timerTimer(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall enemy_move_timerTimer(TObject *Sender);
void __fastcall extras_timerTimer(TObject *Sender);
void __fastcall RadioGroup3Click(TObject *Sender);
void __fastcall cpu_timerTimer(TObject *Sender);
private: // User declarations

public: // User declarations

__fastcall TForm1(TComponent* Owner);
bool __fastcall HasCollided(TControl* C1, TControl* C2);
void bullet_coll();
void player_coll();
void flag_coll();
void flag_follow();
void GameCheck();
void Declare();
void extras_coll();
};
//---------------------------------------------------------------------------

extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------

#endif


I dont know, maybe that helps someone here understand what im doing and somebody may be able to help me learn to make some ai for the game.

[edited by - GT70sgt on May 19, 2004 2:31:45 PM]

[edited by - GT70sgt on May 19, 2004 2:32:26 PM]

Share this post


Link to post
Share on other sites
Hello.
Firstly, please use the SOURCE tags to enclose your code in a small, readable box. This is done like such: < source > Code Here < / source >, without the extra spaces before and after the brackets.
As for the AI? You’ll probably need to look into Finite State Machines, and assuming your game requires it, pathfinding or steering behaviour. Personally I do not believe pre-defining paths are a good substitute from dynamic AI, as they lead to predictable agents and repetitive gameplay. However, generating vastly different paths from the same point to the same objective can be difficult (depending on your pathfinding environment) – any you’ll probably end up generating the same paths over and over, so the agents may still act predictably.
Anyhow, as for agent behaviour… most defenders could generally stick around the objective (you may want to enforce some sort of restriction to prevent defenders from crowding the flag), possibly moving to a location approximately x distance away from the flag then randomly choosing another location approximately x distance away from the objective and moving there (a loop). When a defender sees a target, break from the loop and pursue, until the target gets too far away from the flag. Depending on the number of defenders, you may want to expand the distance to the flag when choosing random waypoints. I’m sure there are more imaginative ways to guard a position – that was the first thing that came to mind, and suitable just to get something up and running.
Attackers – generate random paths to the objective, evade the defenders etc – pretty standard.
Once you get your AI happening you may like to expand it. Teamwork is great – start by distributing your defenders evenly (don’t crowd each other), and your attackers might be more effective if they travel in groups, covering each other and attacking from different angles. Your defenders could identify bottlenecks and cover them appropriately. Tactics such as flanking and distracting may work well – but note that these things may be difficult to code (depending on the environment).

Hope this gives you some ideas,

Jackson Allan

[edited by - jack_1313 on May 19, 2004 7:26:05 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by GT70sgt
this is hard, I can''t seem to get it. I can get the guy to go to the flag and capture it and go through it again, but he doesnt dodge enemies, or the players bullets



Okay, it sounds like you''re further along than you first explained...

If you already have agents that are moving around in your world, you now need to give them ''realistic'' behaviours. That is, behaviours that appear to be reasonable given the context the agent is in.

Let''s take dodging bullets as an example. Firstly, the agent needs to know its being fired upon. Once it knows this, it needs to react. When someone is shooting at you, there really isn''t enough time to stand there, look around and choose the best hiding spot. You''d be dead pretty soon if you did that. So, a realistic behaviour might be to drop prone on the ground. Another one might be to dive in a random direction, or toward the closest object, or perpendicular to the line of fire. Get the idea?

As for dodging enemies, you can handle this in your pathfinding methods. If I understand it correctly, you currently have predefined paths for your agents to walk along to get to and from the flag. Correct? If this is the case, you might want to add some steering behaviours to your agents to handle chasing enemies off the path and avoiding enemies near the path. Here''s an example... your agent is running along the path toward the goal and takes fire from an enemy hiding up ahead. She dives off the path and starts crawling away toward a rock nearby. When she is no longer being fired up, she stands up and looks for the enemy. When she sees him, she starts chasing him using him as the focus of a steering behaviour. While chasing him, she is shooting whenever she gets a clear line of sight to her target. When her target is dead (or escapes), she looks for the closest point on the preset path to the flag and moves there. Once on that path again, she continues to the flag.

All of these states can be modelled in a finite state machine. The decision to change state can be implemented in many different ways. The most trivial is to write them all down as a set of if condition then action rules. Whenever a rule is triggered by a condition, it causes a particular action (like walking, changing weapons, shooting, hiding, dropping prone, etc).

Again, I highly recommend that you read at least some literature on Game AI. While you can certainly implement a basic AI without doing so, you''ll learn so much more and produce a much better game if you do some reading.

Cheers,

Timkin

Share this post


Link to post
Share on other sites