From ee889e6b55c7c6bed6d67bd037b9ec86dc082051 Mon Sep 17 00:00:00 2001 From: Lisa Hamm Date: Mon, 23 Mar 2015 09:44:55 -0500 Subject: [PATCH] Changed BOARD_SIZE from a global constant to a constant within the Board class. Added #valid_cell_number? to check if a number falls in the board's cell range --- lib/tic_tac_toe/board.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tic_tac_toe/board.rb b/lib/tic_tac_toe/board.rb index 3899473..37b9b0e 100644 --- a/lib/tic_tac_toe/board.rb +++ b/lib/tic_tac_toe/board.rb @@ -1,9 +1,10 @@ module TicTacToe - BOARD_SIZE = 3 class Board attr_accessor :cells, :size + BOARD_SIZE = 3 + def initialize(options={}) options = defaults.merge(options) @size = options[:size] @@ -22,6 +23,10 @@ def remove_mark(cell_number) cells[cell_number].symbol = nil end + def valid_cell_number?(cell_number) + (0..(size ** 2 - 1)).include?(cell_number) + end + def empty_cell?(cell_number) cells[cell_number].symbol == nil end