Skip to content

Instantly share code, notes, and snippets.

@nextacademy-private
Created August 31, 2014 09:08
Show Gist options
  • Save nextacademy-private/5505d24b7496a1e0e83f to your computer and use it in GitHub Desktop.
Save nextacademy-private/5505d24b7496a1e0e83f to your computer and use it in GitHub Desktop.
Nested Arrays
# Objective 2: Chessboard
# Objective 3: Data table
@AtsushiT
Copy link

#chess bord

chess_board = Array.new(8) do |board|
 [0,0,0,0,0,0,0,0]
end

p_chess_board = ["P", "P", "p", "p", "p", "p", "p", "p"]
k_chess_board = ["R", "W", "B", "K", "Q", "B", "W", "R"]

chess_board[1] = p_chess_board
chess_board[6] = p_chess_board
chess_board[0] = k_chess_board
chess_board[7] = k_chess_board

p chess_board[7][0] == "R"


def chess_board_method(board)
  new_board = []
  0.upto(7).each do |row|
    new_board << 0.upto(7).map{|column| board[row][column]}
  end
  new_board.each do |row_array|
    print "\n"
    row_array.each do |cell|
      print "[#{cell}]"
    end
  end
  print "\n"
end

chess_board_method(chess_board)

@nech0701
Copy link

nech0701 commented Mar 3, 2016

chessboard = []
chessboard << ["wr","wk","wb","wq","wk","wb","wk","wr"]
chessboard << ["wp","wp","wp","wp","wp","wp","wp","wp"]
chessboard << ["","","","","","","","",]
chessboard << ["","","","","","","","",]
chessboard << ["","","","","","","","",]
chessboard << ["","","","","","","","",]
chessboard << ["bp","bp","bp","bp","bp","bp","bp","bp"]
chessboard << ["br","bk","bb","bq","bk","bb","bk","br"]

p chessboard[0][0]

data_array = []
data_array = [ [ "Number","Name,Position","Points per Game" ],
[ "12","Joe Schmo","Center",[14,32,7,0,23] ],
[ "9","Ms. Buckets","Point Guard",[19,0,11,22,0] ],
[ "31","Harvey Kay","Shooting Guard",[0,30,16,0,25] ],
[ "18","Sally Talls","Power Forward",[18,29,26,31,19] ],
[ "22","MK DiBoux","Small Forward",[11,0,23,17,0] ], ]

p data_array[3][3]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment