Ruby-warrior : Teaching AI concepts with Ruby

I think this project doesn't get enough attention :slight_smile:

I've tried it and it's really cool and entertaining. The code is also
pretty cool to look at, and it's got tests and everything.
What is your opinion of it? How far can you go before you have to
actually think? :slight_smile:

路路路

--
Posted via http://www.ruby-forum.com/.

Aldric Giacomoni wrote:

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

What a cool idea!

Looks fun! Bookmarked.

Regards,

Bill

That looks really really cool. I'll have to play with that this weekend. Thanks!

路路路

On Apr 9, 2010, at 10:20 , Aldric Giacomoni wrote:

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

I've tried it and it's really cool and entertaining. The code is also
pretty cool to look at, and it's got tests and everything.
What is your opinion of it? How far can you go before you have to
actually think? :slight_smile:

AMAZING idea :slight_smile:

路路路

On Apr 9, 2:20 pm, Aldric Giacomoni <ald...@trevoke.net> wrote:

I think this project doesn't get enough attention :slight_smile:GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

I've tried it and it's really cool and entertaining. The code is also
pretty cool to look at, and it's got tests and everything.
What is your opinion of it? How far can you go before you have to
actually think? :slight_smile:
--
Posted viahttp://www.ruby-forum.com/.

Hahaha, I've been studying alot lately and once I finish my tests I'm
definately trying it out, *I've* been with some idea to create a game where
you program stuff in order to do something but in a way that goes
mainstream(and maybe be a good way to learn how to program).

路路路

2010/4/9 Aldric Giacomoni <aldric@trevoke.net>

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

I've tried it and it's really cool and entertaining. The code is also
pretty cool to look at, and it's got tests and everything.
What is your opinion of it? How far can you go before you have to
actually think? :slight_smile:
--
Posted via http://www.ruby-forum.com/\.

--
Thiago Fernandes Massa
11 83979414

Bill Kelly wrote:
Aldric Giacomoni wrote:

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

Oh, definately, this is probably the best way to teach programing.

路路路

--
Posted via http://www.ruby-forum.com/\.

Hello guys! I consider RubyWarrior may be useful for learning. A have
reached for 6'th level (as beginner).

Now my code looks as following: http://good.net/_5pJ5Rurvz .
I can't understand issue: if i call in method:
聽聽聽聽def roam_to_combat!
聽聽聽聽聽聽debug("Entering roam_to_combat")
聽聽聽聽聽聽state = :ws_combat
聽聽聽聽聽聽@ini_health = health
聽聽聽聽聽聽debug(@ini_health)
聽聽聽聽聽聽warrior.attack!(cur_dir)
聽聽聽聽end

then it lacks to execute string "state = :ws_combat".
But if i call
聽聽聽聽def roam_to_combat!
聽聽聽聽聽聽debug("Entering roam_to_combat")
聽聽聽聽聽聽self.state = :ws_combat # <-- here is difference
聽聽聽聽聽聽@ini_health = health
聽聽聽聽聽聽debug(@ini_health)
聽聽聽聽聽聽warrior.attack!(cur_dir)
聽聽聽聽end
then it executes "state = :ws_combat" normally.

Why it didn't execute "state =" without "self"?
Is it Ruby's bug?
I got Ruby 1.8 installed.

Just began and already addicted :smiley:

my lazy fingers found instance_exec very useful :wink:

People,

Bill Kelly wrote:
  Aldric Giacomoni wrote:

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

Oh, definately, this is probably the best way to teach programing.

I tried cloning the latest git but adding

  warrior.rest!

to player.rb and running gave:

Welcome to Ruby Warrior
[1] p - beginner - level 1 - score 0
[2] New Profile
Choose profile by typing the number: 1
Starting Level 1
- turn 1 -

路路路

On 2010-04-10 05:35, H- 16 wrote:
  --------

@ >|

  --------
