Search Unity

[AI Challenge] Capture the Flag

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

  1. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Finished!


    Results
    1. Team Blueberry (THoeppner)
    2. ArrowXRnd (ArowX)
    3. Spreader (Oribow)



    Deadline - April 24th, 2017

    Participate

    Documentation

    This is another community AI Challenge! Some may remember the original challenge by @Arowx, this one I hope to keep as consistent as possible and stick to a deadline.

    More information is located in the Github Repo and Wiki, here.

    I cant wait to see what you guys come up with! Good luck! If you find any issues just post below or contact me.

    Rewards ($250+)
    • First place
      • ($95 Value) Apex Path
      • Fame
      • The title of A.I. God or Goddess. Feel free to add it to your resume

    Rules
    1. You cannot store instances of objects, this includes but is not limited to, IAgent or Soldier classes and IGrabbable or Flag classes. These classes should not be accessed anywhere out of the callbacks provided.
    2. Using or Getting components of the following classes is prohibited, (UIManager, TeamManager, CameraManager, Spawn, Flag, Weapon, Soldier, AnimationController, PoolManager, PoolObject)
    3. Custom navigation systems are allowed, however the unity navmesh system is not, use the Grid provided to your advantage. (GridManager)
    4. You can only move using the MoveTowards and Move methods from the SoldierWrapper class.
    5. You cannot call the DropFlag method on any IAgent that does not belong to you.
    6. You cannot casts Ray outside of the RayCast method provided by the soldier class unless you have permission.
    7. No bug abusing or exploiting. If you see any bugs please notify me as soon as possible!
    8. Other prohibitions are specified in the Wiki.
    These rules should be self-explanatory for the most part. If you need to break any of these rules go ahead but they may not be allowed through to compete with others depending on the situtation.

    Note: The only thing you submit will be your scripts, so editing values of prefabs is fine as they will not be taken into account in the competition.

    Judging
    • The game will be judged with team sizes of 8v8.
    • 6 Rounds: The bot with the highest score will move on to the next elimination round.
    • After each round teams alternate. Your bots will play 3 rounds as red, and 3 as blue.
    • During judging your bots will go through a single-elimination tournament. More Info



    Credits
    • Denis Sylkin - RTS Camera
    • Unity - Unity Particle Pack
    • Marcelo Fernanadez Music - Music
    • Dogzerx (Jose Diaz) - Cartoon Soldier (@dogzerx2 <3)
    • Telecaster - Cloth animation based Flag 1.0

    I would appreciate any asset developers who are interested in providing rewards for winners, please contact me.

    If any level designers and artists would like to contribute, please contact me.
     
    Last edited: May 7, 2017
    chelnok, Not_Sure, gnshkamath and 3 others like this.
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Looks interesting, you should add screenshots and video and more in depth information or a basic overview of the game, weapon types, number of troops, duration, game rules.

    An FAQ maybe... Answers Based On Arowx's View Of Project.

    Is the game 2D or 3D? 3D
    What size will the arenas be? < 100m2
    How will the game score? Flag Capture or Team Obliteration
    How long will a game last? 2 minutes
    Will they be 2D or 3D?
    If 3D could the be played across multiple floors/levels of buildings? Flat Level Floor With 2m+ Blocking Walls
    Will the game have more advanced weapons, troop, equipment types? e.g. Overwatch/MOBA? No Just Guns
    Will the game have powerups e.g. Unreal Tournament Rocket Launcher, BFG? No
    Will the game have Close Combat, e.g. BF1 daggers/maces/bayonet charges or Kicks / Punches / Strangles / Takedowns? No
    Will the game have stealth? No
    Does the game use sound for enemy detection? No
    What about portals and jump pads? No
    Does health regenerate? No
    Do the troops have shields that deplete Halo style? No
    What about sniper weapons? No
    What about grenades? No
    Are you using the Blackboard AI approach for the teams? Not Built In
    Can teams learn a level and store their version of the map? Should Use In Built Grid Manager
    Are maps static or procedural? Currently Static
    Will maps have moving objects/platforms/vehicles? No
     
    Last edited: Mar 21, 2017
    Samuel411 likes this.
  3. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Ah yeah I forgot to put a picture lol. I added one. As for the other questions its just a simple shooter, you can see in the picture. I am uploading a video of the example AI right now. Also enemy detection is based on vision. Its possible to implement communication between your bots so that you can get your other bots to support each other and provide back up.

    Some of the other questions are posted in the Wiki and readme.

    Thanks for the reply I'm excited to see submissions.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Be careful. This sort of feature creep is exactly what made the last challenge fail.

    I'm keen to participate. I don't anticipate being able to produce anything by the deadline, two weeks isn't a long time for anyone to complete a side project. I would suggest stretching it out to allow more people to have a go.
     
    Ostwind and MV10 like this.
  5. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    I won't be participating because I don't have the time at the moment. I just wanted to say that it's pretty cool that you took your time to create this for the community. Hats off to you sir.
     
  6. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Yeah, don't worry I don't play on this being extended past what I have right now. Everything is modular however so you won't need to change your AI too much if I decide to change weapons (Highly unlikely) lol.

    I extended the deadline to a month and 4 days from today (April 24th) to give more time to participants.
     
  7. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Thank you, I should confess my selfishness however... Some of this was done to test my skills with creating something like this lol

    I extended the deadline so I hope to get you to reconsider but otherwise I understand. :)
     
    GarBenjamin and ADNCG like this.
  8. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646


    24 Bots!
     
  9. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    In! Thanks for organising this.

    Are we allowed to do raycasting from arbitrary points, or only from the soldiers POV?
     
  10. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Like raycasting from another point in space? No. I should add that to the rules list...

    You cannot Raycast outside of the soldier's 70 degrees of sight. I'm adding in a raycast handler to the SoldierWrapper class right now. Thank you for pointing it out.
     
  11. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    When you say we can't store instances of the classes, does this mean e.g. if a soldier raycasts ahead and finds a teammate, this teammate cannot be stored as a reference by its class?

    If not, can the information be stored as abstract variables, e.g.

    Code (CSharp):
    1. Class TeamMate{
    2.     int index;
    3.     Cell lastPosition;
    4. }
    5.  
    6. List<TeamMate> teamMates;
    Where the list is populated by doing a bunch of raycasts from each soldier?
     
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Any rules around this? Or can I just hand around direct references to all of my units and the information they have obtained?
     
  13. GarBenjamin

    GarBenjamin

    Joined:
    Dec 26, 2013
    Posts:
    7,441
    Obviously, I am not setting the rules (lol) but I think you'd have to be able to do this because this is what you'd do in real life. I think he is just saying don't cheat which is what storing references to the other entities is. Basically seems like he wants to see real AI like what you could have if you programmed some mini robots in the real world. They could store data collected such as team members and their locations.

    Of course, if communication is allowed as long as it is messaging (headsets, radio, etc).... :)
     
  14. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    You should not have to raycast forward yourself, wrapper should do it for you otherwise I added this to the SoldierWrapper just now. https://github.com/1samuel411/CaptureFlagAIChallenge/wiki/SoldierWrapper#raycast

    It'll handle any raycasts out of the view cone.

    Your code is fine, I mean holding the actual Agent interface allowing you to call IAgent.GetLocation() anytime you'd like, holding their last known position is fine though. :)
     
  15. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    Yeah, I didn't see the post that said we could communicate, thought maybe the soldiers were supposed to have a one frame memory span.

    One thing that bothers me a bit (if the challenge is to make a flexible AI) is that it would not be too difficult to hard-code some values that are driven by to the level layout, even indirectly. @Samuel411 I think maybe you should consider generating a similar but non-identical level at competition time, that would really test adaptability which is a huge part of making interesting AI.
     
    MV10 likes this.
  16. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    Also, since I can see the rules are driven by realism, it would be great to get a breakdown of what sort of communication options are allowed. A static information reference might sound unrealistic but if all the soldiers were within earshot, it's all the same. Otherwise, how can we pass information around?

    One more thing :) can we change the TeamManager class to spawn different prefabs with different specializations, or are all soldiers supposed to be the same at the start?
     
  17. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Got you covered like just now :) https://github.com/1samuel411/CaptureFlagAIChallenge/wiki/SoldierWrapper#get-team-soldiers. Going to have to clone and copy over the SoldierWrapper.cs file to get the new version.

    Returns a list of SoldierWrapper classes for your team mates which allows you to get your own component, move them around, shoot for them, etc. Lets just say they have a mic in their helmets ;)

    You can do anything you want in your project version however when I judge them currently the plan is to just drop your scripts onto them and any other scripts you might have for your soldier. All soldiers right now should be the same. I think I know what you mean though, and no, I think that might complicate it a little bit.
     
    Last edited: Mar 21, 2017
  18. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    A random level generator is something I'd definitely like to implement, might be a little too time consuming though. Perhaps pre-designed levels and cycling through those. Something for the future though, I think changing what I have now might make some things complicated.

    I can definitely say I'm learning a lot from this experience, seeing how I implemented two new functions in the last hour lol
     
  19. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    Sorry what I meant is that maybe you should make a different level for the competition, like by hand. I think it would help to keep people's stuff flexible.
     
  20. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Specialisation should be trivially easy to manage from your own code without needing to modify the TeamManager.
     
    Not_Sure likes this.
  21. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    @Samuel411 just to be clear :) since the SoldierWrapper class has a reference to the IAgent, does that mean it's ok to access teammates positions directly when accessing the list?

    @BoredMormon yes, now that I know that we can get a list of team mates directly - otherwise it would have been a bit tedious to sort out who was who from raycasting everywhere, and since the prefabs are all the same there would not have been an easy way to centralize the organisation.
     
  22. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Yeah you can use the SoldierWrapper class on team mates however you want and can GetComponent on them to get your own base classes
     
  23. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,023
    Great, and thanks again for taking the time to organise this! If it all goes well I might put one together for space combat.
     
    Samuel411 likes this.
  24. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    No problem :) helps me be a better programmer as well :)
     
    frosted likes this.
  25. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Just to confirm you seem to be acting as the game umpire, requiring submission to the challenge directly to you, is this how the competition is going to work?

    I found with the Tanks AI challenge a more open approach (posting your code to the forums) prompted people to be able to build up and improve on early challengers work and to compete with each other and try their bots out. So the challenge was as much a learning experience as a challenge.

    How can competitors validate the competitions outcome without an open approach?
     
    frosted likes this.
  26. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    You can post them here but I know some users would rather have their code hidden to prevent people from copying their project and algorithms.
     
    Not_Sure likes this.
  27. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Will all code be revealed when the deadline is reached so we can verify the winner and marvel at their AI?

    Raises an interesting Meta Game release full version of AI or dumb version to game other contestants?
     
  28. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Oh yeah all code will be revealed when the deadline is over. Don't want anyone thinking im running off with false results. I'm not sure what would motivate me to do something like that to be honest.
     
    Not_Sure likes this.
  29. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Definitely seems to be a couple of bugs:

    • Pathfinding issue where Soldiers get blocked by scenery, probably a rounding error issue, try rounding to int the spawn positions.
    • Soldiers can walk over each other.
    • Soldiers seeing through walls and shooting them, could be a LOS bug.
    • Raycast LOS should check from gun barrel offset.
    • Red Dots Are Not Recycled/Destroyed.
    • There is a time Scale Issue which is probably to do with fixed update delta not being scaled affecting physics (https://docs.unity3d.com/ScriptReference/Time-timeScale.html)
    Suggestions:
    • Team health bars (sum of total team health).
    • Team Counters.
    • Diagonal moves where not blocked.
    • Draws can be wins/losses based on surviving unit count and if equal health total.
    • Turn Speed at 65 degrees a second is way to slow IMHO should probably be 180-360.
     
    Last edited: Mar 21, 2017
  30. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Soldier.EyeSight() is very inefficient as it uses 60 raycasts per Soldier when a single Physics.OverlapSphereNonAlloc (https://docs.unity3d.com/ScriptReference/Physics.OverlapSphereNonAlloc.html) can detect all enemy soliders and flags in range. You can then do raycasts on all hits within the soldiers sight arc.

    You should also use https://docs.unity3d.com/ScriptReference/Physics.RaycastNonAlloc.html

    Note: Unless you run games with >60 team size.

    I tend to use OnTriggerEnter/Exit Sensor trigger colliders attached to the Unit/Soldier assuming Unity will manage it more efficiently than continuous Sphere casts. You could even offset a sphere collider to give a sort of forward arc.
     
    Last edited: Mar 21, 2017
  31. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Great, another AI community challange. Thumbs up :)

    I started with my own soldier but I stumbled over a problem with the GridManager.

    The GridManager.FindClosestCell(...) rounds the position vector not correctly to get the grid cell. You can't use just an int conversion here. It depends on if the given position values (x and y) are positive or negative and if the fraction is larger than 0.5 or not.

    I wrote an extension method for the Vector2 struct which you can use in your GridManager:

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public static class Vector2Extensions
    5. {
    6.     public static Vector2 ToGridCell(this Vector2 position, Vector2 gridSize)
    7.     {
    8.         Vector2 orgPosition = position;
    9.         float fractionX = (orgPosition.x >= 0) ? orgPosition.x - (float)Math.Floor(orgPosition.x) : orgPosition.x - (float)Math.Ceiling(orgPosition.x);
    10.         float fractionY = (orgPosition.y >= 0) ? orgPosition.y - (float)Math.Floor(orgPosition.y) : orgPosition.y - (float)Math.Ceiling(orgPosition.y);
    11.  
    12.         if (Mathf.Abs(fractionX) > 0.5)
    13.             orgPosition.x += (fractionX > 0.5) ? 0.5f : -0.5f;
    14.  
    15.         if (Mathf.Abs(fractionY) > 0.5)
    16.             orgPosition.y += (fractionY > 0.5) ? 0.5f : -0.5f;
    17.  
    18.         return new Vector2((int)Mathf.Clamp(orgPosition.x, -gridSize.x / 2, gridSize.x / 2), (int)Mathf.Clamp(orgPosition.y, -gridSize.y / 2, gridSize.y / 2));
    19.     }
    20. }
    21.  
    In GridManager you can use than just the extension method:

    Code (CSharp):
    1. public Cell FindClosestCell(Vector2 position, bool availableOnly = false)
    2.     {
    3.         position = position.ToGridCell(gridSize);
    4.  
    5.         Cell closestCell = grid[position];
    Hope it helps.

    And we see us on the battlefield :mad:
     
  32. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    ?Mathf.RoundToInt() https://docs.unity3d.com/ScriptReference/Mathf.RoundToInt.html
     
  33. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
  34. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    I use the round down method only because I used it to check if your inside the cell rather than a little bit close to it. I guess I named that method wrong and feel free to write any extensions for it. The grid is yours do as you wish just dont modify it ;)
     
  35. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    What does that mean exactly? Can we create or own GridManager? I thought your GridManager is part of the API and must be used by all agents?
     
  36. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    The grid/cells is yours to do as you wish. The GridManager just generates the cells you'll be using and is a wrapper for getting information about cells. You can make your own 'Grid Manager' but it needs to use the cells provided from the GridManager and those cells can't be modified. For example the GridManager has a method that gets cells in a region, you could write your own method that does the same or does something unique for example.
     
  37. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Hm, I would prefer a defined API for such functionalities so that everyone uses the same algorithms but I know this would mean much effort for you.

    Maybe we can discuss this after the challange. I'm thinking a well defined and documented API would make this topic also more interesting also for others. I would like to work on it.
     
  38. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    I have all the classes that might be used documented in the Github Wiki available here, https://github.com/1samuel411/CaptureFlagAIChallenge/wiki
     
  39. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    Ok, cool. I will check it.
     
  40. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    Bots can't stand on top of eachother right? I mean, if they can there's a pretty obvious winning strategy.

    Would it be cool if I just posted some code to analyze the map for anyone to use if they want? I don't wanna do a full on entry....my tactics would be way too cheesy ;D
     
  41. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Ideas:
    • What about adding half height walls that block movement but allow LOS and shooting. They should work without any major changes to the current simulation (maybe LOS test point would need to be raised a bit).
    • Using Navmeshes for pathfinding, free diagonals and faster pathfinding but keeping GridManager for level awareness.
     
    Last edited: Mar 22, 2017
  42. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    Haha. Nah bots don't have collision set for each other. You can post any code you want here but just know other people could take advantage of it ;)
     
  43. Samuel411

    Samuel411

    Joined:
    Dec 20, 2012
    Posts:
    646
    1. I don't want to change this too much after releasing it.

    2. The navmesh call was a good call lol. Originally I wanted people to do path finding themselves as well but eh. It was too gridy. I changed up the NavAgentExample class. It should be used the exact same except the path generated is a list of Vector3's instead of Cells. :) :)

     
  44. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    I think you might need some time to get it right or make it as good as possible before it's challenge ready. Then you will have the chance to provide a better challenge.

    Idea:
    • Sight Range Extended If Static - If a soldier stand still for a frame their visual range doubles. In effect allowing for better choke points and a form of 'sniping' and only needs a Boolean flag.
     
  45. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    So, just to clarify - you can just stack all your guys up on one spot and move them all at the same time? Wouldn't that like be the entire game then - which stack shoots first?

    You move like 1 at a time with bounding overwatch into the next square so you are guaranteed 3 shots minimum if an enemy moves into LOS.

    I could be imagining this wrong, but it seems like it gets a little degenerate pretty quick no? I think you gotta have friendly fire and collision or it might get kinda silly.
     
    Not_Sure and Arowx like this.
  46. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Tried the half height walls and they just work, blocking movement but allowing shooting over. Free windows and short walls and of course crates.

    Now adding crouching where you can hide behind short walls and pop up to shoot and you have basic stealth.
     
  47. frosted

    frosted

    Joined:
    Jan 17, 2014
    Posts:
    4,044
    you can't do this - not moving is i think an advantage because you shoot first. moving is when you're vulnerable, especially crossing an edge. if you just never move in a corner you are guaranteed either a draw or win. the only reason to move is that if both players just dont move its a draw, so you might want to risk moving for a chance at a win.

    sorry - see, i am not in the spirit of the game and thinking mega cheese already ;D

    you need to make sure there is incentive to move, and you need to make sure there is a need to create a vulnerability. w/o friendly fire and collision i think there might be a couple problems that crop up.
     
    Last edited: Mar 22, 2017
  48. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194


    My attempt at a level, note the half height cells that troops can see and shoot over! It looks complex but attempts to incorporate a number of choke points and killing lanes of various lengths.

    Shooting Galley Left side, Column Alley Horizontal Bottom, Arena Centre, Catacombs Right, and Path Top.

    I've been looking at CS:GO levels and their designs and basic ramps or a ground mesh with levels could massively improve the levels, providing high and low ground advantages/disadvantages.
     
    Last edited: Mar 22, 2017
    Samuel411 likes this.
  49. Mordus

    Mordus

    Joined:
    Jun 18, 2015
    Posts:
    174
    This.
    My first thoughts when i read the thread was .. just have all your units bunch up together and move as one .. and a couple other thoughts i'm going to keep to myself :p.
     
    Not_Sure and Arowx like this.
  50. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    In the game you can move and shoot at the same time, the only issue is the current slow turn rate (65 degrees a second) that makes standing still necessary for your gun to line up with the target.

    Each frame the soldiers scan their line of sight cone (120 degrees), my idea is the range of that cone could be extended if the soldier is not moving and did not fire the last frame.

    Soldiers can also only see for 15m within their sight cone. If they stand still and do not fire for a frame this range could be extended providing a sniper style tactic for very little work.
     
    Last edited: Mar 22, 2017