Class: Connect4::Board

Inherits:
Object
  • Object
show all
Includes:
Boards::Grid
Defined in:
lib/boardgame_engine/connect4.rb

Overview

The Connect-4 board

Instance Method Summary collapse

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

#initializeBoard

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

#displayObject



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

Parameters:

  • col (Integer)

    The column chosen by the player

  • owner (Player)

    the player dropping the chip



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

Returns:

  • (Boolean)


59
60
61
# File 'lib/boardgame_engine/connect4.rb', line 59

def valid_board_input?(input)
  super(input, only_col: true)
end