tictactoe/human.rb

22 lines
370 B
Ruby
Raw Normal View History

2018-01-23 01:04:38 +00:00
class Human
attr_reader :piece
def initialize board, piece
@board = board
@piece = piece
end
def move
print "\nPick a move!\n"
free_moves = @board.get_free
idx = gets.strip.to_i
if not free_moves.include? idx then
print "Square is already taken, try again!"
move
else
@board.set @piece, idx
end
end
end