Artificial Intelligence (AI) competition proposal

Hello everyone.

When reading all your great posts on the forum, I though it would be great to have a competition where every one would design some ‘“brain” and have it compete with the others’ brain. But to do this we need a playground for this brain. So I have decided to design this small football game (my wife rather calls it a “pushball” game), you can have a glance at it in this video:
http://www.youtube.com/watch?v=nFPu5pbHJHo

The game normally runs 50 FPS, but the recording slows down the speed.



I call it a game, but it is a bit different from usual games published here, because it is a game for robot-player programmers: you don’t interract directly with the game, you just start it and watch the match (2 min) to see which team will win and why. When you find out a way to improve your team behavior, then the real game starts for you: you open the project and modify the AI class.



If you want to run it you can get the whole project zipped there:

http://db.tt/obioCQVg

Rename the folder whateverYouWant.codea and paste it in the codea “documents” folder. You will get all the tabs.

If you just want a quick try, the wole project in one text file is there:

http://db.tt/SoV7IPSR

Copy the whole text, paste it in a new empty codea project and run it.



The rules of the competition are:

-- This is a football game for AI competition
-- the team that score the most goals in 2 min wins one "game"
-- the team that wins 2 games out of 3 wins the match!
-- Brain00 is powering teamA, the blue ones on left
-- Brain01 is powering teamB, the red ones on the right
-- try to improve the AI of one of the Brain classes and make the best team!
-- the limits are:
-- 1/ you can read all information from other classes, but not modify them
-- 2/ the FPS when opposing two teams with you brain class should not fall below 30 FPS iPad1
-- share your Brain class on CODEA forum so we can compete!

The intelligence of each team is in the “brain…” classes.

It does only one thing: expose a function to each player that tells him what force to apply when draw() is called.

I have put 2 brains in this first version: Brain00 and Brain01.



Brain01 is a very dumb IA: if the player is on the good side of the ball then push the ball, else go back to my camp

Brain01 = class()

-- this a a very basic brain

function Brain01:init(team)
    -- this parameter is mandatory
    self.team = team
    -- there you can add whatever parameter you need for your brain
end

-- this function is mandatory: it returns for this player the force to apply, a vec2
-- it is called during each call to draw()
function Brain01:force(player)
    local ballToPlayer = player:pos() - ball:pos()
    local attackDirection = player.team.theirGoal:pos() - player.team.myGoal:pos()
    attackDirection = attackDirection:normalize()
    local force = 20
    local vecForce
    -- if the player is on the good side of the ball
     if ballToPlayer:dot(attackDirection) < -20 then
        -- then push the ball
        vecForce = -ballToPlayer:normalize()*force
     else -- else go back to my camp
        vecForce = -attackDirection*force
     end
    return vecForce
end

Brain00 is my best achievement so far (it can really be improved), see the code directly, the post seems to be too long if I put it here.

You can modify Brain01 to make it smarter and win the game against Brain00. For this everything is allowed: you can push the ball, the opponents, use the bumper to propell you… Whatever as long as it goes through the force applied to each of your player and you don’t consume too much computing power.

There is a DEBUG flag at the beginning of the Main tab: set it ‘true’ and you will see the force applied to the players by your Brain class.

There is also a .exist flag for each team: you can set it to false for one team if you want to see what happens with just one team, for debug purposes.



If you want to be in the competition:

  • download the project
  • design a better brain class
  • post it on the forum

    I will keep track of the 2 best AI brain class below with credit to the authors.

    For the moment the 2 best brains are: (haha)

    Number 1: Brain00 from JMV38

    Number 2: Brain01 from JMV38



    Hope you will like this competion idea and join in! Have fun!

Brain number 1:

Brain number 2:

This is fascinating to watch! But a few questions…
Should we post our code plain, or keep it a secret from the other competitors?
How will we decide the winner? By having a tournament?
I have an iPad 2, how will I be able to check the frame rate on an iPad 1?

EDIT =
I just played 3 matches, the scores were 3-2, 4-1, then 0-2. If you do have a tournament, will you play multiple matches, or just sudden death?

.@Jmv38, shouldn’t the energy reset when a goal is scored?

@Jordan thanks for the feedback.

Plain or secret code? My proposal would be to play the competition in the Codea spirit: open source code. The ‘competion’ is just a drive to challenge your brilliant minds, and have fun watching the results. I would favor: post the code on the forum, be a temporary winner, until someone improves your code (while giving you some credits in a ‘credits’ comments section for intance) and makes a better brain and become the new winner.



