Skip to content

Commit

Permalink
Removed attr_accessors for board and winning solutions. Revised winni…
Browse files Browse the repository at this point in the history
…ng solutions using a zero-based index
  • Loading branch information
lisahamm committed Mar 20, 2015
1 parent 55dec59 commit 9650146
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/tic_tac_toe/board.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def empty_cells

def get_winning_mark
winning_solutions.each do |solution|
cell1 = cells[solution[0]-1].symbol
cell2 = cells[solution[1]-1].symbol
cell3 = cells[solution[2]-1].symbol
cell1 = cells[solution[0]].symbol
cell2 = cells[solution[1]].symbol
cell3 = cells[solution[2]].symbol
if cell1 == cell2 && cell1 == cell3 && cell1 != nil
return cell1
end
Expand Down Expand Up @@ -74,8 +74,6 @@ def self.from_array(array)

private

attr_accessor :board, :winning_solutions

def defaults
{size: BOARD_SIZE, cells: nil}
end
Expand All @@ -87,10 +85,14 @@ def cellify(data)
end

def winning_solutions
self.winning_solutions = [
[1, 2, 3], [4, 5, 6], [7, 8, 9],
[1, 4, 7], [2, 5, 8], [3, 6, 9],
[1, 5, 9], [3, 5, 7]
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
]
end

Expand Down

0 comments on commit 9650146

Please sign in to comment.