Skip to content

Instantly share code, notes, and snippets.

@badbabykosh
Created December 9, 2012 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badbabykosh/4246380 to your computer and use it in GitHub Desktop.
Save badbabykosh/4246380 to your computer and use it in GitHub Desktop.
Attempting to build hash of hashes
def build_virtual_boards_hash(board, player)
virtual_boards_hash = {}
new_board_hash = {}
virtual_board = board.dup
empty_spaces_on_board = virtual_board.grid.select{ |k, v| v == " " }.keys
index_mark = 'VB'+empty_spaces_on_board.length.to_s
while empty_spaces_on_board.length >= 1
empty_spaces_on_board.each do |empty_space_symbol|
p new_board_hash = move_as_somebody(board, player, empty_space_symbol, index_mark)
build_virtual_boards_hash(board, player)
end
end
end
---------------------
input is...
@player = "X"
@board.grid[:a1] = "X"
@board.grid[:a2] = " "
@board.grid[:a3] = " "
@board.grid[:b1] = " "
@board.grid[:b2] = "O"
@board.grid[:b3] = " "
@board.grid[:c1] = " "
@board.grid[:c2] = " "
@board.grid[:c3] = " "
---------------------
I need as output something as such...
virtual_board_hash => {
{"VB7"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>" ", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}>}
{"VB6"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>"X", :b1=>" ", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}>}
{"VB5"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>"X", :b1=>"X", :b2=>"O", :b3=>" ", :c1=>" ", :c2=>" ", :c3=>" "}>}
{"VB4"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>"X", :b1=>"X", :b2=>"O", :b3=>"X", :c1=>" ", :c2=>" ", :c3=>" "}>}
{"VB3"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>"X", :b1=>"X", :b2=>"O", :b3=>"X", :c1=>"X", :c2=>" ", :c3=>" "}>}
{"VB2"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>"X", :b1=>"X", :b2=>"O", :b3=>"X", :c1=>"X", :c2=>"X", :c3=>" "}>}
{"VB1"=>#<Board:0x007f9ab388f018 @grid={:a1=>"X", :a2=>"X", :a3=>"X", :b1=>"X", :b2=>"O", :b3=>"X", :c1=>"X", :c2=>"X", :c3=>"X"}>}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment