Skip to content

Instantly share code, notes, and snippets.

@marksim
Created November 8, 2013 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marksim/7374557 to your computer and use it in GitHub Desktop.
Save marksim/7374557 to your computer and use it in GitHub Desktop.
require 'rspec'
class TicTacToe
attr_reader :current_player
def initialize
@current_player = 'O'
@plays = {'O' => [], 'X' => []}
end
def play(x,y)
return false if x > 1 || y > 1 || x < -1 || y < -1
@plays[@current_player] << [x, y]
@current_player = ((@current_player == 'X') ? 'O' : 'X')
end
def at(x,y)
@plays.each do |player, plays|
return player if plays.include?([x, y])
end
nil
end
end
describe "TicTacToe" do
let(:game) { TicTacToe.new }
context "lets two players alternate turns" do
it "assiging O for player1" do
game.play(0, 0) # center
expect(game.at(0, 0)).to eql 'O'
end
it "assigning X for player2" do
game.play(0, 0) # center
game.play(0, 1)
expect(game.at(0,1)).to eql 'X'
end
end
it "does not allow a player to place move off the board" do
expect(game.play(2, 2)).to be_false
expect(game.current_player).to eql 'O'
end
context "has a winner when it" do
it "has 3 of the same token on a row"
it "has 3 of the same token on a column"
it "has 3 of the same token diagonnally left to right"
it "has 3 of the same token diagonnally right to left"
end
context "has a tie when it" do
it "has all rows and columns filled without a winner present"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment