Bienvenue à Blogs CodeS-SourceS Identification | Inscription | Aide

Project Hoshimi, tutorial for beginners (Part 2)

Defining your bots

How to define a bot ?

You have to define the behaviour of your bots. Each bot you define have to inherit from a SDK bot, for example if you want to inherit from NanoCollector, you have to do :

    [Characteristics(ContainerCapacity = 20,
        CollectTransfertSpeed = 5,
        Scan = 2,
        MaxDamage = 4,
        DefenseDistance = 12,
        Constitution = 7)]
    public class XCollector : NanoCollector
    {
    }

Before each class of bot you define, you must add a Characteristics attribute. This will define the properties of your bot. You have to distribute an amount of points in 6 categiries.

  • ContainerCapacity : this is the amount of AZN units your bot can carry (20 maximum for NanoCollector, 50 maximum for NanoContainer, 0 for others)
  • CollectTransfertSpeed : this is the number of AZN units by turn your bot can transfer from an AZN point, and to a NanoNeedle.
  • Scan : this defines the distance your bot can see enemy bots.
  • MaxDamage : this defines the power of the attack of the bot (if the bot can attack).
  • DefenseDistance : this defines de distance your bot can attack (if the bot can attack).
  • Constitution : this defines how your bot will be difficult to kill.

Limitations when defining a new bot

You cannot put what you want for these caracteristics, there is limitations. Your dll has to respect the rules.

Open the PHServer.exe.config file with notepad, for each type of bot, there are 7 values. One value for each characteristic defines the maximum value you can set in that characteristic for that bot. The 7th value (Total) is the max number of points you can set for the sum of all the characteristics.

For exemple :

For a NanoCollector, you have :

    <!--NanoCollector-->
    <add key="NanoCollector_CC" value="20" />
    <add key="NanoCollector_CTS" value="5" />
    <add key="NanoCollector_Scan" value="5" />
    <add key="NanoCollector_MD" value="5" />
    <add key="NanoCollector_DD" value="12" />
    <add key="NanoCollector_C" value="50" />
    <add key="NanoCollector_Total" value="50" />

You can do :

[Characteristics(ContainerCapacity = 20,
    CollectTransfertSpeed = 5,
    Scan = 2,
    MaxDamage = 4,
    DefenseDistance = 10,
    Constitution = 7)]

But you cannot do

[Characteristics(ContainerCapacity = 22,
    CollectTransfertSpeed = 5,
    Scan = 5,
    MaxDamage = 4,
    DefenseDistance = 10,
    Constitution = 7)]

Because the max for ContainerCapacity is 20.

And you cannot do

[Characteristics(ContainerCapacity = 20,
    CollectTransfertSpeed = 5,
    Scan = 5,
    MaxDamage = 4,
    DefenseDistance = 10,
    Constitution = 7)]

Because 20 + 5 + 5 + 4 + 10 + 7 = 51, and the total allowed is 50.

Structuring your code

Making each bot doing something

A good structure to execute code for each of your bot is to make each NanoBot implement an IBot interface :

    public interface IBot
    {
        void Action(Player team);
    }

Then, in the WhatToDoNextEvent function, you have to do that :

    foreach (NanoBot bot in this.NanoBots)
    {
        IBot iBot = bot as IBot;
        if (iBot != null)
            iBot.Action(this);
    }

The Action function of every IBot in your team will be called.

Don’t forget to make your bots implement the IBot interface :

    [Characteristics(ContainerCapacity = 20,
        CollectTransfertSpeed = 5,
        Scan = 2,
        MaxDamage = 4,
        DefenseDistance = 12,
        Constitution = 7)]
    public class XCollector : NanoCollector, IBot
    {
        public void Action(Player team)
        {
            // Do something
        }
    }

The distance functions

Distances are very important in Project Hoshimi. You should have a method that gives you the distance between two points. There are several ways to do that. If from and to are the 2 points you want to calculate the distance between :

  • The Euclidian distance :

The Euclidian distance is the direct distance between 2 points. You can easily calculate it :

    Math.Sqrt((from.X - to.X) * (from.X - to.X) + (from.Y - to.Y) * (from.Y - to.Y));

  • The Manhattan distance :

This distance is the minimum distance between 2 points, if your bot can only move horizontally and vertically (this is the case in Project Hoshimi). You can calculate it :

    Math.Abs(from.X - to.X) + Math.Abs(from.Y - to.Y);

  • The Real distance :

Your bot will use pathfinding (either the build-in one, or yours) to move, so the real distance will depend on your pathfinder. Calculating this distance can help you to have accurate values to use, but it can be more more difficult (and longer) to compute.

You will have to choose what distance function to use, according to the situation.

