RubyWarrior - Bloc
31–40 of 70 posts
Re: RubyWarrior - Bloc
#32- 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 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
#34This 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…
Re: RubyWarrior - Bloc
#35This 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
#36Nicely 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…
> 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
#37Nicely 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…
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
#38Re: RubyWarrior - Bloc
#39Nicely 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…
:)
Re: RubyWarrior - Bloc
#40This 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…