Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
use variable to store move
Browse files Browse the repository at this point in the history
  • Loading branch information
edgenard committed Apr 2, 2018
1 parent 21918f4 commit 1885386
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tic-tac-toe/tic_tac_toe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ def initialize(s, position=nil, player=nil)
end

def best_move_for(player)
move = NO_MOVE

This comment has been minimized.

Copy link
@medwards1771

medwards1771 Apr 3, 2018

Contributor

can you tell us a little more about the difference between the code before and after this commit?
what is the benefit(s) of storing move as a variable?

SQUARES_ON_BOARD.each do |square|
if square_unoccupied?(square)
return square if winning_move?(square, player)
move = square if winning_move?(square, player)
end
end

SQUARES_ON_BOARD.each do |square|
if square_unoccupied?(square)
return square
move = square if move == NO_MOVE
end
end
return NO_MOVE
return move
end

def winning_move?(square, player)
Expand Down

0 comments on commit 1885386

Please sign in to comment.