-
-
Save mikekellyio/7883595 to your computer and use it in GitHub Desktop.
This file contains 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
class C4Board | |
attr_attribute :board | |
attr_attribute :mover | |
BLACK = :black | |
RED = :red | |
EMPTY = nil | |
def initialize(state = C4Board.starting_board) | |
mover = :black | |
board = state | |
end | |
# returns an array of all the columns a piece can be dropped in currently | |
def moves | |
board.map {|c| c.index nil } | |
end | |
# returns a new board with the to_move's piece dropped in the provided column | |
def move(position) | |
mover = mover.eq?(:red) ? :black : :red | |
end | |
# returns :red or :black, depending on whose turn it is. | |
def player_to_move | |
mover | |
end | |
# truthy if won, false otherwise | |
def won? | |
end | |
# should return 2d array suitable for displaying | |
def cells | |
end | |
# returns a board initialized to be empty, with :black set as the current player. | |
def self.starting_board | |
Array.new(6) { Array.new(7) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment