Skip to content

Instantly share code, notes, and snippets.

@mikekellyio
Forked from bokmann/C4Board.rb
Created December 10, 2013 00:17
Show Gist options
  • Save mikekellyio/7883595 to your computer and use it in GitHub Desktop.
Save mikekellyio/7883595 to your computer and use it in GitHub Desktop.
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