Note : Some people find will tell you that you can’t do anything without pathfinder. Don’t listen to them. Of course, you get an advantage by having your own pathfinder. If you plan to spend much time with Project Hoshimi, you should develop your own pathfinder. But if you are not familiar with AI algorithms, you will spend much time on it, and your first versions will be slow. So if you are a novice, don’t worry, you can do well without pathfinder, there are other things much more important to implement in your program.

What to do with my NanoAI ?

Protect it !!

If you compare Project Hoshimi with chess, NanoAI is both the King and the Queen. If you loose your NanoAI, you are pretty sure that you have lost the game. The first thing to do is to protect it. There are several ways to do that, and I let you find some original tactic, but the simplest way is to build a defender bot (inherited from NanoCollector) that follow the AI and defends it when it sees a Pierre bot.

Use it efficiently

The NanoAI is also the only bot able to build bots. There are 2 types of bots : NanoMoveable, and not NanoMoveable (easy no ?). When building a bot, this difference is very important because when you build a non NanoMoveable, it is built at the location of the NanoAI. So you’ll have to move your NanoAI where you want to build the bot.

This is what happens when you make NanoNeedles, NanoBlockers and NanoWalls.

So the job of your NanoAI is quite simple : moving where you want to build a NanoNeedle, NanoBlocker or NanoWall, then build it, and repeat that.

When a non-NanoMoveable is built on a cell (but you, or you opponent), you cannot build any non NanoMoveable bot on this cell, and you cannot destroy it. So you’ll have to be the quicker to build NanoNeedles on HoshimiPoints.

Last words…

Here are some final advices for your strategy and your code :

  • Always try to imagine what will do your enemy.
  • Think about original strategies.
  • The best tactics are often the simpler.
  • Cluster your code into many classes. Don’t put all your code in the Player class. Last year, my project had 69 different classes.
  • Try to have a code very easy to maintain instead of a very optimized code.
  • Try to never hardcode any value. This is very useful to have a set of constants you can tune to balance your strategy (number of bots to build for example).
  • Avoid every exception. If your code raises an exception, the remaining code won’t be executed, and you will probably loose.
  • Don’t forget to comment your code.

Good luck to everyone, I hope you will enjoy Project Hoshimi as much as I did !!

Written by RaptorXP (Flavien Charlon) [Team Atomnium, World Champion 2006]

Part 1 | Part 2 | FAQ

Publié dimanche 1 octobre 2006 17:51 par RaptorXP
Ce post vous a plu ? Ajoutez le dans vos favoris pour ne pas perdre de temps à le retrouver le jour où vous en aurez besoin :

Commentaires

# Project Hoshimi, tutorial for beginners (Part 3 : FAQ)

Q &amp;amp; A for beginners
Q : At which frequency my WhatToDoNextEvent function is called ?A : You can...
dimanche 1 octobre 2006 18:59 by Code is poetry

# Project Hoshimi, tutorial for beginners (Part 1)

Abstract
I participated last year to Project Hoshimi 2006. I spent very much time to design my AI. I...
dimanche 1 octobre 2006 19:01 by Code is poetry

# Tutorial Project Hoshimi pour les d&amp;#233;butants

Richard avait demand&#233; aux finalistes de Project Hoshimi d'&#233;crire un petit article destin&#233; aux d&#233;butants...
dimanche 1 octobre 2006 19:22 by Code is poetry
Les commentaires anonymes sont désactivés

Les 10 derniers blogs postés

- [WPF] Comment charger dynamiquement un fichier XAML qui définit des eventhandler ? par Thomas Lebrun le il y a 20 heures et 45 minutes

- Article sur le filtrage des modèles de site SharePoint par The Grib's Lair [Sébastien PICAMELOT - MVP SharePoint] le 09-04-2008, 00:11

- Adopter votre Redo en 3D - Clone Virtuel - avec photosynth par RedoBlog - The .NET Gentleman !!! le 09-04-2008, 00:07

- [Expression Web] Astuce de la Semaine : Mettre en bouton ses macros dans une barre d'outils. par Expression Web & Me le 09-03-2008, 20:48

- [.Net] Présentation du Client Profile par Elise's blog le 09-03-2008, 12:28

- SharePoint : Test de Chrome avec SharePoint 2007 (MOSS et WSS) par Blog Technique de Romelard Fabrice le 09-03-2008, 11:38

- Google Chrome : Faille de Sécurité ?!? par The diary of EBArtSoft le 09-03-2008, 11:35

- ASP.net - tout savoir sur la validation des entrées utilisateurs | les controles de validation par Atteint de JavaScriptite Aiguë [Cyril Durand] le 09-02-2008, 23:43

- Google Chrome J'adopte ! par The diary of EBArtSoft le 09-02-2008, 21:36

- SharePoint : Eviter les Access Denied pour l’indexation de ferme SharePoint distante par Blog Technique de Romelard Fabrice le 09-02-2008, 20:50