MailRuChamps / raic-2018

Russian AI Cup — artificial intelligence programming contest. Official website: http://russianaicup.ru
43 stars 32 forks source link

Rust repeater with local runner integration #124

Open elsid opened 5 years ago

elsid commented 5 years ago

Introduced as replacement for Repeater (https://russianaicup.ru/p/repeater) to use for Rust-only strategies (same approach could be use for any other language). The idea is to read stdin with game log and communicate with local runner in the same time. Local runner data is ignored. Instead stdin is used to read and parse game state. Strategy output action is ignored. Default action is sent to local runner. So local runner will not show any activity, but one could use custom rendering to visualize in schematic view any data.

Usage example:

  1. Download game log from https://russianaicup.ru/game/view/<...>
  2. Run local runner and repeater:
    local_runner/codeball2018 --p2 empty &
    target/release/repeater elsid < game.log
elsid commented 5 years ago

Fixed conversion to opposite coordinates. x should be same.

How to check.

  1. Make strategy with code (prints all robots coordinates to stdout):
    impl Strategy for MyStrategyImpl {
    fn act(&mut self, me: &Robot, rules: &Rules, game: &Game, action: &mut Action) {
        println!("{} {:?}", me.id, game.robots.iter().map(|v| (v.id, v.x)).collect::<Vec<_>>());
        action.target_velocity_x = 30.0;
    }
    }
  2. Run for both sides:
    local_runner/codeball2018 \
    --noshow \
    --team-size 1 \
    --log-file ${PWD}/game.json \
    --p1-name a \
    --p2-name b \
    --p1 tcp-31001 \
    --p2 tcp-31002 &
    sleep 1
    target/release/my-strategy 127.0.0.1 31001 0000000000000000 > a1.log &
    sleep 1
    target/release/my-strategy 127.0.0.1 31002 0000000000000000 > b1.log
    wait
  3. Run repeat:
    local_runner/codeball2018 \
    --noshow \
    --team-size 1 \
    --p1-name a \
    --p2-name b \
    --p1 tcp-31001 \
    --p2 tcp-31002 &
    sleep 1
    target/release/repeater a 127.0.0.1 31001 0000000000000000 < ${PWD}/game.json > a2.log &
    sleep 1
    target/release/repeater b 127.0.0.1 31002 0000000000000000 < ${PWD}/game.json > b2.log
    wait
  4. Strategies outputs should be same for original run and repeat:
    diff a1.log a2.log
    diff b1.log b2.log

It differs without 424b1d16bcdc650a287a664000746b363a2efdc1.