Permalink
Browse files

Clean up: Be more consistent with empty lines

Make it easier to determine where a section ends (and at what indent level to add new code)
  • Loading branch information...
1 parent 1bd40aa commit ba4d0fbb660c6af63cc7ce4c9a24d1bc66fdc30f @esambo committed Feb 29, 2012
@@ -22,5 +22,6 @@ def get_best_position
@board_state.extend Minimax
@board_state.best_position
end
+
end
end
@@ -40,5 +40,6 @@ def response
@winner
)
end
+
end
end
@@ -1,5 +1,6 @@
module TicTacToe
Player = Struct.new(:mark) do
+
def initialize(mark)
self.mark = mark.upcase.to_sym
self.mark = :none unless X? or O?
@@ -50,5 +51,6 @@ def to_i
def to_s
draw? ? ' ' : self.mark.to_s
end
+
end
end
@@ -6,4 +6,5 @@ module TicTacToe
:terminal,
:winner
)
+
end
@@ -17,5 +17,6 @@ def move_taken?(number)
def take_turn
self.next_player = self.next_player.turn
end
+
end
end
@@ -42,5 +42,6 @@ def max_for_X(final_positions)
def min_for_O(final_positions)
final_positions.min_by { |p| p.rank }
end
+
end
end
@@ -23,5 +23,6 @@ def deep_copy
def take_turn
self.next_player = self.next_player.turn
end
+
end
end
@@ -46,5 +46,6 @@ def full?
spaces = self.positions.count(Player.none)
spaces == 0
end
+
end
end
@@ -6,12 +6,14 @@
module TicTacToe
class AiNeverLoses
+
def call
next_player = Player.X
space = Player.none
board_state = BoardState.new 3, space, next_player
context = BestPositionContext.new board_state
context.call
end
+
end
end
@@ -58,6 +58,8 @@ module TicTacToe
numbers.uniq.count.should == 9
end
end
+
end
+
end
end
@@ -10,11 +10,11 @@ module TicTacToe
describe '#call' do
let(:context) { BestPositionContext.new(board_state) }
-
it 'should calls #best_position' do
context.board_state.should_receive(:best_position)
context.call
end
end
+
end
end
@@ -10,6 +10,7 @@ module TicTacToe
end
describe '#call' do
+
context 'with a position number' do
let(:number) { 5 }
let(:context) { PlaceMarkContext.new(board_state, number) }
@@ -23,7 +24,6 @@ module TicTacToe
before :each do
context.board_state.stub(:place_mark) { true }
end
-
it 'should call #winner' do
context.board_state.should_receive(:winner)
context.call
@@ -34,7 +34,6 @@ module TicTacToe
before :each do
context.board_state.stub(:place_mark) { false }
end
-
it 'should not call #winner' do
context.board_state.should_not_receive(:winner)
context.call
@@ -89,6 +88,7 @@ module TicTacToe
response_set = context.call
response_set.terminal.should == terminal
end
+
end
context 'without a valid ply' do
@@ -109,9 +109,14 @@ module TicTacToe
response_set = context.call
response_set.winner.should == winner
end
+
end
+
end
+
end
+
end
+
end
end
@@ -24,6 +24,7 @@ module TicTacToe
it 'should not be #O?' do
player.should_not be_O
end
+
end
context 'with :X' do
@@ -36,27 +37,25 @@ module TicTacToe
it 'should not be #none?' do
player.should_not be_none
end
+
end
context 'with :O' do
let(:player) { Player.new :O }
-
it 'should be #O?' do
player.should be_O
end
end
context "with 'X'" do
let(:player) { Player.new 'X' }
-
it 'should be #X?' do
player.should be_X
end
end
context "with 'O'" do
let(:player) { Player.new 'O' }
-
it 'should be #O?' do
player.should be_O
end
@@ -68,6 +67,7 @@ module TicTacToe
player.should be_none
end
end
+
end
describe '#X' do
@@ -95,24 +95,25 @@ module TicTacToe
end
describe '#turn' do
+
context 'with X' do
let(:player) { Player.new :X }
-
it 'should be O' do
player.turn.should be_O
end
end
context 'with O' do
let(:player) { Player.new :O }
-
it 'should be X' do
player.turn.should be_X
end
end
+
end
describe '#to_s' do
+
context 'with :X' do
it "should be 'X'" do
Player.X.to_s.should == 'X'
@@ -130,9 +131,11 @@ module TicTacToe
Player.none.to_s.should == ' '
end
end
+
end
describe '#to_i' do
+
context 'with :X' do
it 'should be 1' do
Player.X.to_i.should == 1
@@ -150,6 +153,8 @@ module TicTacToe
Player.none.to_i.should == 0
end
end
+
end
+
end
end
@@ -29,7 +29,6 @@ module TicTacToe
before :each do
win_position.path = '9864732510'
end
-
it "should be the second last path position: '1'" do
win_position.next_position_number.should == 1
end
@@ -42,12 +41,12 @@ module TicTacToe
win_position.path = '1'
end
let(:position_number) { 2 }
-
it "should change #path to '12'" do
win_position.position_number = position_number
win_position.path.should == '12'
end
end
end
+
end
end
@@ -2,6 +2,7 @@
module TicTacToe
module Helpers
+
def board_of_marks_to_sequental_players(grid_of_string_marks)
grid_of_string_marks.split.map { |mark| Player.new mark }
end
@@ -23,5 +24,6 @@ def setup_players(alternating_sequence_numbers)
board_state.next_player = player
end
end
+
end
end
@@ -12,6 +12,7 @@ module TicTacToe
end
describe '#place_mark' do
+
context 'with no marks' do
it 'should have 9 empty player spaces' do
board_state.positions.should == Array.new(9, Player.none)
@@ -36,7 +37,6 @@ module TicTacToe
context 'with placing a mark in the first space' do
let(:number) { 1 }
-
it 'should remember the last placed position number' do
board_state.place_mark number
board_state.last_position_number.should == number
@@ -49,6 +49,7 @@ module TicTacToe
end
describe 'returns valid_ply' do
+
context 'with place mark on a free space' do
it 'should be true' do
valid_ply = board_state.place_mark 1
@@ -63,7 +64,10 @@ module TicTacToe
valid_ply.should == false
end
end
+
end
+
end
+
end
end
Oops, something went wrong.

0 comments on commit ba4d0fb

Please sign in to comment.