class TicTacToe
def initialize
@board = Array.new(9){|i| "#{i}:__"}
puts "Welcome to Tic Tac Toe!"
show_board
@turn = 1
choose_spot
end
def show_board
puts "\n\n"
puts "Player 1 may begin. Please place your mark using the numbers provided on the board."
puts "\n\n"
puts ">>>>>>>>>>>>>>>"
puts "#{@board[0]}|#{@board[1]}|#{@board[2]}|\n\n"
puts "#{@board[3]}|#{@board[4]}|#{@board[5]}|\n\n"
puts "#{@board[6]}|#{@board[7]}|#{@board[8]}|"
puts "<<<<<<<<<<<<<<<"
puts "\n\n"
end
def choose_spot
@player = @turn.odd? ? "1" : "2"
@board_piece = @turn.odd? ? "X" : "O"
turn += 1
puts "Player #{@player}, (#{board_piece}). Your turn. Please type a number to put your piece on the board."
@input = gets.chomp.to_i
check_valid_spot
end
def check_valid_spot
loop do
board.each do |i|
if @input.include?(0..8)
if i.include?("__")
i.replace(@board_piece)
else
puts "Sorry there's already a piece there! Please try again."
end
else
puts "Sorry that isn't a valid number! Please look at the board and try again."
end
end
end
end
end
Y2xhc3MgVGljVGFjVG9lCglkZWYgaW5pdGlhbGl6ZQoJCUBib2FyZCA9IEFycmF5Lm5ldyg5KXt8aXwgIiN7aX06X18ifQoJCXB1dHMgIldlbGNvbWUgdG8gVGljIFRhYyBUb2UhIgoJCXNob3dfYm9hcmQKCQlAdHVybiA9IDEKCQljaG9vc2Vfc3BvdAoJZW5kCgoJZGVmIHNob3dfYm9hcmQKCQlwdXRzICJcblxuIgoJCXB1dHMgIlBsYXllciAxIG1heSBiZWdpbi4gUGxlYXNlIHBsYWNlIHlvdXIgbWFyayB1c2luZyB0aGUgbnVtYmVycyBwcm92aWRlZCBvbiB0aGUgYm9hcmQuIgoJCXB1dHMgIlxuXG4iCgkJcHV0cyAiPj4+Pj4+Pj4+Pj4+Pj4+IgoJCXB1dHMgIiN7QGJvYXJkWzBdfXwje0Bib2FyZFsxXX18I3tAYm9hcmRbMl19fFxuXG4iCgkJcHV0cyAiI3tAYm9hcmRbM119fCN7QGJvY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