Space Fight AI Tournament Idea
Space Fight AI Tournament Idea
Artificial Intelligence!
Yes thats right. Anyone who is not busy, and is also bored (should be quite a few, I hope ;) I heartly invite you to a challenge!
Its called NanoShips and the idea is this:-
You write the AI for a freefoating space ship, using the Template_AI.bi provided... Then when we have at least 2 AI files submitted, we get them to battle eachother!
All the ground work has been done (admittedly it wasn't too much work), all that is left is for a few people to rise to the challenge!
Contents of the archive:-
NanoHost.bas - This is the core engine and must not be modified!
VsConfig.bi - This file is used to link the AI functions to a ship
Template_AI.bi - Use this as a template to fill in with your own AI code. Your AI code is a single function, given values from the NanoHost engine telling you your position, their position, the nearest enemy laser and so on. In here you also set a few unique things for your ship (name, colour, draw function)
The AI file you write will return an Action and a Message to NanoHost...
' The available return actions are:-
' IDLE
' THRUST
' BACKTHRUST
' TURNCCW
' TURNCW
' SHOOT
' The following Constants are available:-
' CONST PI = 3.1415926535897932384626433832795
' CONST Radians = PI / 180
' The values you may work with, are given in the function header...
' Your Health, Power, Angle, Position X, Position Y.
' The Enemy Positon X and Y.
' The X and Y of the nearest Enemy Laser (-1,-1) indicates inactive.
' There are 0 TO 15 flags available.
' You can store values in the Flag() array to use however you wish.
' The flag array is the only acceptable means of storing values
' between NanoHost cycles.
' The amount of damage your Lasers do to the Enemy is proportional
' to your current Power at the time of impact.
' You may do anything in this function, with the following exceptions:-
' You may not use SLEEP.
' You may not access the buffer of the screen.
' You may not change values outside of this function.
' You may not use INKEY$ or MULTIKEY, or any other form of user input.
' You may not use STATIC.
' You are allowed to write extra functions for your "host" AI function, and
' the function name must be prefixed with your alias.
' Be careful of constants, make sure they are prefixed too.
Here is a link to the source zip:-
http://mambazo.langfordtavern.com/zips/NanoShips_AI.zip
I wish you all the best of luck!
Yes thats right. Anyone who is not busy, and is also bored (should be quite a few, I hope ;) I heartly invite you to a challenge!
Its called NanoShips and the idea is this:-
You write the AI for a freefoating space ship, using the Template_AI.bi provided... Then when we have at least 2 AI files submitted, we get them to battle eachother!
All the ground work has been done (admittedly it wasn't too much work), all that is left is for a few people to rise to the challenge!
Contents of the archive:-
NanoHost.bas - This is the core engine and must not be modified!
VsConfig.bi - This file is used to link the AI functions to a ship
Template_AI.bi - Use this as a template to fill in with your own AI code. Your AI code is a single function, given values from the NanoHost engine telling you your position, their position, the nearest enemy laser and so on. In here you also set a few unique things for your ship (name, colour, draw function)
The AI file you write will return an Action and a Message to NanoHost...
' The available return actions are:-
' IDLE
' THRUST
' BACKTHRUST
' TURNCCW
' TURNCW
' SHOOT
' The following Constants are available:-
' CONST PI = 3.1415926535897932384626433832795
' CONST Radians = PI / 180
' The values you may work with, are given in the function header...
' Your Health, Power, Angle, Position X, Position Y.
' The Enemy Positon X and Y.
' The X and Y of the nearest Enemy Laser (-1,-1) indicates inactive.
' There are 0 TO 15 flags available.
' You can store values in the Flag() array to use however you wish.
' The flag array is the only acceptable means of storing values
' between NanoHost cycles.
' The amount of damage your Lasers do to the Enemy is proportional
' to your current Power at the time of impact.
' You may do anything in this function, with the following exceptions:-
' You may not use SLEEP.
' You may not access the buffer of the screen.
' You may not change values outside of this function.
' You may not use INKEY$ or MULTIKEY, or any other form of user input.
' You may not use STATIC.
' You are allowed to write extra functions for your "host" AI function, and
' the function name must be prefixed with your alias.
' Be careful of constants, make sure they are prefixed too.
Here is a link to the source zip:-
http://mambazo.langfordtavern.com/zips/NanoShips_AI.zip
I wish you all the best of luck!
Last edited by mambazo on May 16, 2006 22:51, edited 2 times in total.
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
Can I have multiple returnAI values at once? If I do:
will that work?
Code: Select all
ReturnAI.action or = shoot
ReturnAI.action or = TurnCCW
Here's some starter code to give an example of how to code the AI funtion...
This code will make the ship turn to face the opponent....
This code will make the ship turn to face the opponent....
Code: Select all
DIM AS DOUBLE DesiredAngle
' Turn to face the enemy
DesiredAngle = ATN(ABS(EnemyY - PosY) / ABS(EnemyX - PosX)) / (PI / 180)
' NorthEast Quad
IF EnemyX > PosX AND EnemyY < PosY THEN
DesiredAngle = 360 - DesiredAngle
END IF
' NorthWest Quad
IF EnemyX < PosX AND EnemyY < PosY THEN
DesiredAngle = 180 + DesiredAngle
END IF
' SouthWest Quad
IF EnemyX < PosX AND EnemyY > PosY THEN
DesiredAngle = 180 - DesiredAngle
END IF
IF ABS(DesiredAngle - Angle) > .01 THEN
IF DesiredAngle > Angle THEN
IF (DesiredAngle - Angle) <= ((Angle + 360) - DesiredAngle) THEN
ReturnAI.Action = TURNCW
ELSE
ReturnAI.Action = TURNCCW
END IF
END IF
IF DesiredAngle < Angle THEN
IF (Angle - DesiredAngle) < ((DesiredAngle + 360) - Angle) THEN
ReturnAI.Action = TURNCCW
ELSE
ReturnAI.Action = TURNCW
END IF
END IF
END IF
-
- Posts: 5494
- Joined: Sep 12, 2005 20:06
- Location: California
Oh yeah, forgot about that one :Dmambazo wrote:Hint: Don't forget about the Flag() array, you can use it to your advantage by storing data like, the state of your AI (i.e. tracking the enemy, ready to fire, dodging a laser, etc)
Honestly I don't know if I have time or energy to do this, but it sounds fun ^_~;; Maybe you can keep it open for a high length of time or store all AI in a database. Perhaps this will catch on :P
Here's a stupid little one I just made, took 10 seconds so it aint much, just picks a random direction, speeds off as fast as it can in that direction and starts firing at the player, doesnt seem to wanna let me subtract 1 from Flag(4), fix that and it works fine : )
Code: Select all
DIM AS MessageAI ReturnAI
'1 = Quit
'2 = Turn to face and quit
If Flag(0) = 0 Then
Flag(0) = 1
Flag(3) = INT(RND * 360) + 1
Endif
If Flag(3) > 0 Then
ReturnAI.Action = TURNCW
Flag(3) = Flag(3) - 1
ReturnAI.Message = "Rotating..."
goto 1
Else
Flag(1) = 1
Flag(4) = 50
endif
If Flag(1) > 0 Then
ReturnAI.Action = THRUST
ReturnAI.Message = "Picking up speed..."
Flag(4) = Flag(4) - 1
If Flag(4) = 0 Then Flag(1) = -1
goto 1
endif
if Flag(1) = -1 Then
If Flag(2) < 1 Then
Flag(2) = 100
ReturnAI.Action = SHOOT
ReturnAI.Message = "!!FIRE!!"
Goto 1
Endif
ReturnAI.Message = "Waiting to shoot while facing the player..."
Flag(2) = Flag(2) - 1
Goto 2
Endif
Goto 1
2 DIM AS DOUBLE DesiredAngle
DesiredAngle = ATN(ABS(EnemyY - PosY) / ABS(EnemyX - PosX)) / (PI / 180)
IF EnemyX > PosX AND EnemyY < PosY THEN
DesiredAngle = 360 - DesiredAngle
END IF
IF EnemyX < PosX AND EnemyY < PosY THEN
DesiredAngle = 180 + DesiredAngle
END IF
IF EnemyX < PosX AND EnemyY > PosY THEN
DesiredAngle = 180 - DesiredAngle
END IF
IF ABS(DesiredAngle - Angle) > .01 THEN
IF DesiredAngle > Angle THEN
IF (DesiredAngle - Angle) <= ((Angle + 360) - DesiredAngle) THEN
ReturnAI.Action = TURNCW
ELSE
ReturnAI.Action = TURNCCW
END IF
END IF
IF DesiredAngle < Angle THEN
IF (Angle - DesiredAngle) < ((DesiredAngle + 360) - Angle) THEN
ReturnAI.Action = TURNCCW
ELSE
ReturnAI.Action = TURNCW
END IF
END IF
END IF
1 RETURN ReturnAI
Cool, I've just made an AI for it too, I'll put them up against eachother and post the results of 5 matches...
http://mambazo.langfordtavern.com/zips/Mambazo_AI.bi
Good luck ;P
http://mambazo.langfordtavern.com/zips/Mambazo_AI.bi
Good luck ;P
Code: Select all
IF (Flag(3) > 0) THEN
ReturnAI.Action = TURNCW
Flag(3) = Flag(3) - 1
ReturnAI.Message = "Rotating..."
GOTO 1
ELSEIF (Flag(1) = 0) THEN
Flag(3) = 1
Flag(4) = 50
Flag(1) = 1
END IF