How do we decide the winner? My idea was that i would run the posted brains on my iPad, in the order first-in-first-out, and report the results by editing my first 3 posts. If there are less than 10 competitors it can be done once a week, until everybody gets bored with this. If there are more competitors, we’ll find a way when problem pops up. Everyone can check the results by running the brains against one another on his own iPad. If someone thinks he has been eliminated just by bad luck, and could be a winner, then he can retry the following week with the same brain. Each competitor should submit one or two brain per week maximum, so there is no traffic jam.



Power limitation: in case of doubt i will measure the fps on my ipad and tell the info to the owner of the brain. We’ll find a way when the problem pops up (we could have ipad 1/2/3 categories, but a real ‘master’ of AI will find a way to comply and win even on ipad1, right?).



Multiple matches or sudden death? Sudden death, but you can retry the next week! The rule is 3 games in a row, the brain that gains 2 out of 3 gains the match.



Hope all this sound sensible? I am ok to ajust things, i have only one golden rule: let’s have fun!

Best regards.

@Jordan

Energy reset after a goal? I would rather not: in a real match, you get tired if you use too much energy at the beginning. This is good constrain because it can generate subtle differences in strategies, making the difference in the long run.

@Jordan Hi ! I want to introduce a ‘‘max force limit’’, as i have set a max speed limit. It makes more sense (a real player cannot apply a huge force). Is that ok for you?

I guess it would be, but I am thinking, you could get your player to shoot… It would not affect me.

@Andrew_stacey Hello! At the moment i am getting a headache at a classical cinnematic problem, maybe as a mathematician you already have the solution somewhere? The problem is: i have a ball of mass m=1 at position x0,y0 and speed vx0,vy0 , i want to apply a force dF(t) so that is goes to the position x1,y1 with speed vx1,vy1 once there. How can i calculate dF(this frame) if the constrain is ‘‘minimize time to reach the target state’’? Or if it is ‘‘minimize the total energy spent’’? Thank you!

You’re going to need some constraints. If I’m allowed arbitrarily strong forces, I can get across as quickly as you like by applying a huge force to get me almost there and then braking suddenly to bring the velocity down to what it should be. Similarly, to minimise total energy spent then I give it a very small kick at the start and then just wait a long time.

So what additional constraints do you want to impose?

@Andrew_Stacey Good point! I have a maximum force per frame limit (100) and a maximum speed limit (1000). If we say within this constrain, achieve the minimum time to go from state1 to state2, it should be ok? For the other case, minimum energy spending, we can add the constrain time should be equal to dt (0.1 to 1s, depending on the situation). Thanks!

An alternative constrain could be: i have a budget of dF=20 per frame. If i apply a force amplitude of exactly dF (or less), what should be the vec2 force dF(t) to minimize the time to go from state0 to state1? Or to do it in exactly dt seconds? (in this last case however the problem might still be underdetermined…?). Hum… seems more complex than I thought.

I know this is from ages ago but I decided to fiddle with it.

First I tried to make a behavior that was too complex for me to figure out, and it sucked.

Then I added four lines to Brain01, and in every tournament I’ve played my new brain won—against both Brain00 and Brain01.

All I did was apply super basic energy management; if a player has more than 75% of their total energy, they charge very hard, and once they have less, they charge less hard and recuperate.


BrainUG = class()

-- modification of a very basic brain

function BrainUG:init(team)
    -- this parameter is mandatory
    self.team = team
    -- there you can add whatever parameter you need for your brain
end

-- this function is mandatory: it returns for this player the force to apply, a vec2
-- it is called during each call to draw()
function BrainUG:force(player)
    local ballToPlayer = player:pos() - ball:pos()
    local attackDirection = player.team.theirGoal:pos() - player.team.myGoal:pos()
    attackDirection = attackDirection:normalize()
    --if at full energy, charge hard
    local force = 80
    --if at 75%, use normal force
    if player.energy < player.energyMax * 0.75 then
        force = 20
    end
    local vecForce
    -- if the player is on the good side of the ball
    if ballToPlayer:dot(attackDirection) < -20 then
        -- then push the ball
        vecForce = -ballToPlayer:normalize()*force
    else -- else go back to my camp
        vecForce = -attackDirection*force
    end
    return vecForce
end

If anybody else wants to take a fresh stab at this, I suggest a wrinkle: use Brain01 as a base and try to do as little modification as possible.

I forgot to tag @Jmv38, in the odd chance he wanders by :wink:

I tried to make a brain where two members of my team are blockers, and they pick an opposing team member to bully, in order to drain its energy, but it was harder than I could figure out.

I kind of two of my players to focus on one of the opponents’ players, but everything’s so bouncy I couldn’t really get the energy-drain thing to work.

Any tips?

No takers?

I’m winning this by changing four lines of code, and I barely understand how the physics engine works, and none you all got nothin’?

not playing it but i might get to it