Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Little help with simple ai #459929
06/12/16 13:20
06/12/16 13:20
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
Could someone help me with a simple enemy ai problem.
I created this game based on pong on a 1 player vs pc the bat moves on the same y as the ball. But now it will never miss the ball so that seems a little unfair. How to make it react a bit slower so it can actually miss the ball to
Here is what I have so far and it works however now It is unbeatable
the clamp is needed cause the computer player must not leave the player area

Code:
action player2ai()
{
	set(my,SHADOW | METAL);
	player02 = me;
	c_setminmax(me);
	ent_create("spark2+16.tga", vector(player02.x,player02.y,player02.z+10), sprite_played);
	while (!bbal) {wait (1);}
	while(health2 >=1 )
	{
		blast_rocketpl22();
		
		my.y = bbal.y;
		my.y = clamp(my.y,-344,344);
		/////	my.y += 1 * (bbal.y - bbal.y);
		wait(1);
	}
	ent_remove(astron);
	ent_remove(bbal);
	ent_remove(bringer);
	set(play1_pan,SHOW);
	ent_create("explo2+16.tga", vector(player02.x,player02.y,player02.z+10), sprite_played);
	wait(1);
	ent_remove(me);
	game_over();
}



i know i know should have paid more attention at math back at school grin Credits in game for him who helps me out laugh

Last edited by Realspawn; 06/12/16 13:21.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Little help with simple ai [Re: Realspawn] #459933
06/12/16 16:52
06/12/16 16:52
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
A bit more info about your current AI (e.g. a video) would help. wink

From what I understand, your problem now is that the AI always blocks player balls 100% succesfull. You could solve this by letting the AI calculate the move time to intercept a player ball. And than give it a chance to decrease or increase this value as if the AI made a mistake during its calculation. (so the AI goes to slow to or beyond the point where the player ball would hit)

Another trick would be to give it a small chance the AI go suddenly to fast or to slow as if its fingers slipped of the mouse or such.

Re: Little help with simple ai [Re: Reconnoiter] #459935
06/12/16 17:36
06/12/16 17:36
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
thank you for your response here is some test footage

https://www.youtube.com/watch?v=JMFs8Bkp9zc&feature=youtu.be

i was thinking maby make it move on y like the ball but a bit slower
so there is a different in speed between bat and ball. As you can see in the clip the blue bat is now always there in time laugh

laugh

Last edited by Realspawn; 06/12/16 17:37.

Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Little help with simple ai [Re: Realspawn] #459936
06/12/16 18:22
06/12/16 18:22
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
I wrote a pong game in javascript some weeks ago, this is what I did:
Code:
/* An AI controller */
var AIController = function(paddle, ball) {
	this.speed = paddle.MAX_SPEED;
	this.paddle = paddle;
	this.ball = ball;
	this.lastTick = 0;
	this.calcCnt = 0;
	
	this.ballSign = -1;
	if(this.paddle.isRightPaddle)
		this.ballSign = 1;
};

