Class: GameBoardFolder
- Inherits:
-
Object
- Object
- GameBoardFolder
- Defined in:
- lib/threesmodel/game_board_folder.rb
Overview
A game board keeps and manipulates the state of the game.
Instance Method Summary collapse
- #can_fold_down?(state) ⇒ Boolean
- #can_fold_left?(state) ⇒ Boolean
- #can_fold_right?(state) ⇒ Boolean
- #can_fold_up?(state) ⇒ Boolean
-
#fold_down(state) ⇒ Object
Folds the game board downwards.
-
#fold_left(state) ⇒ Object
Folds the game board from right to left.
-
#fold_right(state) ⇒ Object
Folds the game board from left to right.
-
#fold_up(state) ⇒ Object
Folds the game board upwards.
-
#initialize(line_folder = LineFolder.new) ⇒ GameBoardFolder
constructor
A new instance of GameBoardFolder.
Constructor Details
#initialize(line_folder = LineFolder.new) ⇒ GameBoardFolder
5 6 7 |
# File 'lib/threesmodel/game_board_folder.rb', line 5 def initialize(line_folder = LineFolder.new ) @line_folder = line_folder end |
Instance Method Details
#can_fold_down?(state) ⇒ Boolean
77 78 79 80 81 82 83 |
# File 'lib/threesmodel/game_board_folder.rb', line 77 def can_fold_down?(state) foldable = false state.column_vectors.each{|line| foldable = (foldable or @line_folder.can_fold?(line.to_a.reverse)) } foldable end |
#can_fold_left?(state) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/threesmodel/game_board_folder.rb', line 53 def can_fold_left?(state) foldable = false state.row_vectors.each{|line| foldable = (foldable or @line_folder.can_fold?(line.to_a)) } foldable end |
#can_fold_right?(state) ⇒ Boolean
61 62 63 64 65 66 67 |
# File 'lib/threesmodel/game_board_folder.rb', line 61 def can_fold_right?(state) foldable = false state.row_vectors.each{|line| foldable = (foldable or @line_folder.can_fold?(line.to_a.reverse)) } foldable end |
#can_fold_up?(state) ⇒ Boolean
69 70 71 72 73 74 75 |
# File 'lib/threesmodel/game_board_folder.rb', line 69 def can_fold_up?(state) foldable = false state.column_vectors.each{|line| foldable = (foldable or @line_folder.can_fold?(line.to_a)) } foldable end |
#fold_down(state) ⇒ Object
Folds the game board downwards.
43 44 45 46 47 48 49 50 51 |
# File 'lib/threesmodel/game_board_folder.rb', line 43 def fold_down(state) new_state = [] state.column_vectors.each {|column| values = column.to_a.reverse values = @line_folder.fold(values) new_state << values.reverse } Matrix.columns(new_state) end |
#fold_left(state) ⇒ Object
Folds the game board from right to left.
10 11 12 13 14 15 16 17 18 |
# File 'lib/threesmodel/game_board_folder.rb', line 10 def fold_left(state) new_state = [] state.row_vectors.each_index {|i| values = state.row_vectors[i].to_a values = @line_folder.fold(values) new_state << values } Matrix.rows(new_state) end |
#fold_right(state) ⇒ Object
Folds the game board from left to right.
21 22 23 24 25 26 27 28 29 |
# File 'lib/threesmodel/game_board_folder.rb', line 21 def fold_right(state) new_state = [] state.row_vectors.each {|row| values = row.to_a.reverse values = @line_folder.fold(values) new_state << values.reverse } Matrix.rows(new_state) end |
#fold_up(state) ⇒ Object
Folds the game board upwards.
32 33 34 35 36 37 38 39 40 |
# File 'lib/threesmodel/game_board_folder.rb', line 32 def fold_up(state) new_state = [] state.column_vectors.each {|column| values = column.to_a values = @line_folder.fold(values) new_state << values } Matrix.columns(new_state) end |