LukasPJ Posted February 15, 2017 Share Posted February 15, 2017 Hey guys!Here's a minor challenge and request for you! My teammate (Simon Jensen) and I are working on my master thesis, which consists of the following components: We will make a game. People will write AI's for the game. We will write a reinforcement learnt AI, which trains on the previously mentioned AI's and attempts to beat them. We are almost done with the game, and we are gonna arrange a hackathon, where people can develop AI's which will compete. However, we could always use more ai's, and we would like to work out some of the quirks before the hackathon, so I'm hoping some of you will try and implement an AI for the game!The AI's are implemented in C#, you will implement a function which you can name anything you want, for example it could be named "MyThinkMethod". This method takes a FeatureVector and returns a PlayerAction. Whatever you do inside this function is up to you, as long as you don't access any other information from Torque3D than what is given in the FeatureVector, and don't try to manipulate the state of Torque3D. We didn't have time to patch up all the security holes there are.Here's a simple example of an AI that simply moves forward:using Torque3D; using Torque3D.Engine.Util.Enums; namespace GameAI { public class AIClass { [ConsoleFunction] public static PlayerAction MyThinkMethod(FeatureVector vector) { return PlayerAction.MoveForward; } } } And here is an example which avoids obstacles:using Torque3D; using Torque3D.Engine.Util.Enums; namespace GameAI { public class AIClass { [ConsoleFunction] public static PlayerAction MyThinkMethod(FeatureVector vector) { if (vector.DistanceToObstacle < 1.5f) return PlayerAction.TurnRight; return PlayerAction.MoveForward; } } } Getting started is simple! Just download the game (Winx64 compiled on Windows 10) here. Open the VS solution in the aiProject folder. It should be able to compile right away, so see if the solution compiles.The solution is a simple C# solution, with a single class, which references the Torque3D.dll and outputs to the aiLibs folder. All dll's in the aiLibs folder will be probed for static functions with the [ConsoleFunction] attribute, so you can have multiple AI's in different dll's. You will see I left a simple one for you to try and beat :)Then simply run the Game.exe file. When the main menu loads, select "SinglePlayer" and "StartLevel" and then you should see the following screen:[himg=200]http://i.imgur.com/RsENGnx.png[/himg]Now you can write in the name of the function that the AI should use (there is a bad one for default). For example you could write "MyThinkMethod" or "LukasThink" like so:[himg=200]http://i.imgur.com/mefQRgg.png[/himg]Now, you should see the game running which looks like this. The Player 1 is the blue one, Player 2 is green.uEtxfZ6CLVo Please tell me if anything is unclear and thank you so much if you take a look at this. Feel free to report bugs, errors, stuff that is not properly explained etc. And if you make a cool AI, please post it here so we, and everyone else, can download it and compete against it! :)Happy coding!Edit:You control the camera with WASD + E for up and C for down.Edit:Game mechanics!This is fairly important, I guess.. The game mechanics are as follows:T3D has the standard 32ms tickrate. Each tick allows both players to take 1 action (i.e. one call to their think function). The players can take the following actions: None - Do nothing MoveLeft - Strafe left MoveRight - Strafe right MoveForward - Move forward MoveBackward - Move backward TurnRight - Turn right at a rate of 2 degrees per tick TurnLeft - Turn left at a rate of 2 degrees per tick Shoot - Shoot once, with a probability of missing. If the shoot delay is greater than 0, this action will fail. Prepare - Save one action for next round Now, we can take a bunch of actions, but what information are we basing it on? The idea is that you have limited information about the game world. When an enemy is within your FOV, you can't tell for sure where it is. So you will have to rely on the Damage Probability.When a player is in your FOV, there is a certain probability that you will hit the player, and thus a probability that you miss. The closer the enemy is to the center of your FOV, the higher the probability. We use a Normal distributed PDF, so the probability quickly drops.This is the full list of information you get in the so-called "FeatureVector": Change in rotation Change in movement Velocity The probability that a shot at the current tick will result in damaging the other player The change in "Damage Probability" Current health Current health of the enemy Distance to obstacles directly in front of you Ticks since the game started Ticks since an enemy was last observed (i.e. since damage probability > 0) Ticks since damage was last taken Delay in ticks before you can shoot again Quote Link to comment Share on other sites More sharing options...
Duion Posted February 16, 2017 Share Posted February 16, 2017 Are you using BadBehavior ? I use those behavior trees and found them really easy to use and practical. Just an idea. Quote Link to comment Share on other sites More sharing options...
JeffR Posted February 16, 2017 Share Posted February 16, 2017 This looks pretty sweet. I'll have to dick around with this this weekend :D Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted February 16, 2017 Author Share Posted February 16, 2017 Are you using BadBehavior ? I use those behavior trees and found them really easy to use and practical. Just an idea.Nope, I dunno if BadBehavior was an option, but there's not really any AI stuff in there. I custom-wrote a Player class for the purpose and made the "ThinkMethod" functionality. Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted February 17, 2017 Author Share Posted February 17, 2017 New update!Important changes:Renamed "killProb" to "damageProb" where applicable.Fixed places where "prob" was spelled "prop".Added the health of the enemy to the feature vectorEvery round now has a timer, if timeout both players loses There were also minor UI changesAvailable here: http://www.filedropper.com/sharpshooter-deploy_1 Quote Link to comment Share on other sites More sharing options...
JeffR Posted February 21, 2017 Share Posted February 21, 2017 As per my comment in irc, ran into some trouble running it. Here's the command prompt output: Microsoft Windows [Version 6.1.7601]Copyright © 2009 Microsoft Corporation. All rights reserved.D:\gamedev\T3DMIT\SharpShooter-Deploy>game.exeUnhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///D:\gamedev\T3DMIT\SharpShooter-Deploy\aiLibs\LukasAI.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information. --- End of inner exception stack trace --- at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm,Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at Torque3D.Initializer.InitializeTypeDictionaries(String path) in C:\Speciale\Game\Torque3D\My Projects\Empty\buildFiles\c#\Torque3D\Torque3D\Initializer.cs:line 19 at Game.Program.Main(String[] args) Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted February 21, 2017 Author Share Posted February 21, 2017 As per my comment in irc, ran into some trouble running it. Here's the command prompt output: Microsoft Windows [Version 6.1.7601]Copyright © 2009 Microsoft Corporation. All rights reserved.D:\gamedev\T3DMIT\SharpShooter-Deploy>game.exeUnhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///D:\gamedev\T3DMIT\SharpShooter-Deploy\aiLibs\LukasAI.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information. --- End of inner exception stack trace --- at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm,Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at Torque3D.Initializer.InitializeTypeDictionaries(String path) in C:\Speciale\Game\Torque3D\My Projects\Empty\buildFiles\c#\Torque3D\Torque3D\Initializer.cs:line 19 at Game.Program.Main(String[] args) Huh, that is a weird issue. Try deleting the LukasAI.dll file, apparently it is out-of-date or something similar. Quote Link to comment Share on other sites More sharing options...
Johxz Posted February 25, 2017 Share Posted February 25, 2017 @LukasPJ Bro I can't download the game, the link is broken or something.... Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted February 25, 2017 Author Share Posted February 25, 2017 @LukasPJ Bro I can't download the game, the link is broken or something.... Gimme a day, I just had the Hackathon, and I found a bunch of issues, which I will solve.This is the presentation we used today:http://lukasj.org/sharpshooter/#/There is a download link at:http://lukasj.org/sharpshooter/#/14But atm you have to delete, the dll's inside the "AiLibs" folders before it works. I'm working on updating the deployment zip so it works out of the box :P I'm also creating a subreddit for the game, as we intend to keep supporting the game during our thesis :)It incurs to me that I should probably have posted the livestream of the tournament here.. Quote Link to comment Share on other sites More sharing options...
JeffR Posted March 3, 2017 Share Posted March 3, 2017 I got myself sick for most of the weekend and first half of this week, so I didn't get to do much with this like I wanted to, but it's cool that it sounds like the tourney went well.Did the stream get archived anywhere? Quote Link to comment Share on other sites More sharing options...
LukasPJ Posted March 3, 2017 Author Share Posted March 3, 2017 I got myself sick for most of the weekend and first half of this week, so I didn't get to do much with this like I wanted to, but it's cool that it sounds like the tourney went well.Did the stream get archived anywhere?Thanks for reminding me to update this! I made some updates, I now have a small, slightly active, community at https://www.reddit.com/r/SharpShooter/The code is, of course, open source and I will do tournaments regularly to update ranking The stream didn't get archived, but all the bots (5 of them) are available, so one can see them in action locally :) Small video here : Quote Link to comment Share on other sites More sharing options...
JeffR Posted March 5, 2017 Share Posted March 5, 2017 Awesome!I'll be having a poke around :)Also, you need to update your C-Interface PR with the current stuff so I can get that merged in! :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.