Skip to content

Instantly share code, notes, and snippets.

@thefonso
Created December 13, 2012 10:49
Show Gist options
  • Select an option

  • Save thefonso/4275674 to your computer and use it in GitHub Desktop.

Select an option

Save thefonso/4275674 to your computer and use it in GitHub Desktop.
The little machine that generates X! boards.
def generate_boards(board, player)
virtual_board = board.dup
new_board_hash = {}
empty_spaces = virtual_board.grid.select{ |k, v| v == " " }.keys
empty_spaces.each do |space|
cloned_board = Board.new
cloned_board.grid = board.grid.clone
if player == 'O'
new_board = move_as_somebody(cloned_board, 'X', space)
new_player = 'X'
@virtual_board_hash[@i] = new_board.grid
else
new_board = move_as_somebody(cloned_board, 'O', space)
new_player = 'O'
@virtual_board_hash[@i] = new_board.grid
end
generate_boards(new_board, new_player)
end
return @virtual_board_hash
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment