Created
December 13, 2012 10:49
-
-
Save thefonso/4275674 to your computer and use it in GitHub Desktop.
The little machine that generates X! boards.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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