a ruby programming game
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.
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.
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.
-1, 2 | 0, 2 | 1, 2 | ||
-2, 1 | -1, 1 | 0, 1 | 1, 1 | 2, 1 |
-2, 0 | -1, 0 | 0, 0 | 1, 0 | 2, 0 |
-2, -1 | -1, -1 | 0, -1 | 1, -1 | 2, -1 |
-1, -2 | 0, -2 | 1, -2 |
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
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
def think populations.each do |population| field = population.look_around.first population.move_to field end endThe 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.
def think populations.each do |population| begin field = population.look_around.first population.move_to field rescue Tournament::PuppetDeath # ignore end end endAnother 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 endeach_population also does the loop for you
def think each_population do |population| # population does something here # no rescue Tournament::PuppetDeath necessary end end
In addition to the three events attacked, death and killed from level Greenfields, there are two new events concerning an agents population.
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
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.
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.