./rubywarrior/p-beginner/player.rb:3:in `play_turn': undefined method `rest!' for #<RubyWarrior::Turn:0x7f5f0ced1a58 @action=nil, @senses={}> (NoMethodError)
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/units/warrior.rb:12:in `play_turn'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/units/base.rb:72:in `prepare_turn'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:50:in `play'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:50:in `each'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:50:in `play'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:46:in `times'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:46:in `play'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/game.rb:72:in `play_current_level'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/game.rb:63:in `play_normal_mode'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/game.rb:23:in `start'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/runner.rb:17:in `run'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/rubywarrior:5

What have I missed?

Thanks,

Phil.
--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: phil@pricom.com.au

state = :ws_combat

is an assignment to a local variable. You are not using the variable
in the method, so i assume this is not what you want. When you do

self.state = :ws_combat

you are calling the method state= on the object, which I suppose you
have (maybe created by attr_accessor).

The fact that you have to call it this way is to disambiguate between
a local variable assignment and a method call with implicit receiver.
This is a consequence of the syntactic sugar that allows you have
methods name xxx= that look like assignments.

Jesus.

路路路

On Thu, Apr 15, 2010 at 10:00 PM, akraynov <akraynov@bk.ru> wrote:

Hello guys! I consider RubyWarrior may be useful for learning. A have
reached for 6'th level (as beginner).

Now my code looks as following: http://good.net/_5pJ5Rurvz .
I can't understand issue: if i call in method:
def roam_to_combat!
debug("Entering roam_to_combat")
state = :ws_combat
@ini_health = health
debug(@ini_health)
warrior.attack!(cur_dir)
end

then it lacks to execute string "state = :ws_combat".
But if i call
def roam_to_combat!
debug("Entering roam_to_combat")
self.state = :ws_combat # <-- here is difference
@ini_health = health
debug(@ini_health)
warrior.attack!(cur_dir)
end
then it executes "state = :ws_combat" normally.

Why it didn't execute "state =" without "self"?
Is it Ruby's bug?
I got Ruby 1.8 installed.

Ok :wink: then :wink: ;), why are the Shopping Baskets still So Dumb :wink: ??

:wink:

thunk

People,

Bill Kelly wrote:
Aldric Giacomoni wrote:

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

Oh, definately, this is probably the best way to teach programing.

I tried cloning the latest git but adding

  warrior.rest!

to player.rb and running gave:

...

