Level Clone War

Introduction

Clone_war

Level Clone War is based on the previous level Greenfields. Mainly all actions you know from there have been extended. But we also have a new one: Now it is possible to split a population and this changes a lot.

Agent and Population Actions

After splitting a population you end up with another population. If you then want to make a look around or a move, you will have to specifiy which of the two populations should do it.
On the otherhand actions like info or time are independent from any population and can therefore be invoked by the agent directly.

  population_a.look_around
  population_b.move_to 1, 1
  population_c.size
  population_c.resource
  info 'some message'
  time
  next_event
  each_event

Above all the action you know from Greenfields grouped by population and agent actions.

Action Points

In general population actions will cost actions points, while agent actions are for free.
Action costs have to be paid by the agent not the population. This means, that after an agent moves a population, he has to pay the action costs first before he can continue with another action. Even if this second action concerns another population.

Game Over

The agent loses the game, when he lost all his populations.

Split

Already announced, here now the details. A population can split into two equal sized populations, the so created population is then moved to a field of your choice. To specifiy to which field the new population should be moved, you can pass the same paramters to split as you know it from move.

  new_population = old_population.split field
  new_population = old_population.split x: 1, y: 1
  new_population = old_population.split 1, 0
  new_population = old_population.split nil    # => will do nothing
  new_population = old_population.split 0, 0   # => will do nothing

After a successful split of a population with a initial size of 500, both the origin and the new created population will have a size of 250.
If you try to move the new created population to a field, that is occupied by another agent, then the whole action will be canceled. You will receive a disengage message in your report to comprehend what happened respectively did not happen.

Note: The former disengage block for the action move will be removed from both levels Greenfields and Clone War. A deprecation warning will be added to your reports.

A split action costs the same as a movement action, the new movement costs by the way, but more on this later. If in contrast the split action has been canceled only half of the costs have to be paid. All your populations will be managed for you, more on this later.

Merge

If you move a population to a field with another population belonging to you, then both populations will be merged.

Sensor

-1, 20, 21, 2
-2, 1-1, 10, 11, 12, 1
-2, 0-1, 00, 01, 02, 0
-2, -1-1, -10, -11, -12, -1
-1, -20, -21, -2
The sensor action look_around has been extended. You can now look further by passing the radius as parameter. Default radius is 1 and behaves just like you know it from level Greenfields. For level Clone War a maximum of 2 is available and gives you back the shown view on the left. As you can see it's a "circular" view, the edges are missing. For those edges you wont get back a field but nil.

In addition to look_around also look_at is now available. With this action you can take a look at a specific field within radius 1 for very low costs.



Of course the different views have different costs:

look_around with radius 2: 5 action points
look_around with radius 1: 2 action points
look_around with radius 0: 0.2 action points
look_at: 0.2 action points

        population.look_around(0) # equal to look_at(0,0)
        population.look_around    # radius 1
        population.look_around(2) # radius 2

        population.look_at(1,0)
        population.look_at(field) # ???

        view = population.look_around(2)
        view[2,1] # => field
        view[2,2] # => nil
      

Movement

There's also some changes to the action move_to. Horizontal and vertical movements cost the same as in the previous level Greenfields, but moving diagonally now costs 8.5 action points.

Horizontal and vertical movement: 6 action points
Diagonal movement: 8.5 action points

Populations

In order to handle all your populations there are a few agent actions. The method populations just returns the array containing all your populations.
      def think
        populations.each do |population|
          field = population.look_around.first
          population.move_to field
        end
      end
    
The populations array is managed for you. If you split, the new created population will be added automatically to the populations array and it will remove populations from the array if they die.

Before we continue with other methods, let's have a closer look at the code above. As you may remember Zero X is simulated continously. Meaning that the population object you get from populations method, may have died in the meantime and when you want to execute the look_around or move_to, there's no population anymore. In this case a Tournament::PuppetDeath exception will be raised, that you need to rescue.
      def think
        populations.each do |population|
          begin
            field = population.look_around.first
            population.move_to field
          rescue Tournament::PuppetDeath
            # ignore
          end
        end
      end
    
Another way to get a population is the method next_population, which uses an Enumerator and returns one population after another. But when you use next_population with a block, it will also catch the Tournament::PuppetDeath for you, abort the current block and move to the next population.
      def think
        loop do
          next_population do |population|
            # population does something here
            # no rescue Tournament::PuppetDeath necessary
          end
        end
      end
    
each_population also does the loop for you
      def think
        each_population do |population|
          # population does something here
          # no rescue Tournament::PuppetDeath necessary
        end
      end
    

Events

In addition to the three events attacked, death and killed from level Greenfields, there are two new events concerning an agents population.

Captured Population

If an agent kills a population of another agent, he will receive a caputered population event. The event includes the code name of the victim and the name of the population killed.

Lost Population

If one of your populations has been killed during combat, you will receive a lost population event. The event includes the code name of the attacker and the name of the attacked population.

Killed and Death

The killed and death events will only be sent if the last population of an agent has been killed.

Download the demo agents:
Zip

Example

Here's an example of a simple agent. Each of his population will either move or split to a random free field.

	      module Demo

          class Example < Tournament::Agent

            def after_start
              @random = Random.new
            end

            # moves or splits a random free field
            def think
              each_population do |population|
                free_field = population.look_around.select {|f| f.has_no_population?}.shuffle.first
                if @random.rand(0..1) == 0
                  population.move_to free_field
                else
                  population.split free_field
                end
              end
            end

          end

        end
	    

Agent Class

Level_select As soon as you have reached "Clone War" you can begin to create agents. When uploading a new agent you can now choose the new level as shown on the left. Don't try to modify an old agent and try to update it, create a new one.

Points

In level Clone War the points are distributed more subtler. First you get 1 point for each 1/5 time survived in a game and 10 points if your agent survives the game.
For example in a game, that lasted 60 time units, agent 001, who died just after 5 time units, will receive 0 points, agent 002, who died after 45 time units, will receive 3 points and agent 003, who survived the whole game will receive 10 points.

Second from the agents, that survived, the ones with the 5 biggest populations, meaning the sum of all their populations, will receive bonus points. The one with the biggest population gets 10 extra points, the next best 8 points, the third-best 6 points, the fourth-best 4 points and the fifth-best 2 points.

Again in short: the longer an agent survives the more points he gets, if he survives the game he gets 10 points. The 5 agents with the biggest population get bonus points, the best of them gets the maximum of 20 points for a game.

Next Level

Yes, there are plans for another level. If you have suggestions or ideas, please feel free to drop a message to .