tictactoe/human.rb

24 lines
429 B
Ruby

class Human
attr_reader :piece, :val
def initialize board, piece
@val = piece
@board = board
@piece = piece
end
def move
print "\nPick a move!\n"
free_moves = @board.get_free
idx = gets.strip.to_i
free_moves.map! {|i| i+1}
if not free_moves.include? idx then
print "Square is already taken, try again!"
move
else
@board.set @piece, (idx - 1)
end
end
end