./rubywarrior/p-beginner/player.rb:3:in `play_turn': undefined method `rest!' for #<RubyWarrior::Turn:0x7f5f0ced1a58 @action=nil, @senses={}> (NoMethodError)
       from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/units/warrior.rb:12:in `play_turn'
...
What have I missed?

I dunno as I haven't played with the code yet, but you're calling rest! on a Turn, not on the Warrior. Make sure your warrior variable (or method call result?) is what you think it is.

Make sure you still have something like:

  class Player
    def play_turn(warrior)

路路路

On Apr 9, 2010, at 23:38 , Philip Rhoades wrote:

On 2010-04-10 05:35, H- 16 wrote:

Hi,

路路路

On 10 April 2010 08:38, Philip Rhoades <phil@pricom.com.au> wrote:

People,

I tried cloning the latest git but adding

       warrior.rest!

to player.rb and running gave:

Welcome to Ruby Warrior
[1] p - beginner - level 1 - score 0
[2] New Profile
Choose profile by typing the number: 1
Starting Level 1
- turn 1 -
--------
>@ >|
--------
./rubywarrior/p-beginner/player.rb:3:in `play_turn': undefined method
`rest!' for #<RubyWarrior::Turn:0x7f5f0ced1a58 @action=nil, @senses={}>
(NoMethodError)

What have I missed?

You just can't warrior.rest! on level 1, warrior methods are added level by

level.

And, why would you rest when you can just go straight ahead? :wink:

B.D.

Yes, "state" is assignment method. It behaves unsimiliar as other
languages:
"xxx=" can be declared in Object Pascal too, for example.
It seems local variable "state" has overriden my method "state".
This can be a source of many hidden bugs for those who well-skilled in
Delphi or C++.
Why Ruby doesn't give me any warning?

路路路

On 16 邪锌褉, 03:25, Jes煤s Gabriel y Gal谩n <jgabrielyga...@gmail.com> wrote:

On Thu, Apr 15, 2010 at 10:00 PM, akraynov <akray...@bk.ru> wrote:
> Hello guys! I consider RubyWarrior may be useful for learning. A have
> reached for 6'th level (as beginner).

> Now my code looks as following:http://good.net/_5pJ5Rurvz\.
> I can't understand issue: if i call in method:
> def roam_to_combat!
> debug("Entering roam_to_combat")
> state = :ws_combat
> @ini_health = health
> debug(@ini_health)
> warrior.attack!(cur_dir)
> end

> then it lacks to execute string "state = :ws_combat".
> But if i call
> def roam_to_combat!
> debug("Entering roam_to_combat")
> self.state = :ws_combat # <-- here is difference
> @ini_health = health
> debug(@ini_health)
> warrior.attack!(cur_dir)
> end
> then it executes "state = :ws_combat" normally.

> Why it didn't execute "state =" without "self"?
> Is it Ruby's bug?
> I got Ruby 1.8 installed.

state = :ws_combat

is an assignment to a local variable. You are not using the variable
in the method, so i assume this is not what you want. When you do

self.state = :ws_combat

you are calling the method state= on the object, which I suppose you
have (maybe created by attr_accessor).

The fact that you have to call it this way is to disambiguate between
a local variable assignment and a method call with implicit receiver.
This is a consequence of the syntactic sugar that allows you have
methods name xxx= that look like assignments.

Jesus.

You are OFF-TOPIC. I can't say this more plainly: FUCK OFF.

路路路

On Apr 9, 2010, at 13:40 , thunk wrote:

Ok :wink: then :wink: ;), why are the Shopping Baskets still So Dumb :wink: ??

:wink:

thunk

Guys,

People,

Bill Kelly wrote: Aldric Giacomoni wrote:

I think this project doesn't get enough attention :slight_smile:
GitHub - ryanb/ruby-warrior: Game written in Ruby for learning Ruby and artificial intelligence.

Oh, definately, this is probably the best way to teach
programing.

I tried cloning the latest git but adding

warrior.rest!

to player.rb and running gave:

...

./rubywarrior/p-beginner/player.rb:3:in `play_turn': undefined
method `rest!' for #<RubyWarrior::Turn:0x7f5f0ced1a58 @action=nil,
@senses={}> (NoMethodError) from
/usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/units/warrior.rb:12:in
`play_turn'

>>

... What have I missed?

I dunno as I haven't played with the code yet, but you're calling
rest! on a Turn, not on the Warrior. Make sure your warrior variable
(or method call result?) is what you think it is.

Make sure you still have something like:

class Player def play_turn(warrior)

I just used something simple above because the example stuff gave me the same problem - that is, using:

class Player
   def play_turn(warrior)
     if warrior.feel.enemy?
       warrior.attack!
     else
       warrior.walk!
     end
   end
end

results in:

Welcome to Ruby Warrior
[1] p - beginner - level 1 - score 0
[2] New Profile
Choose profile by typing the number: 1
Starting Level 1
- turn 1 -

路路路

On 2010-04-10 18:11, Ryan Davis wrote:

On Apr 9, 2010, at 23:38 , Philip Rhoades wrote:

On 2010-04-10 05:35, H- 16 wrote:

  --------

@ >|

  --------
./rubywarrior/p-beginner/player.rb:3:in `play_turn': undefined method `feel' for #<RubyWarrior::Turn:0x7f4c176e0680 @action=nil, @senses={}> (NoMethodError)
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/units/warrior.rb:12:in `play_turn'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/units/base.rb:72:in `prepare_turn'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:50:in `play'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:50:in `each'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:50:in `play'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:46:in `times'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/level.rb:46:in `play'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/game.rb:72:in `play_current_level'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/game.rb:63:in `play_normal_mode'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/game.rb:23:in `start'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/../lib/ruby_warrior/runner.rb:17:in `run'
         from /usr/lib/ruby/gems/1.8/gems/ruby-warrior/bin/rubywarrior:5

Not something I was expecting from something that is supposed to help teach Ruby . .

