I thought the answer about how to create multidimensional arrays as=20
presented here was very interesting, "create an array of arrays." A funny th=
ing=20
happened on the way to the store.
I fired up FreeRIDE and entered, "chessboard =3D Array.new(8, Array.new=
(8, "=20
")) like so:
irb(main):009:0> chessboard=3DArray.new(8,Array.new(8," "))
=3D&g=
t; [["=20
", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " ", "=
"],=20
[" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ", " "=
, "=20
"], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ", " ",=
"=20
", " "], [" ", " ", " ", " ", " ", " ", " ", " "], [" ", " ", " ", " ", " ",=
"=20
", " ", " "]]
This was exactly as I expected. Then I tried putting a pawn on the=20
board:
irb(main):010:0> chessboard[3][3]=3D"Pawn"
=3D> "Pawn"
Then I looked at the board:
irb(main):011:0> chessboard
=3D> [[" ", " ", " ", "Pawn",=20=
" ", "=20
", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ",=20
"Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " ", " "], ["=
",=20
" ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " ", " ", " "=
, "=20
"], [" ", " ", " ", "Pawn", " ", " ", " ", " "], [" ", " ", " ", "Pawn", " "=
, "=20
", " ", " "]]
You have got to be kidding. The pawn shows up eight times. Not at all w=
hat=20
I expected nor what I wanted. No matter how I tried, I could not make just o=
ne=20
entry in the array of arrays. It appears to me that you have to roll yo=
ur=20
own when using Ruby. Either that or I've misunderstood or made an error in=20
trying to use the information I have gained.
I am very new to this "Ruby" thing and OO in general but it appears to=20=
me=20
that we've got to create a class that contains the required definitions=20
(methods, variables, etc.).
Charles Gray -- Phoenix, AZ (tcykgreis on skype and=20
google-talk)
-------------------------------1163611484--
--part1_327.10162e6d.328cd6dd_boundary--