Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[AI Challenge] Capture the Flag

Discussion in 'General Discussion' started by Samuel411, Mar 20, 2017.

  1. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Coffee makes me gassy :<

    And yeah I guess I was still asleep, I fixed it.
     
  2. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Go for it! Can't wait to see what you come up with :D
     
  3. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    I'm going to add the current submissions (yours and ArrowX's) to the repo so others can try them out while testing.
     
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Nice mix of ambush and attack with good LOS angles! Well done.
     
  5. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Thanks, but it works mainly if the enemy just runs straight to the flag and tries to capture it. If he has a similar tactic it would end in a draw.
     
  6. Oribow

    Oribow

    Joined:
    Nov 9, 2012
    Posts:
    38
    Thanks for sharing your AIs. It's really helpfull for testing. Let me return the favor, by sharing an AI approach of mine.
    I only use it for testing, so do what you want with it.

    I named it "Spreader".
    It's quite similiar to the Blueberry AI. 7 of the 8 bots will run to predetermined points and the 8th will try to get the flag. If he dies, a new Bot is choosen to make the dash for the flag. Once the flag is obtained, all bots return to the home base.

    In tests with ArrowRnd and Blueberry, this approach beats ArrowRnd in 70% of the cases. But it can't beat Blueberry in any way. Each bot walking to the flag gets taken down one by one.
     

    Attached Files:

    Samuel411 likes this.
  7. Oribow

    Oribow

    Joined:
    Nov 9, 2012
    Posts:
    38
    @Samuel411 What actually happens, if both teams kill the same amount of bots and no team gets the flag? I mean certain bot setups could lead to all matches ending in a draw. Who wins in that case? (For example: Blueberry against Blueberry ends in 3 out of 3 matches I've seen in a draw)
     
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    @Samuel411 Cool now we just need an AI test harness and score card (it will save you time later)!
     
  9. Oribow

    Oribow

    Joined:
    Nov 9, 2012
    Posts:
    38
    A little code snippet for thoose who want a better representation of the view cone.
    It connects the two border lines of the view field with a circle sector. I also added a little circle around the soldier and colored the whole thing in theire respective team colors.

    Code (CSharp):
    1. if (IsDead())
    2.             return;
    3.         Gizmos.color = GetTeam() == Team.Type.A ? Color.red : Color.blue;
    4.  
    5.         float pointsPerRad = 100f / 360f;
    6.         float circleRad = 0.4f;
    7.         int circlePoints = 100;
    8.  
    9.         Vector3 prevPoint = new Vector3(Mathf.Cos(0) * circleRad, 0.1f, Mathf.Sin(0) * circleRad);
    10.         Vector3 newPoint;
    11.         float degrees;
    12.         for (int iPoint = 1; iPoint < circlePoints; iPoint++)
    13.         {
    14.             degrees = ((float)(iPoint) / pointsPerRad) * Mathf.Deg2Rad;
    15.             newPoint = new Vector3(Mathf.Cos(degrees) * circleRad, 0.1f, Mathf.Sin(degrees) * circleRad);
    16.             Gizmos.DrawLine(transform.TransformPoint(prevPoint), transform.TransformPoint(newPoint));
    17.             prevPoint = newPoint;
    18.         }
    19.         newPoint = new Vector3(Mathf.Cos(0) * circleRad, 0.1f, Mathf.Sin(0) * circleRad);
    20.         Gizmos.DrawLine(transform.TransformPoint(prevPoint), transform.TransformPoint(newPoint));
    21.  
    22.         circlePoints = (int)(viewRadius * pointsPerRad);
    23.         prevPoint = new Vector3(0, 1, 0);
    24.         float degreeOffset = -(viewRadius / 2 - 90) * Mathf.Deg2Rad;
    25.         for (int iPoint = 0; iPoint < circlePoints; iPoint++)
    26.         {
    27.             degrees = ((float)(iPoint) / pointsPerRad) * Mathf.Deg2Rad + degreeOffset;
    28.             newPoint = new Vector3(Mathf.Cos(degrees) * viewDistance, 1, Mathf.Sin(degrees) * viewDistance);
    29.             Gizmos.DrawLine(transform.TransformPoint(prevPoint), transform.TransformPoint(newPoint));
    30.             prevPoint = newPoint;
    31.         }
    32.         degrees = viewRadius * Mathf.Deg2Rad + degreeOffset;
    33.         newPoint = new Vector3(Mathf.Cos(degrees) * viewDistance, 1, Mathf.Sin(degrees) * viewDistance);
    34.         Gizmos.DrawLine(transform.TransformPoint(prevPoint), transform.TransformPoint(newPoint));
    35.         prevPoint = new Vector3(0, 1, 0);
    36.         Gizmos.DrawLine(transform.TransformPoint(prevPoint), transform.TransformPoint(newPoint));
     
  10. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Likely ill just pair them up with other submissions till one falls. If two are at the finals and a draw happens ill buy an apex path license for the other winner lol
     
  11. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Hm what do you mean?
     
  12. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    A challenge manager that plays all challengers against each other and records the scores on a grid, like the one I made for the Tank AI challenge.
     
  13. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Yeah that's the plan :)
     
  14. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Just a reminder nearing 5 days until the competition is over! Keep em coming!
     
  15. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Working on mine atm, sorry I'm late!
     
  16. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    So I was having a look at the current submissions and was very impressed by @THoeppner 's use of angles and cover, but I noticed that the positioning was all hard-coded. I think it would be good if something came out of this challenge that was more flexible and dynamic.

    So I began with a script that processes data gathered using the public GridManager CheckAvailability () function (I hope this is allowed?).

    It calculates all of the points belonging to separate obstacles (using connected-components labelling), and stores the centroid, bounding box and all the perimeter values that a soldier can hide in for each obstacle (currently Vector2, but these can be used directly as keys to get the corresponding cell). Hopefully any of you can use this to calculate tactical stuff such as moving to cover, attacking covered enemies etc, in a dynamic way.

    It can also create a texture with the information on it, and display it on a material if you assign the material.

    NOTE: obstacle at index 0 is the negative obstacle(empty ground), and obstacle at index 1 is the surrounding wall, so you might want to disregard those.

    Edit: pics (color coded by hue-shifting using the obstacle index)

    Obstacles
    Obstacles.png

    Perimeters
    Perimeters.png

    Obstacle centers
    Centroids.png
     

    Attached Files:

    Last edited: Apr 21, 2017
    frosted likes this.
  17. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    @Billy4184

    Nice - I also wanted to participate but my algorithm required to know the positions of the obstacles.
    • In my understanding @THoeppner 's solution is not compatible with the rules because of the hardcoded positions
    • I was too lazy to think about a solution for dynamically creating the map data
    • I am wondering if your solution is compatible with the rules - if it is, I believe based on another rule, that you can create an AI that will not loose.
     
  18. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Yes you're right. Due to the lack of time I hard-coded all the positions and rotations of my bots. There was not enough time to create a general approach to calculate the best hiding positions for a randomly generated level.

    I want to work on it now, but first I want to have a more flexible API to command the bots. I started my own little project for this. Let's see how far I come with it :)
     
  19. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Why do you think so?

    There is no rule which says that this is forbidden
     
  20. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Not sure what you mean, but note that the CheckAvailability method provided by GridManager does not take into account whether an enemy is there - the raycast uses a mask which only detects the ground. So I don't think it's possible to create an infinitely good AI just by knowing the map better?

    Hope you can find a use for my script there.

    I must say, you did a great job figuring out the best angles. I don't think there are two better places than the ones you chose, with the possible exception of the box obstacle in between them. And your AI consistently won over the other submissions in my tests, seems so far you're the person to beat!
     
  21. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Thanks :D
     
  22. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    @THoeppner because I asked @Samuel411 if it was allowed at the time I thought I would still participate and he said it was not

    @Billy4184 I applaud what you did. I did not look into your code, but I would assume if it is basically drawing a map based on visuals from the soldiers, it should be allowed. I don't know if the checkavailability works on the map, even if soldiers have no line of sight. In this case there is little difference from hard coding the locations. @Billy4184, I did not keep my AI strategy (it was handwritten) but i remember bits and pieces PM me if interested.

    I think it is best to let Samuel reply, it is his challenge and I really like what he did. He would be better to answer what is legitimate and what now. I was just sharing my understanding.
     
  23. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    This is allowed since he is using the CheckAvailability method and not storing a list of vector3's of hiding spots, hiding points, etc.

    Sorry for the late replies, finals (yay) are coming up :( Results will most likely be May 4-5. Around there. Keep them coming, 2 more days!
     
  24. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    Great that CheckAvailability methods works (edit: I meant "is allowed") - I wish I had come up with this as it would have allowed me to implement my AI idea - it's too late now for me, but I hope you will do another challenge after this one.

    I think the rule that "hardcoding POI" is not allowed did not stand out enough - I am happy I verified this with you but it seems others like @THoeppner were not aware.
     
  25. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    I'm sorry I had interpreted your inquiry as being you having a list of gameobjects of the scene or having a empty gameobject as references to cover points or something before having the game run.

    I'm going to have a post mortem posted once the results are in case anyone decides to run a competition of their own they can learn from any failures or successes I have had. It is likely that I will run another competition depending on how my upcoming projects come up but currently it looks like there will be one. I'd really like to see something like Ludum Dare but for small things like this where you get a "game" and the competition is adding something specific thing to that game.

    Thank you for reaching out that first time and following with the project, I'm glad to have attained your attention thus far.
     
  26. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Hey @Samuel411 can you give an exact date and time for the deadline?
     
  27. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    11:59:99 pm on April 24th EST time. I'll still accept anything that comes in the morning after, I know that time zones sometimes restrict people.
     
    Billy4184 likes this.
  28. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    Hi, I think I have to clarify something :) I confused in my earlier posts @THoeppner with @Oribows.

    A while ago, I considered participating and downloaded a GIT version, this had 3 submissions in it.

    What confused me at the time was, that they were likely not checked for compatibility with the rules and hence I was unsure if they can be used as examples or not. I asked @Samuel411 if hardcoded locations were allowed and he confirmed that they were not.

    As a lesson learned, I would suggest to only include submissions in GIT that are checked for compatibility with the rules, otherwise it can be misleading for others.

    Excerpt from the SoldierSpreader AI that was included in my download from GIT
    Code (CSharp):
    1.     Vector3[] poi = new Vector3[]
    2.     {
    3.         new Vector3(8.356801f,0,-7.617511f),
    4.     new Vector3(12.2468f,0,-10.36751f),
    5.     new Vector3(4.146801f,0, -3.337511f),
    6.      new Vector3(-3.633199f,0, 4.892489f),
    7.       new Vector3(-11.5532f,0, 11.93249f),
    8.       new Vector3(-7.813199f,0, 8.932488f),
    9.     };
     
  29. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Just while it's on my mind, I think it would be good in future to have something like a 'practice competition' halfway through to sort of get people moving - I didn't start until very late and of course that's my fault, but I think that not having a huge period of general silence from the competition would help keep it fresh in people's minds. Just an idea :)
     
  30. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Hm I guess you are right. These were made for people to have more options to test against. Ill have to write more examples in future competitions.
     
  31. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Line of sight for dynamically evaluating good firing/cover positions ... bit slow though ...

    LOS.png
     
  32. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Looks neat :)
    I have an i7 cpu so i hope I'll be able to handle it if you submit it. Maybe saving that data somewhere rather than generating it everytime might be a good idea? If its in the update loop maybe try having it only run when the current node in the grid changes?
     
  33. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Yeah it was just horribly unoptimised. I have it down to 2 seconds on my laptop now for evaluating LOS everywhere from all of the possible cover positions on the map.

    Now I just need to find a way to valuate them. Hope I scrape through with something tonight.
     
    Samuel411 likes this.
  34. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Submissions will be closed in an hour people! Submit your final entries soon!
     
  35. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    What, I thought you wrote 11:59 pm?
     
  36. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Anyway never mind, I need to get some sleep and mine is nowhere near done, so I won't be entering this one :(
     
  37. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Huh never mind it ends in 10 hours from now. Sorry peoples. Keep them coming! I don't know what I was thinking...
     
  38. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    The Challenge is officially over, thank you for people who participated and responded to the thread :) I appreciate everyone's help and encouragement.

    I'll begin recording results and submissions tomorrow morning :)
     
    Billy4184 likes this.
  39. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    Thanks for organising it!! Wish I hadn't left mine so late, but I suppose we can still tinker around with stuff anyway.
     
  40. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Yeah, thanks for the cool challange. Hope we can see the winner AI also in action :)
     
  41. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Arowx and Billy4184 like this.
  42. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Good work, I was hoping there would be more entrants.

    What do you think we could do to make it easier/better for future AI challenges?

    Would a trial, test and adjust period for the challenge work to improve it before people take part?

    Could or does the challenge need to provide more AI sensor features?

    We have tried tanks and soldiers, what might the next AI challenge involve?
     
  43. sngdan

    sngdan

    Joined:
    Feb 7, 2014
    Posts:
    1,154
    I was a big fan of this project but due to time constraints could not participate.

    Things I think would keep such an AI challenge interesting are in my view:
    • Random level generation (or at least unknown until submission deadline)
    • Keep framework as much as possible simple and stable (current one seems to be fine), only bug fixes and must have improvements based on learnings from previous challenges
    • Enhance clarity of ruleset + good documentation
    • Have a well documented example AI in the project
    • If the tournament is kind of automated, repeat it at the end of each month (provided new entrant) and have monthly winner
    • Try to get a sponsor (Unity, Asset owners) to have a price for the monthly champion (if there is a new one)
     
  44. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
  45. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Wow, my Bots really won. Well done, men!!! :D

    But it's sad that there were only three entries. I hoped more people would take part in it. I'm thinking you can learn much from other people solutions.

    It would be good when the people who didn't participate say why they didn't do. One reason I left the tank challenge was that there were too many changes during the challenge. This was much better here. A well documented API is a must have. And the API must be easy to understand and to use.

    A trial phase like @Arowx suggested could be good. This can help to fix errors and to build in features the people want and need. But this can also upset some people if you ignore their wishes.

    We had now two challenges were the AI must fight against each other. Maybe an AI for a simple dexterity game could be fun.
     
  46. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    I think it would also help to 'break in' the competition by having a preliminary competition, maybe two weeks in, where nobody actually gets judged, but rather just allows people to publicly see their stuff in action, work out the kinks and generate interest and excitement in the whole thing. It would also get competitors invested in it early rather than allowing them (like me!) to sit around doing nothing until the last day.