Thanks,

Phil.
--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail: phil@pricom.com.au

> Hello guys! I consider RubyWarrior may be useful for learning. A have
> reached for 6'th level (as beginner).

> Now my code looks as following:http://good.net/_5pJ5Rurvz\.
> I can't understand issue: if i call in method:
> def roam_to_combat!
> debug("Entering roam_to_combat")
> state = :ws_combat
> @ini_health = health
> debug(@ini_health)
> warrior.attack!(cur_dir)
> end

> then it lacks to execute string "state = :ws_combat".
> But if i call
> def roam_to_combat!
> debug("Entering roam_to_combat")
> self.state = :ws_combat # <-- here is difference
> @ini_health = health
> debug(@ini_health)
> warrior.attack!(cur_dir)
> end
> then it executes "state = :ws_combat" normally.

> Why it didn't execute "state =" without "self"?
> Is it Ruby's bug?
> I got Ruby 1.8 installed.

state = :ws_combat

is an assignment to a local variable. You are not using the variable
in the method, so i assume this is not what you want. When you do

self.state = :ws_combat

you are calling the method state= on the object, which I suppose you
have (maybe created by attr_accessor).

The fact that you have to call it this way is to disambiguate between
a local variable assignment and a method call with implicit receiver.
This is a consequence of the syntactic sugar that allows you have
methods name xxx= that look like assignments.

Jesus.

Yes, "state" is assignment method. It behaves unsimiliar as other
languages:
"xxx=" can be declared in Object Pascal too, for example.
It seems local variable "state" has overriden my method "state".

Yes, that's exactly what happens. The parser flags state as a local
variable, and not state= as a method call.

This can be a source of many hidden bugs for those who well-skilled in
Delphi or C++.
Why Ruby doesn't give me any warning?

I don't know.

Jesus.

路路路

On Fri, Apr 16, 2010 at 9:00 AM, akraynov <akraynov@bk.ru> wrote:

On 16 邪锌褉, 03:25, Jes煤s Gabriel y Gal谩n <jgabrielyga...@gmail.com> > wrote:

On Thu, Apr 15, 2010 at 10:00 PM, akraynov <akray...@bk.ru> wrote:

akraynov wrote:

It seems local variable "state" has overriden my method "state".
This can be a source of many hidden bugs for those who well-skilled in
Delphi or C++.
Why Ruby doesn't give me any warning?

Because it doesn't parse incorrectly; it just runs incorrectly. That's
why you need to do what Jesus explained.
The burden of intelligence is on the developer :wink:

路路路

--
Posted via http://www.ruby-forum.com/\.

you really don't want to send a swarm of angry Ru'ids after you...

just look at the swarm power of butterflies:

路路路

On Apr 9, 5:17 pm, Ryan Davis <ryand-r...@zenspider.com> wrote:

On Apr 9, 2010, at 13:40 , thunk wrote:

> Ok :wink: then :wink: ;), why are the Shopping Baskets still So Dumb :wink: ??

> :wink:

> thunk

You are OFF-TOPIC. I can't say this more plainly: FUCK OFF.

Well, what do you have in front of you? nothing, so you just need to
warrior.walk!
You'll get the feel method later, you don't need it yet as there is no
enemy. (enemies will be shown on the map)

B.D.

路路路

On 10 April 2010 12:56, Philip Rhoades <phil@pricom.com.au> wrote:

Guys,

I just used something simple above because the example stuff gave me the
same problem - that is, using:

class Player
def play_turn(warrior)
   if warrior.feel.enemy?
     warrior.attack!
   else
     warrior.walk!
   end
end
end

results in:

Welcome to Ruby Warrior
[1] p - beginner - level 1 - score 0
[2] New Profile
Choose profile by typing the number: 1
Starting Level 1
- turn 1 -
--------
>@ >|
--------
./rubywarrior/p-beginner/player.rb:3:in `play_turn': undefined method
`feel' for #<RubyWarrior::Turn:0x7f4c176e0680 @action=nil, @senses={}>
(NoMethodError)

Not something I was expecting from something that is supposed to help teach
Ruby . .