tictactoe/human.rb

24 lines
429 B
Ruby
Raw Permalink Normal View History

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