Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Artificial Intelligence (AI) competition proposal

Jmv38Jmv38 Mod
edited August 2012 in Competition Posts: 3,295

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:


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!

Comments

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Brain number 1:

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Brain number 2:

  • edited August 2012 Posts: 371

    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?

  • Posts: 371

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

  • Jmv38Jmv38 Mod
    edited August 2012 Posts: 3,295

    @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.

  • Jmv38Jmv38 Mod
    edited August 2012 Posts: 3,295

    @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.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @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?

  • Posts: 371

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

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @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!

  • Posts: 2,161

    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?

  • Jmv38Jmv38 Mod
    Posts: 3,295

    @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!

  • Jmv38Jmv38 Mod
    Posts: 3,295

    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.

Sign In or Register to comment.