Random moves

Blitz3D Forums/Blitz3D Beginners Area/Random moves

En929(Posted 2012) [#1]
This is a BlitzPlus question. I was wondering how do I make the opponent character below do random moves in the same way it's done in fighting games like street fighter, etc. Thanks!


Graphics 1280, 720, 16
SetBuffer BackBuffer()
GameTimer = CreateTimer(60)


Global  HENRYIMAGE = LoadAnimImage ("Henry's Film.PNG",400,370,0,19) 
						  
Type HENRY
	Field x,y
	Field image
	Field Frame             
End Type 

Const RightStand = 1        
Const RightGo = 2				
Const RightPunch = 7       
Const RightStandAfterPunch = 6 
Const LeftStand = 4              
Const LeftGo = 5                
Const LeftPunch = 9					
Const LeftStandAfterPunch = 8	
Const Rightkick = 15			
Const LeftKick = 17				
								
													
;this is actually the target character in which the opponent goes after. 								

Global h.HENRY = New HENRY
h\x = 300
h\y = 400
h\image = HENRYIMAGE
h\frame = Rightstand   


;I'm trying to get this character to do the random moves based on 
;the constants above.

Global OPPONENT.HENRY = New HENRY 
OPPONENT\x = 700
OPPONENT\y = 400
OPPONENT\image = HENRYIMAGE
OPPONENT\frame = Leftstand                      
							                   

While Not KeyDown (1) 

Cls 


 DrawImage (h\image,h\x,h\y,h\frame) 

 DrawImage (OPPONENT\image,OPPONENT\x,OPPONENT\y,OPPONENT\frame) 

				
								
Flip
Wend 							





Last edited 2012


stayne(Posted 2012) [#2]
Are you sure you want them to be random? That sort of AI wouldn't put up much of a fight. If I were you I would write on paper every aspect of AI you want to have. Blocking, kicking, punching, etc. Meaning if your player is kicking, the AI will choose to either block, jump back, etc. in order to put up a decent fight. So write down every AI state first and then go from there. It will be much easier in the long run. Example:

- Player hits the punch key
- AI decides to block
- Player hits the punch key again and hits the enemy
- AI decides to kick
- Player blocks the kick
- AI knows a block opens up the lower body and decides to kick
- etc etc

Last edited 2012


Kryzon(Posted 2012) [#3]
I think he means a persistent state: making the AI move a few steps, and what condition that triggers it.
@En929: these movements may look random to you, but you can be sure the programmer has specific conditions for them to happen.

You can add a few other actions to stayne's list like:
- If health is above or equal to 70%, then move toward player in order to attack (so the CPU is feeling confident).
- If health is below 70%, start the "attentive mode". Any time the player approaches, move back to evade and draw a random number - if the number is below 'n', do a surprise attack, else just keep moving back until there's no more space so you need to forcibly attack or jump over player to change sides etc.
- Implement combos. Attack attack attack, do a special then move back and wait for a player reaction.

If you trigger a moving state, don't change this state until the target location has been reached OR some other higher priority state needs triggering (the player is in attack-range, or you have enough "mana" for a special attack etc.). This is how you make it persistent - the CPU moves actual distances, not just a single pixel.

You can build more of these AI schemes for different 'personalities'. If you find the right combination of character+personality (since each character has a slightly different set of specials and moves, and looks different so they propose different personalities), then you're golden because it'll feel like the CPU is alive. Player immersion will be much greater.
But you do need to take your time to actually design how these AI schemes will be (pen & paper).

Consider movement as a lower-priority kind of state and blocking\attacking as much more important because in the middle of a movement the player might suddenly approach the opponent and then the CPU 'has' to defend itself.

Last edited 2012


En929(Posted 2012) [#4]
Thanks for the advice Kryzon and Stayne