<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Comment Feed for Channel 9 - Building Battling Bots with DumbBots.Net</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet/RSS"></atom:link>
	<image>
		<url>http://files.channel9.msdn.com/thumbnail/6dfd2182-5870-47ae-8495-ea0768908c40.png</url>
		<title>Channel 9 - Building Battling Bots with DumbBots.Net</title>
		<link></link>
	</image>
	<description>Today&#39;s project was one that I just happened across and I thought kind of cool, I mean what&#39;s more fun than programming bots to hunt down a kill each other? (Answer: Playing with the source of the project that lets you program bots to hunt down and kill each other) DumbBots.NetProject DescriptionA simple programming game that allows editing of scripts while the game is still being run. The scripts control the AI of some combatants in a Quake III-style game. The game can be used as a tool to get people interested in coding, or simply as a competitive game between different code. Some extensibility provided to create a simple sandbox environment. A &amp;quot;director&amp;quot; AI can be programmed to alter the dynamics of the game for a customizable experience. Scripts are currently written in C#. Features Program scripts while game is in play to immediately view results Scintilla.NET code editor Basic &amp;quot;intellisense&amp;quot; to quickly find method needed &amp;quot;Director&amp;quot; AI allows a customizable experience - change the game rules, load custom models, etc Basic messaging system allows interaction between different AI&#39;s Powered by Irrlicht engine   The arena is 3D which is kind of cool too;   Included is a simple map editor;  Here&#39;s the Solution;  So how does it work? Here&#39;s an abbreviated view of the code path that handles the runtime code compiling. private void btnCompileTeam1_Click(object sender, EventArgs e)
    {
        CompileScript(Team.Team1);
    }
private void CompileScript(Team team)
{
    SoundManager.PlayUpdate();
    ScriptCompiler sc = new ScriptCompiler();
    List&amp;lt;string&amp;gt; dllList = new List&amp;lt;string&amp;gt;();

    //TODO: need to reimplement referencing assemblies

    if (team == Team.Director)
    {
        rchTxtBoxErrors.Text = sc.CompileDirectorScript(&amp;quot;C#&amp;quot;, _txtCode.Text, dllList);
        ScriptRunner.ReflectDirectorScript();
    }
    else
    {
        rchTxtBoxErrors.Text = sc.CompileScript(&amp;quot;C#&amp;quot;, _txtCode.Text, (int)team, dllList);
        ScriptRunner.ReflectScript(team);
    }
}

internal string CompileScript(string language, string code, string fileName, List&amp;lt;string&amp;gt; dllList)
{
    CodeDomProvider cdp = CodeDomProvider.CreateProvider(language);
    CompilerParameters cp = new CompilerParameters();

    cp.OutputAssembly = fileName;
    cp.ReferencedAssemblies.Add(&amp;quot;DumbBots.NET.exe&amp;quot;);
    cp.ReferencedAssemblies.Add(&amp;quot;System.dll&amp;quot;);
    cp.ReferencedAssemblies.Add(&amp;quot;System.Drawing.dll&amp;quot;);
    cp.ReferencedAssemblies.Add(&amp;quot;Irrlicht.NET.dll&amp;quot;);
    for (int i = 0; i &amp;lt; dllList.Count; i&amp;#43;&amp;#43;)
    {
        cp.ReferencedAssemblies.Add(dllList[i]); //Add external DLLs mentioned in user script
    }

    cp.WarningLevel = 1;

    cp.CompilerOptions = &amp;quot;/target:library /optimize&amp;quot;;
    cp.GenerateExecutable = false;
    cp.GenerateInMemory = false;

    System.CodeDom.Compiler.TempFileCollection tfc = new TempFileCollection(AppDomain.CurrentDomain.BaseDirectory, false);
    CompilerResults cr = new CompilerResults(tfc);

    cr = cdp.CompileAssemblyFromSource(cp, code);

    StringBuilder sb = new StringBuilder();

    if (cr.Errors.Count &amp;gt; 0)
    {
        foreach (CompilerError ce in cr.Errors)
        {
            sb.AppendLine(ce.ErrorNumber &amp;#43; &amp;quot;: &amp;quot; &amp;#43; ce.ErrorText &amp;#43; &amp;quot; Line: &amp;quot; &amp;#43; ce.Line);
        }
    }
    else
    {
        sb.AppendLine(&amp;quot;Build succeeded&amp;quot;);
    }

    return sb.ToString();
}

internal static void ReflectScript(Team team)
  {
      try
      {
          byte[] rawAssembly = LoadFile(String.Format(&amp;quot;AI\\AIscript{0}.dll&amp;quot;, (int)team));
          Assembly assembly = AppDomain.CurrentDomain.Load(rawAssembly);

          TeamScripts[team] = (ICommand)assembly.CreateInstance(&amp;quot;Scripting.AIScript&amp;quot;);

          assembly = null;
          rawAssembly = null;
      }
      catch (Exception)
      {
          TeamScripts[team] = null;
      }
  }
 If you&#39;ve ever thought about building bots that battle, interested in runtime code compiling or just looking for something fun to play with, here you go... </description>
	<link></link>
	<language>en</language>
	<pubDate>Wed, 22 May 2013 11:41:33 GMT</pubDate>
	<lastBuildDate>Wed, 22 May 2013 11:41:33 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<item>
		<title>Re: Building Battling Bots with DumbBots.Net</title>
		<description>
			<![CDATA[very nice<p>posted by moutlou</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634728502278362860</link>
		<pubDate>Thu, 17 May 2012 11:17:07 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634728502278362860</guid>
		<dc:creator>moutlou</dc:creator>
	</item>
	<item>
		<title>Re: Building Battling Bots with DumbBots.Net</title>
		<description>
			<![CDATA[<p>You might as well check Marvin's Arena ( <a href="http://www.marvinsarena.com/">http&#58;&#47;&#47;www.marvinsarena.com&#47;</a> ) <img src='http://ecn.channel9.msdn.com/o9/content/images/emoticons/emotion-1.gif?v=c9' alt='Smiley' /></p><p>posted by SPech</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634739608633360436</link>
		<pubDate>Wed, 30 May 2012 07:47:43 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634739608633360436</guid>
		<dc:creator>SPech</dc:creator>
	</item>
	<item>
		<title>Re: Building Battling Bots with DumbBots.Net</title>
		<description>
			<![CDATA[<p>@<a href="/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634739608633360436?areaType=Blogs&amp;areaName=Coding4FunBlog">SPech</a>:Nice! Thanks for the heads up on that.</p><p>posted by gduncan411</p>]]>
		</description>
		<link>http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634739799387033960</link>
		<pubDate>Wed, 30 May 2012 13:05:38 GMT</pubDate>
		<guid isPermaLink="true">http://channel9.msdn.com/coding4fun/blog/Building-Battling-Bots-with-DumbBotsNet#c634739799387033960</guid>
		<dc:creator>gduncan411</dc:creator>
	</item>
</channel>
</rss>