Permalink
Browse files

use variable to store move

  • Loading branch information...
edgenard committed Apr 2, 2018
1 parent 21918f4 commit 18853867489a34e45c29939c146f7abee350e8e3
Showing with 4 additions and 3 deletions.
  1. +4 −3 tic-tac-toe/tic_tac_toe.rb
@@ -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.

@medwards1771

medwards1771 Apr 3, 2018

Collaborator

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)

0 comments on commit 1885386

Please sign in to comment.