Montag, 17. Januar 2011

Installing Io on my Mac

Currently I'm reading Seven Languages in Seven Weeks by Bruce Tate. The frist new language to learn is Io, a prototype based language. So I installed it on my Mac running Snow Leopard.
These instructions are not by an expert, but just describes the way it worked for me. If you have any suggestions or improvements feel free to add a comment.

The easiest way to install Io is by using Homebrew.
brew install io
If you want the lastest version from github you can alternatively install Io by hand.

First we need CMake, a cross platform make tool. Download the OS X version and install it.

Update: If you want to use the Socket Addon, you must also install libevent.
sudo port install libevent
or use a the corresponding command if you want to install it with Homebrew.

Then we need the lastest version of Io from github. Unpack it and change to that directory, then issue the following commands:
mkdir build && cd build
cmake ..
sudo make install
This will install libraries to /usr/local/lib and add the commands to /usr/local/bin: io and io_static. Then we're ready to test Io's VM with:
io ../libs/iovm/tests/correctness/run.io
If you get an error like this:
dyld: Library not loaded: libbasekit.dylib
  Referenced from: /usr/local/bin/io
  Reason: image not found
Trace/BPT trap
Then we have to show the linker the way to the libraries:
DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/lib
export DYLD_LIBRARY_PATH
I added these two lines to my .profile.

After that you should be ready to get started.
io
Io 20090105
Io> "Hello Io" print
Hello Io==> Hello Io


Update: After playing around with Io, I wanted to try out the Socket Addon. But I got this error:
Io> Socket

  Exception: Object does not respond to 'Socket'
  ---------
  Object Socket                        Command Line 1
The missing libevent library was the cause for this error. Io doesn't complain about it, when compiling, but just skips the addon.

Donnerstag, 18. November 2010

Combat Damage in Season 2

The combat damage in ZeroX has been quite high. Until now the combat damage has been divided inversely proportional to the population size, both agents suffered the same combat damage.
With season 2 this will change in favor of the bigger adversary. The combat damage for the smaller will remain the same. But the damage for the bigger will also be inversely proportional to the population sizes. Let's compare the two algorithms with a seek and destroy sequence with:

  Season 1 Season 2
step   Agent 1 Agent 2 Agent 1 Agent 2
1 population 1000 1500 1000 1500
combat damage 600 600 600 400
2 population 400 900 400 1100
combat damage 276 276 293 107
3 population 124 624 106 993
combat damage 103 103 96 11
4 population 21 521 10 982
combat damage 20 20 10 1
5 population 1 501 0 981

As in season 1 both adversary were classified excat the same, therefore they suffered the same damage. The bigger one could never take advantage of his population superiority. This will now be considered.

Mittwoch, 10. November 2010

Secure your steps, how to disengage from a move action

Update: This feature has been removed in with the beginning of the 3rd season. Instead use look_at for agents in level Clone War.

In Zero X the simulation and all agents are running continuously. That's one big difference to other programming games, that usually are round based. The consequence is, that in the time between an agent inspects his environment with a look_around and the action he takes, with a move_to for example, the environment can change.
For example a field is free, when he makes the look_around, but has been occupied in the meanwhile by another agent, when he moves. This would result in a unintended attack against this other agent.

Although this case is rare, as a look_around and a move_to are very close. But this time gape can grow bigger as the analysis of the environment takes more time. In general agents have to deal with this kind of insecurity about their perception. This one of the many challenges in this game.

But in order to handle better this kind of insecurity, starting with season 2, move_to can now take a block.
move_to(x,y) {|target| ... }
The argument passed to the block is another view of the target field at the exact time of the movement. This gives the agent the chance to check the preconditions of his action. If they are not fulfilled anymore, he can now disengage from the move action.

move_to(x,y) do |target|
  unless target.has_no_population?
     disengage 'field is not free anymore!'
  end
end
Disengage can take a message, that will then be displayed in your reports. The action is canceled and the agent remains on his starting field. But disengage comes not for free. A move_to would cost 6 action points, disengage from this action still costs 3 action points.

Disengage can only be used within an action block like the one in move_to.

Donnerstag, 26. August 2010

The End of Season 1

