

Play a Ruby + AI Coding Game in Your Browser via Bloc - choxi
http://www.trybloc.com/courses/ruby-warrior

======
jmduke
Really, really cool concept. I'm a sucker for in-browser coding, and wrapping
it in a little game with 'AI' is a great idea.

But as someone who knows other languages and doesn't know Ruby, it does a
pretty poor job of teaching the language. Take, for example, level 3, where
you need two if statements (check health, then check for an enemy): it took me
ten minutes to realize that ruby uses 'elsif' instead of 'else if' or 'elif'
because the error thrown by the in-browser compiler was vague at best ("Oops,
looks like we found a syntax error in your code. Try again and click "Grade
it!" does not exactly illuminate any issues.)

I echo other commenters re: animation but I think in terms of actual didactic
potential you need to add more actual coding documentation so newbies aren't
lost. Still, huge amount of potential and I'm excited to see this develop.

~~~
jolan
The syntax highlighting shows that 'else if'/'elif' aren't valid but it's
pretty subtle.

------
trun
The site is running kind of slow so I just did the first couple levels...

The directions (e.g. forward vs left) were a little confusing as you can't
tell which way the character is facing at first. Not a problem after level 1
though.

I second gerggerg's suggestion of step-by-step animation, along with
highlighting as it runs each line of code. That would really help drive home
the point for non-coders.

Are you capturing incorrect responses to see what common sticking points are?
For example, I thought .feel() returned a string at first before eventually
having to look at the tip.

Awesome idea though! I've been working on something very similar that I hope
to share soon.

~~~
choxi
got a huge traffic spike, increased our dynos so it should be a little
snappier now. glad you like it though!

------
llimllib
> Oops, looks like we found 0 errors in your code. Try again and click "Grade
> it!"

hmmm.

Also, when you have a syntax error, you need to copy it to a file on your
system and figure out where the error is because the game doesn't even tell
you what line it's on, let alone what the error said.

edit: Also, "a" is an archer, but it's not in the legend so you can't know
what it is until you die from it: <https://skitch.com/llimllib/gsi36/ruby-
warrior-beginner-bloc>

~~~
Groxx
I just got that, not quite sure what the cause of mine is. It happened
immediately after I recursed though, so I wonder if that has something to do
with it?

edit: apparently not, that's working now. Still not sure what caused it,
though.

edit2: you can get it by calling non-existent methods on RubyWarrior classes -
try .feel.archer? for example. I don't remember if this is what I did for my
exact error, but it's likely it was something similar.

------
gerggerg
Pretty cool, my issues:

    
    
      - The code box can't be resized.
      - You have to read the 'tip' every time. It contains core api and not just tips.
      - Some characters aren't in the map key (archer)
      - It's a little shy on instructions.
    
    

What would be awesome:

    
    
      - To see it run through your code in realtime with the healths and points displayed.
    

But honestly it's a really awesome concept and was fun to play even for
someone who already knows ruby.

~~~
choxi
thanks for the feedback! we're working on adding a reference section on our
site with the API.

the realtime thing would be awesome, hadn't thought of that.

~~~
cubicle67
Could you please differentiate between an error in the code and the player
dying?

I just spent ages trying to figure out what the error ("Oops, looks like we
found 1 error in your code") was and it wasn't until after some amount of
frustration that I realised there was more information below the fold showing
the problem was my player was dying and not my syntax

------
Groxx
FYI for confused:

    
    
      * you face 'forward', which is to the right.
        .walk! or .walk!(:forward) is what you want until later.
      * you can feel walls: .feel.wall?
      * you can print: p "Feels: #{warrior.feel}"
      * add this to the bottom of your file to get .archer? and .wizard? methods on look:
        class RubyWarrior::Space
          def archer?
            self.unit.kind_of? RubyWarrior::Units::Archer
          end
          def wizard?
            self.unit.kind_of? RubyWarrior::Units::Wizard
          end
        end
    

Thanks for the original monkeypatch go to numle at
<http://news.ycombinator.com/item?id=3435382>

It's beatable w/o hand-coding each action - I ended with a fairly-general
setup that only took a couple changed lines to solve the last task (a
should_shoot? method, basically). But the 'course' as a whole needs a LOT of
work. And better documentation. And fixes for the missing methods. And a
better progression - if you don't set up something fairly flexible early on,
you'll be re-writing a lot each time; the steps don't encourage you to
generalize very well. And / or hints as to how to design something good to do
this - there are absolutely no suggestions, no _learning_ , just 'tips' that
tell you half the API available to you.

If anyone wants a cheat-sheet for my setup for the end:
<https://gist.github.com/1574167> though it was tweaked at each level
slightly, and grew into that. Definitely not my best work, but it works.

------
algorithms
I think there is insufficient information on the pages on what to do, since
you require very specific commands and there are no hints whatsoever.

I love the idea though. If someone would be interested on working(for fun and
as a learning experience) on something like this with html5 canvas and some
graphics and all with a Ruby or Python back-end, tell me :D

------
tiptup
As someone with zero programming skills, I find the course pretty frustrating
for a complete beginner (not sure the segment you're targeting tbh).

I like the concept of in-browser coding as it removes the set-up barrier for
noobs like myself, who struggled with setting up Python on Windows!

It would be great if there are better instructions as to what one needs to do.
The tips aren't really tips when the info provided are essential to progress.
It's pretty daunting for a beginner to go through the github page when I only
need a couple of lines on the key need-to-knows for that particular level.

I echo gerggerg and trun's suggestion of step-by-step animation as the output
failures leaves me none the wiser as to what went wrong as it's gibberish to
me just now.

------
freehunter
Unfortunately, I have had some problems with Bloc's website every time I've
tried to use it. This example took 3 minutes to load the initial page. Earlier
today I was running through some Ruby code tutorials, and it got hung up on
evaluating the code. Their site runs pretty quick, until it doesn't.

I don't know if it's just under heavy load every time I try to use it
(admittedly only when it's on the front page of Hacker News, but it's
seemingly always on the front page) or if I'm doing something wrong. Love the
site, hate the performance.

~~~
choxi
sorry about that :(

it's definitely because of hacker news, I just increased our Heroku dynos by
_a lot_ though so it should be quicker

~~~
freehunter
Hey thanks for a response. I've been meaning to visit some time when it's not
on the front page, so I can give your poor servers a break while I learn.
Troubles of being a popular web app, I guess :)

------
numle
A monkey patch for the archer:

    
    
      class RubyWarrior::Space
        def archer?
          self.unit.kind_of? RubyWarrior::Units::Archer
        end
      end

~~~
Groxx
Similarly, include this in the patch for .wizard?:

    
    
      def wizard?
        self.unit.kind_of? RubyWarrior::Units::Wizard
      end

------
FuzzyDunlop
I think this'd be really helpful if it was documented better. As it is, it
assumes you already know what you're supposed to be doing. It tells you part
of what you need to do, but buries the rest in the github page.

Some better error reporting, even providing the interpreter in JS (as
suggested by another commenter), would allow people to run the app offline
without leaving their browsers. Having the ability to install the gem is
great, but I would say the browser opens it up to people who might not want to
- or can't - do that.

Finally, the layout of the page means you have to keep scrolling up and down
to refer to the level details and get back to the editor. There's a lot of
horizontal space wasted with the fixed-width layout, when it could be used to
present the level details and the editor side-by-side (thus allowing the
editor to assume the full height of the browser).

This could be a really good tutorial with a bit more polish :) if I understood
it all and knew Ruby well enough I'd gladly contribute.

------
zkarcher
My attempt at Level 1:

    
    
      class Player
        def play_turn(warrior)
          warrior.walk!(:right)
        end
      end
    

The warrior keeps bumping in to a wall, and the code fails.

This is counter-intuitive, because the exit is to the right of the warrior. I
can't endure another N levels of nonintuitive frustration, sorry.

~~~
lloeki
actually the warrior starts facing right (which is not specified but could be
supposed). so :right is actually moving down, since all movements are
relative, which is inferred by :forward and :backward being present and :up
:down missing, which I suppose would rather be :north :south :east and :west.
Once you also understand that tips really are not, but the necessary API doc,
well, it's smooth sailing.

------
mrinterweb
It kept saying I had syntax errors. I copied the code and checked it with
`ruby -c mycode.rb` and it passed. Not sure which version of ruby they are
using here. I was just trying to make the game fun with a little meta
programming, guess that is not allowed.

------
xal
Probably a good idea to speed up the ruby by compiling a ruby binary to
javascript (through emscripten) similarly to how <http://repl.it> did it. That
way you don't need a server.

------
kooshball
It would be nice to have some syntax hints. I dont know ruby so I dont know
what the syntax for an if/else statement would look like even if it's
obviously simple to someone that's seen it before.

~~~
cubicle67

        if warrior.feel.empty?
          warrior.walk! :forward
        else
          warrior.attack!
        end
    

Edit: if you're new to ruby syntax, then it's probably worth pointing out that
the ? and ! on the end of the method names has no special function (they're
both valid characters for using in method names). By convention, methods that
return a boolean end in ? and methods that modify the object end in !. For
example, Array has two sort methods - sort and sort!. some_array.sort will
return a sorted copy of some_array but leave the original unsorted.
some_array.sort!, however, will sort aome_array

------
trebor
Syntax errors could use a bit of help. I know Ruby and haven't made an obvious
error, so it'd be nice to see some kind of exception/description rather than
"try again".

------
JonLim
I love this idea and learning from it, but I thought I could move left and
right and instead I bump into walls.

Damn you archer!

~~~
JonLim
Actually level 5 is kinda wonky. The tips tell me to rescue captives, but
regardless of what I do, it just says this:

    
    
        > Oops, looks like there was a syntax error in your code. Try again and click "Grade it!"
    

Without anything for me to look at. Weird.

~~~
bct
I had the same problem, for some reason

    
    
        get '/:short_code' do
        end
    

got inserted at the end of the textarea.

------
sgrove
It says I can use warrior.health, but that doesn't seem to be true - I
constantly get

player.rb:5:in `play_turn': undefined method `health' for
#<RubyWarrior::Turn:...> (NoMethodError)

Not sure if it's supposed to be added in later levels or what, but it's a bit
frustrating. This looks really fun.

------
littleidea
I really like the high level concept, but I dislike the poke the mutable
state, disregard Demeter, nested if-else style of programming that the warrior
api encourages.

Don't take it too harshly, I definitely like what you are trying to do with
the service and I'm interested to see how your classes evolve.

~~~
choxi
completely agree, in the next iteration we'll allow you to create and edit
multiple files to try and encourage you to use better programming practices

------
akkartik
I did the available levels a few years ago, if anyone's curious:
<http://github.com/akkartik/brooks-ruby-warrior>

------
shubber
As a side note (for all of you who've typed :wq in the code entry field), you
can 'gem install rubywarrior' and play Ryan Bates's original locally. A little
snappier, too.

------
bryanh
Gonna have to echo that the code box needs to be much bigger or auto-adjusts.