AIController.prototype.play = function() {
	if(pongGame.getOptions().difficulty == 0) {
		this.REACT_TIME = 320;
		this.ACT_TIME = 4;
		this.MOVE_VEL = 6;
		this.SPREAD = 1;
	} else if(pongGame.getOptions().difficulty == 1) {
		this.REACT_TIME = 250;
		this.ACT_TIME = 8;
		this.MOVE_VEL = 8;
		this.SPREAD = 1;
	} else if(pongGame.getOptions().difficulty == 2) {
		this.REACT_TIME = 150;
		this.ACT_TIME = 12;
		this.MOVE_VEL = 10;
		this.SPREAD = 1;
	} else {
		this.REACT_TIME = 80;
		this.ACT_TIME = 20;
		this.MOVE_VEL = 14;
		this.SPREAD = 0;
	}
	
	this.paddle.isCPU = 1;
	this.paddle.speed = this.speed;
	
	if(Math.sign(this.ball.xSpeed) == this.ballSign) {
		if(this.calcCnt < this.ACT_TIME) {
			var deltaX;
			if(this.SPREAD)
				deltaX = Math.abs((this.paddle.xPos) - this.ball.xPos) * Math.random()*2 - 1;
			else
				deltaX = Math.abs((this.paddle.xPos) - this.ball.xPos);
			
			var deltaY = (this.paddle.yPos + this.paddle.paddleHeight / 2 + deltaX / (this.paddle.gameWidth / this.MOVE_VEL)) - this.ball.yPos;
			
			if(deltaY > 0) {
				this.paddle.yPos -= Tools.clamp(this.paddle.speed * Math.abs(deltaY) / (this.paddle.gameWidth / this.MOVE_VEL), 0, this.speed);
				this.paddle.startMovingUp();
			} else if(deltaY < 0) {
				this.paddle.yPos += Tools.clamp(this.paddle.speed * Math.abs(deltaY) / (this.paddle.gameWidth / this.MOVE_VEL), 0, this.speed);
				this.paddle.startMovingDown();
			}
			
			this.paddle.yPos = Tools.clamp(this.paddle.yPos, 0, this.paddle.gameHeight - this.paddle.paddleHeight);
			
			this.calcCnt++;
		} else {
			var ticks = new Date().getTime();
			if(ticks - this.lastTick > this.REACT_TIME)
			{
				this.lastTick = ticks;
			} else {
				this.calcCnt = 0;
			}
		}
	} else {
		this.calcCnt = this.ACT_TIME;
	}
}


Re: Little help with simple ai [Re: Ch40zzC0d3r] #459939
06/12/16 18:49
06/12/16 18:49
Joined: May 2005
Posts: 867
Chicago, IL
Dooley Offline
User
Dooley  Offline
User

Joined: May 2005
Posts: 867
Chicago, IL
You could have the bat check it's position against the position of the ball, and move in that direction at a fixed rate but never faster than the vertical movement of the ball. This way, a sharper angled ball would be able to move faster than the bat, but it would be able to keep up with more direct shots.

Re: Little help with simple ai [Re: Dooley] #459940
06/12/16 18:51
06/12/16 18:51
Joined: May 2005
Posts: 867
Chicago, IL
Dooley Offline
User
Dooley  Offline
User

Joined: May 2005
Posts: 867
Chicago, IL
Something like this:

if(my.y < ball.y)
{
my.y += 10 * time_step;//not sure what speed to put here
}
else if(my.y > ball.y)
{
my.y -= 10 * time_step;
}

EDIT: This will probably cause the bat to jitter up and down a bit, so you could add a little gap, like:

if(my.y < ball.y - 1)

if(my.y > ball.y + 1)

You're making me want to write a pong game laugh


Last edited by Dooley; 06/12/16 18:56.
Re: Little help with simple ai [Re: Dooley] #459942
06/12/16 19:10
06/12/16 19:10
Joined: Jul 2001
Posts: 4,801
netherlands
Realspawn Offline OP

Expert
Realspawn  Offline OP

Expert

Joined: Jul 2001
Posts: 4,801
netherlands
Dooley that was the way i was thinking in not sure how to do it but you did it it works as a charm. All game is complete now lets look for some one that can make it work one vs one online grin

thx


Find all my tutorials & Workshops at : www.rp-interactive.nl

Creativity starts in the brain
Re: Little help with simple ai [Re: Realspawn] #459943
06/12/16 19:18
06/12/16 19:18
Joined: May 2005
Posts: 867
Chicago, IL
Dooley Offline
User
Dooley  Offline
User

Joined: May 2005
Posts: 867
Chicago, IL
Awesome, glad to help!

I tried some multiplayer stuff a while ago. Look up Locoweeds Multiplayer Tutorial. I forgot if it was Lite-C or C-Script...

And if you need a beta-tester, I'm your guy wink


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1