The 10th tournament ended actually with two winners, Bulldog and Rincewind. Both made 6.8 points, Bulldog is only ranked first, because he has a better overall ranking.

After 10 tournaments, it's time to look back. The first tournament began with 9 agents, by now the agents have doubled. They not only have become more, no they also have become better. FireLion the winner of the first two tournaments, looked in the beginning very promising, but in the meanwhile has been displaced to the 10th rank. Others have come with a better strategy.

After total 46 games, the ranking list can grouped in three parts:
There's the 5plus group, agents that have an average of more than 5 points. Means they don't only survive in most of the games, the also achieve better ranks. WoodElf, Bulldog, Gruyere, Oreiller, Mild Gruyere and Rincewind are in this group.
The second group are agents that survive sometimes, they have an average of 3 to 4 points. And then there's the last group that have less than 3 points, meaning they don't survive very often.

But remember this tournaments are not only about winning or loosing, in fact I don't see any loosing in contributing an agent. It's about to figure out which strategy works better then another.

After 10 tournaments we make a break and end the first season. We will continue the tournaments in October, the exact date will be announced.

Congratulations to everybody and see you soon for the second season!

Samstag, 31. Juli 2010

Attacked Events

In Zero X some events are directly reported to the agents. They can read them, during their think method with next_event or iterate over them with each_event. The event will be removed as soon as it has been read.
event = next_event
event.class    # => AttackedEvent
event.attacker # => '003' agent code name
event.damage   # => 132
If an agent is attacked by another agent, the victim receives an attacked event. The event includes the code name of the attacker and the damage suffered.

Here an example with an iterator:
each_event do |event|
  if event.instance_of? AttackedEvent
    puts "attacked by #{event.attacker} and suffered #{event.damage}"
  end
end
In your tests you can fire the attacked event by using has_been_attacked_by. The method takes the codename of the attacker and an optional damage parameter.
it "should behave different if it has been attacked" do
  @agent.has_been_attacked_by '003'
  @agent.think
  ...
end
The new test methods are available with SDK Version 0.9.7.
Download the new SDK V0.9.7

See the documentation.

Donnerstag, 22. Juli 2010

Bulldog wins 9th tournament

Bulldog won the 9th tournament with 8.0 points. He won 2 games, made one second place and a third place.
Wood Elf, the high flyer of the last tournament, made this time only 4.6 points and was placed at rank 6, still holding the first rank in the total ranking.
Newcomer Mild Gruyere won 1 game and is placed 4th in the tournament ranking.

I'm still experimenting with the runtime velocity of the simulation. This time the simulation run even slower, the action cost to time unit ratio was 1/15. Like this the resource reached their maximum at the end of each game. I think will keep the action costs in this range for the next tournament.
class Agency < Tournament::Agency
  level 'Greenfields'
  agents_per_game 22
  games_per_agent 1
  game_duration 300 # sec
  time_unit 45 # sec
  action_cost_time_unit_ratio 1.0 / 15.0
  build_options 'Greenfields::World' => { :size => 8 },
                'Greenfields::Resource' => { :size => 4000..16000 },
                'Greenfields::Population' => { :size => 40..160 }
end
Ranking of the 9th tournament.

Montag, 5. Juli 2010

High-Flyer

Incredible! Wood Elf makes the perfect tournament with 10 points! This means she won all 5 games in the tournament. Having a look at the rankings of Wood Elf, we see that, in the 4 tournaments she participated, she won 3 of them and made a second place in the other. This is clear an outstanding performance.
She now leads the overall ranking with 7.85 points, leaving the second placed Gruyere with 5.69 points behind.

The world size for this tournament has now been increased by one to eight. And the simulation run even slower, one time unit now took 30 seconds.
Here the whole configuration for the last tournament:
module Greenfields

  class Agency < Tournament::Agency
    level 'Greenfields'
    agents_per_game 22
    games_per_agent 5
    game_duration 1800 # sec
    time_unit 30 # sec
    action_cost_time_unit_ratio 1.0 / 10.0
    build_options 'Greenfields::World' => { :size => 8 },
                  'Greenfields::Resource' => { :size => 4000..16000 },
                  'Greenfields::Population' => { :size => 40..160 }
  end

end

Ranking of the 8th tournament.