Behold my advanced AI!

Miscellaneous Forums/Blitz Showcase/Behold my advanced AI!

For Blitz3D:
Global px,py,psp,ps#,pc
Global minerals,rawminerals,money,mineralcapacity

AppTitle "Mineral Miner"

Graphics 800,600,32,1

SetBuffer BackBuffer()
SeedRnd MilliSecs()

Type miner

	Field m.miner
	Field px,py,psp,ps#,pc
	Field minerals,mineralcapacity
	
End Type

mineramount=1

For ma=1 To mineramount
	m.miner=New miner
Next

For m.miner=Each miner
	m\px=Rnd(0,790)
	m\py=Rnd(0,590)
	m\psp=2
	m\minerals=0
	m\mineralcapacity=250
	m\ps#=10
	m\pc=Rnd(25,255)
Next

money=100
rawminerals=25000

upgrade1=False
upgrade2=False

While Not KeyHit(1)

	Display()
	Miner()

	Flip
	Cls
	
Wend

Function Display()

	;base
	Color 0,0,255
	Rect 0,500,100,100,1
	Color 0,0,0
	Text 30,540,"BASE"
	
	;minerals
	Color 255,0,0
	Rect 700,0,100,100,1
	Color 0,0,0
	Text 710,45,"MINERALS"
	Color 255,0,0
	Text 700,100,"Amount: "+rawminerals
	
	;info
	Color 200,200,200	
	Text 10,10,"Money: $"+money		

End Function

Function Miner()	
	
	For m.miner=Each miner
	
		If m\minerals=0 Then
			If m\px<750 Then m\px=m\px+1*m\psp
			If m\py>50 Then m\py=m\py-1*m\psp
		EndIf
	
		If m\minerals>=m\mineralcapacity Or rawminerals=0 Then
			If m\px>50 Then m\px=m\px-1*m\psp
			If m\py<550 Then m\py=m\py+1*m\psp
		EndIf
	
		If m\minerals>0 And m\px=<100 And m\py>500 Then	
		
			money=money+m\minerals*3.3
			m\minerals=0
			m\ps=10
					
		EndIf
	
		If m\minerals<=m\mineralcapacity And rawminerals>0 And m\px>700 And m\py<100 Then
			
			m\minerals=m\minerals+1	
			rawminerals=rawminerals-1
			m\ps#=m\ps#+0.05						
	
		EndIf	
		
		Color 0,m\pc,0
		Oval m\px,m\py,m\ps#,m\ps#,1
		Color 255,0,255
		Text m\px-8,m\py+12,m\minerals	
		
		;If KeyHit(2) And money>=10000 And m\mineralcapacity<400 Then money=money-10000:upgrade1=True
		;If upgrade1=True Then	m\mineralcapacity=400		
				
		;If KeyHit(3) And money>=12000 And m\psp<3 Then money=money-12000:upgrade2=True
		;If upgrade2=True m\psp=3		
	
	Next	
	
	If KeyHit(28) And money>1200 Then
		
		money=money-1200
		
		m.miner=New miner
		m\px=50
		m\py=550
		m\psp=2
		m\minerals=0
		m\mineralcapacity=250
		m\ps#=10
		m\pc=Rnd(25,255)
	
	EndIf	
	
End Function


Press enter to buy another miner if you have $1200.

Uh ... wow!

That's about the most any RTS can offer in terms of gameplay, imho! :-)

It runs in BlitzPlus without any modifications.

You probably had fun making it :P?

omg, a Blitz3D game that compiles in Blitz+? UR A GENIUS

heh, thankyou, thankyou. That isn't *actual* AI though, is it? Anyones know how AI works in most games? I know it is different for every one, but how does the computer move 'on its own'? Or do actions on its own?

"how does the computer move 'on its own'? Or do actions on its own?"

i seem to recall your little spheres moving and doing things on their own. you coded some AI... really, dumbed-down simple AI... but hey it's a start.

basic idea:

-give an ai unit a destination ie the location of food, the location of an enemy, the location of a safe region etc etc
-pathfind to the location using whatever algorithm suits
-check for change of situation every so often while ai unit is travelling to destination ie if it is shot at perhaps it changes from seeking food to seeking the enemy that shot at it

Hmmm, I see.