Bienvenue à Blogs CodeS-SourceS Identification | Inscription | Aide

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 went to the finals in India and I won the 1st place. Project Hoshimi is a very fun contest; if you like programming and video games (especially RTS), Project Hoshimi is for you. So, I’m sure you will enjoy participating.

I will give you some basic advices about Project Hoshimi in this paper. There are 2 important parts in Project Hoshimi : code design, and strategy. If you want to get far in the contest, of course, you have to write reliable and efficient code, but this can’t make you win. You also need to have a good strategy to win. The last element in Project Hoshimi is… luck. As in any game, there is always a luck factor in a Project Hoshimi game, but this is your job to minimize it.

To get familiar with Project Hoshimi, don’t hesitate to begin with the beginner mode. You will learn how it works; the program is very user friendly. Then, you will have to code your strategy to get more accuracy and to design a more advanced strategy. This is where my tutorial takes place.

How to begin ?

The WhatToDoNextEvent event

Take the tutorial, you will see that line :

    this.WhatToDoNextEvent += new WhatToDoNextEventHandler(MyAI_WhatToDoNextEvent);

it means that the function

    void MyAI_WhatToDoNextEvent()
    {
    }

will be called by the game at a certain frequency (each 800 milliseconds, see the FAQ). In this function, you will have to put every order you want to give to your bot. That’s all you have to do …

Build a bot

The most important bot in Project Hoshimi is the NanoAI. You can access to it like this :

    this.AI

Quite simple, isn’t it ?

You can give him different orders :

    Point destination = new Point(100, 100);
    this.AI.MoveTo(destination);

You said your AI to move to the point defined by X = 100, Y = 100.

If you want your AI to stop moving, you do :

    this.AI.StopMoving();

An important thing your AI can do is building other bots. You’ll have to define a new type of bot (see further). Then, you have to type :

    this.AI.Build(typeof(XCollector));

then, your AI will build a new XCollector (that you have defined), available the next turn.

Where are my bots ?

When you have build some bots, you may want to access them in you code, to give them orders. You can access them by the collection :

    this.NanoBots

You can use each bot in you team by doing that :

    foreach (NanoBot bot in this.NanoBots)
    {
    }

Giving orders to your bots

If you want to say to all of your XCollector to go to the point X = 150, Y = 50, you can do :

    Point destination = new Point(150, 50);
    foreach (NanoBot bot in this.NanoBots)
    {
        // If bot is a XCollector, collector is not null,
        // else, collector becomes null.
        XCollector collector = bot as XCollector;
        if (collector != null)
        {
            collector.MoveTo(destination);
        }
    }

The injection point

You have to provide an injection point in the ChooseInjectionPointEvent event. This is where your NanoAI get injected at the beginning of the game.

Each contestant has his own method to find the best injection point. This is a critical choice for your program, because your NanoAI can get injected too far from every HoshimiPoint and you won’t get enough points. In the other side, the NanoCollectors and NanoContainers are injected at the injection point when they are built, regardless to the position of you AI. So pay attention to the AZN points, or you will get difficulties to collect AZN if you IP is too far from them.

Remember that you must not provide an invalid IP (in the bones for exemple), because the SDK will give you automatically an IP near of Pierre.

Collecting AZN

One important thing in Project Hoshimi is the way you collect AZN. You can use 2 different bots to do that :

  • The NanoCollector : This bot can defend against Pierre, but it can only stock 20 AZN units.
  • The NanoContainer : This bot can stock 50 AZN units, but it cannot defend against Pierre.

You may have to do a choice between these 2 bots. Remember you can use both, maybe depending on the state of the game.

Interacting with the environment

Retrieving some information about the game

Is the last exemple, I said to every XCollector in my team to go to X = 150, Y = 50. But it is quite stupid. Why not telling them to go to a Hoshimi Point ?

You can retrieve informations about entities (HoshimiPoints and AZN) by using that collection :

    this.Tissue.Entities

also, if you want the location of the first HoshimiPoint, you can do :

    Point hoshimiLocation;
    foreach (Entity entity in this.Tissue.Entities)
    {
        if (entity.EntityType == EntityEnum.HoshimiPoint)
        {
            hoshimiLocation = new Point(entity.X, entity.Y);
            break;
        }
    }

You can also get information about your ennemy’s bot by using :

    this.OtherNanoBotsInfo

The entities

There are 2 kinds of entities : AZN and HoshimiPoint. These are 2 very important points.

  • HoshimiPoints : This is where your NanoAI can build NanoNeedles and score points.

    if (entity.EntityType == EntityEnum.HoshimiPoint)
    {
    }

  • AZN : This is where your NanoCollectors and NanoContainers can collect AZN.

    if (entity.EntityType == EntityEnum.AZN)
    {
    }

Objectives

Objectives are a way to receive points. Some objectives can be very important to achieve. You can look at the objective in your program by doing this :

    foreach (BaseObjective objective in Mission.Objectives)
    {
        if (objective is NavigationObjective)
        {
            // ...
        }
        if (objective is ScoreObjective)
        {
            // ...
        }
    }

When you accomplish an objective, you get bonus points. These bonus depend from the mission, you can get the bonus amount by :

    objective.Bonus

There are some different objectives :

  • NavigationObjective : You must send nanobots at given points of the map with a time constraint.
  • UniqueNavigationObjective : A unique nanobot must reach some given points with a time constraint.
  • ScoreObjective : You must have a minimum score before a given turn.
  • AIAliveObjective : Your NanoAI must be alive at a given turn.

Of course, new objectives can be added during the competition. Keep an eye on the Project Hoshimi forum.

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

Part 1 | Part 2 | FAQ

Publié dimanche 1 octobre 2006 15:15 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 2)


Defining your bots
How to define a bot ?
You have to define the behaviour of your bots. Each bot...
dimanche 1 octobre 2006 18:54 by Code is poetry

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

Q & 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

# Tutorial Project Hoshimi pour les débutants

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

Les 10 derniers blogs postés

- Entity Framework : providers Oracle, MySQL et PostgreSQL par Matthieu MEZIL le il y a 6 heures et 1 minutes

- [WPF] Nouvel article sur c2i.fr par Richard Clark le il y a 22 heures et 38 minutes

- F# nouvelle CTP 1.9.6.2 (update) par Pierrick's Blog le 09-06-2008, 13:27

- La suite ...Proposition de collaboration rédactionnelle entre les communautés de développeurs et Microsoft France par LucasR le 09-05-2008, 17:45

- [Fun] Votre simulateur de vol avec Microsoft ESP par Julien Chable le 09-05-2008, 12:02

- [Best Practices] Customisation du My Site : Comment le modifier en amont et en aval par The Mit's Blog le 09-05-2008, 10:47

- Patrick Tisseghem s'en est allé ... par The Mit's Blog le 09-05-2008, 10:04

- MS AutoCollage par alex# le 09-05-2008, 09:18

- Un grand SharePointeur nous a quitte : Patrick Tisseghem manquera à la communauté ! par RedoBlog - The .NET Gentleman !!! le 09-05-2008, 08:52

- [WPF] Comment charger dynamiquement un fichier XAML qui définit des eventhandler ? par Thomas Lebrun le 09-04-2008, 10:56