Class: Connect4::Board
- Inherits:
-
Object
- Object
- Connect4::Board
- Includes:
- Boards::Grid
- Defined in:
- lib/boardgame_engine/connect4.rb
Overview
The Connect-4 board
Instance Method Summary collapse
- #display ⇒ Object
-
#drop_chip(col, owner) ⇒ void
Drop a chip from a certain player into a given column.
-
#initialize ⇒ Board
constructor
A new instance of Board.
- #valid_board_input?(input) ⇒ Boolean
Methods included from Boards::Grid
#clear_diag_path?, #clear_horz_path?, #clear_vert_path?, #consecutive?, #generate_board, #get_piece_at, #parse_input, #set_piece_at
Constructor Details
#initialize ⇒ Board
Returns a new instance of Board.
36 37 38 |
# File 'lib/boardgame_engine/connect4.rb', line 36 def initialize @board = generate_board(6, 7) end |
Instance Method Details
#display ⇒ Object
40 41 42 |
# File 'lib/boardgame_engine/connect4.rb', line 40 def display super(show_col: true) end |
#drop_chip(col, owner) ⇒ void
This method returns an undefined value.
Drop a chip from a certain player into a given column
50 51 52 53 54 55 56 57 |
# File 'lib/boardgame_engine/connect4.rb', line 50 def drop_chip(col, owner) @board.reverse_each do |row| if row[col].nil? row[col] = owner break end end end |
#valid_board_input?(input) ⇒ Boolean
59 60 61 |
# File 'lib/boardgame_engine/connect4.rb', line 59 def valid_board_input?(input) super(input, only_col: true) end |