Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Pull #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ Usage
# bundle install
# irb -I lib

require 'tictactoe'

ttt = TicTacToe.new([["X", "X", "X"],
["O", "O", "_"],
["O", "_","_"]]
["O", "_","_"]])

ttt.winner # => "X"
```
Expand Down
4 changes: 2 additions & 2 deletions lib/tictactoe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def in_coll?(config, player)
end

def in_diag?(config, player)
diag_indexes = [(0...size).zip((0...size))]
diag_indexes << (0...size).to_a.reverse.zip((0...size))
diag_indexes = [(0...size).to_a.zip((0...size).to_a)]
diag_indexes << (0...size).to_a.reverse.zip((0...size).to_a)
diagonals = diag_indexes.map {|indexes| indexes.map { |x, y| config[x][y] } }
in_row?(diagonals, player)
end
Expand Down
14 changes: 14 additions & 0 deletions test/tictactoe_test.rb
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
require 'test_helper'

describe TicTacToe do

describe "X wins horizontally" do
subject do
TicTacToe.new([["X", "X", "X"],
["O", "O", "_"],
["O", "_","_"]])
end
it "X must be the winner" do
subject.winner.must_equal "X"
end
end
end