Live data from Hacker News

RubyWarrior - Bloc

bloc.io

31–40 of 70 posts

Re: RubyWarrior - Bloc

#32
Nicely made. Some frustrations:

- while, until, retry (and others?) not allowed.

- not being able to see the class of something. Its more ruby style to do 'space.is_a?(Enemy)' than 'space.enemy?'. This would also help to build case statements rather than lots of ifs.

- no 'print' or 'puts'. How am I supposed to know what 'look' returns when it never really tells me?

- I prefer a single set of rules rather than adding rules as you go. When first I have to use :backward but later this becomes basically redundant as 'pivot' is added, it just makes me frustrated in having to refactor. Same thing for feel/look.

Re: RubyWarrior - Bloc

#33
This should win every level (given enough tries):

  def play_turn(warrior)
    m = warrior.methods.grep(/.!$/).sample
    warrior.send(m, *([nil, :backward].sample if m != :rest!))
  end
(that sucker of :rest! that doesn't accept a direction argument!)

It's kind of amusing to see the warrior do random stuff like shooting arrows backwards and pivoting back in the worst possible moments. Too bad that Run button repeats the same movements if you didn't edit the source code somehow.

Great game and concept BTW!

Re: RubyWarrior - Bloc

#34

This should win every level (given enough tries): def play_turn(warrior) m = warrior.methods.grep(/.!$/).sample warrior.send(m, *([nil, :backward].sample if m != :rest!)) end (that sucker of :rest! that doesn't accept a direction argument!) It's kind of amusing to see the warrior do random stuff like shooting arrows backwards and pivoting back in the worst possible moments. Too bad that Run button repeats the same mo…

The sandbox probably always initializes with the same random seed.

Re: RubyWarrior - Bloc

#35
post #34

This should win every level (given enough tries): def play_turn(warrior) m = warrior.methods.grep(/.!$/).sample warrior.send(m, *([nil, :backward].sample if m != :rest!)) end (that sucker of :rest! that doesn't accept a direction argument!) It's kind of amusing to see the warrior do random stuff like shooting arrows backwards and pivoting back in the worst possible moments. Too bad that Run button repeats the same mo…

The sandbox probably always initializes with the same random seed.

No, it seems to be a client-side thing. If no edit was made in the code editor since last run it doesn't make the request to https://www.bloc.io/api/v1/ruby_warrior_players/:id (which seems to be the one that returns the warrior and enemy movements). Repeating the same request in cURL multiple times does return different results.

Re: RubyWarrior - Bloc

#36

Nicely made. Some frustrations: - while, until, retry (and others?) not allowed. - not being able to see the class of something. Its more ruby style to do 'space.is_a?(Enemy)' than 'space.enemy?'. This would also help to build case statements rather than lots of ifs. - no 'print' or 'puts'. How am I supposed to know what 'look' returns when it never really tells me? - I prefer a single set of rules rather than adding…

Hehe, i feel identified with some of these frustrations, but i think it's better the way it is.

> Its more ruby style to do 'space.is_a?(Enemy)' than 'space.enemy?'. This would also help to build case statements rather than lots of ifs.

But that would require to explain that an Enemy class/module (and possibly others) exists. With the presented interface you can/should only care about Warrior and Place. Much simpler.

> no 'print' or 'puts'. How am I supposed to know what 'look' returns when it never really tells me?

With Ruby's Array methods. Warrior#look returns an Array of at most 3 Places. What else should you know?

> I prefer a single set of rules rather than adding rules as you go. When first I have to use :backward but later this becomes basically redundant as 'pivot' is added, it just makes me frustrated in having to refactor. Same thing for feel/look.

That happened to me too, but i think it adds to the sense of progress and discovery throughout the game. Like most games, you don't start with all the tools and abilities at your disposal. And you can always ask respond_to? if you want an algorithm that works for all level ;)

Re: RubyWarrior - Bloc

#37

Nicely made. Some frustrations: - while, until, retry (and others?) not allowed. - not being able to see the class of something. Its more ruby style to do 'space.is_a?(Enemy)' than 'space.enemy?'. This would also help to build case statements rather than lots of ifs. - no 'print' or 'puts'. How am I supposed to know what 'look' returns when it never really tells me? - I prefer a single set of rules rather than adding…

No loops because (as it's a game AI) it's meant to be called once per game tick, rather than as a driver. I didn't try continuations but it's possible you could get something like that to work.

As a Rubyist for a decade now, please avoid is_a? if at all possible. It defeats the awesome flexibility that is duck typing. Also, I have no idea why you feel that would be better for cases, my code ran in a case statement for brevity.

'look' told me that it returns an array of Spaces. They're the same type as the Space feel returns.

Agreed on pivot though.

Re: RubyWarrior - Bloc

#39

Nicely made. Some frustrations: - while, until, retry (and others?) not allowed. - not being able to see the class of something. Its more ruby style to do 'space.is_a?(Enemy)' than 'space.enemy?'. This would also help to build case statements rather than lots of ifs. - no 'print' or 'puts'. How am I supposed to know what 'look' returns when it never really tells me? - I prefer a single set of rules rather than adding…

The changing requirements and arbitrary restrictions added realism for me.

:)

Re: RubyWarrior - Bloc

#40

This should win every level (given enough tries): def play_turn(warrior) m = warrior.methods.grep(/.!$/).sample warrior.send(m, *([nil, :backward].sample if m != :rest!)) end (that sucker of :rest! that doesn't accept a direction argument!) It's kind of amusing to see the warrior do random stuff like shooting arrows backwards and pivoting back in the worst possible moments. Too bad that Run button repeats the same mo…

Haha, I didn't play long enough to realize all the methods ended with a bang, this is awesome.
Post reply on HN