lib/ttt.rb
def play(board, board_size, board_length, player)
    puts "The game has started".green
    index = player.to_i
    if player.to_i == 1
      board_size += 1
    end
    while index < board_size
      if index.odd?
        print "\nPlayer A -- Pick a number: ".cyan
        value = gets.chomp
        puts
        player_a = player_a(board, value)
        display_board(board, board_length.to_i)
        sign = "X"
        @player_a_count += 1
        if winner(board, sign, board_length)
          puts "PLAYER A - Congratulations!!! You are the winner\n".green
          @winners << "X"
          @player_a_count = 0
          break
        end
        unless player_a
          puts "Invalid number, please try again".red
          index -= 1
          @player_a_count -= 1
        end
        puts "In Draw!!!".green if (index + 1) == board_size
        @winners << "In Draw"
      else
        print "\nPlayer B -- Pick a number: ".cyan
        value = gets.chomp
        puts
        player_b = player_b(board, value)
        display_board(board, board_length.to_i)
        sign = "O"
        @player_b_count += 1
        if winner(board, sign, board_length)
          puts "PLAYER B - Congratulations!!! You are the winner\n".green
          @winners << "O"
          @player_b_count = 0
          break
        end
        unless player_b
          puts "Invalid number, please try again".red
          index -= 1
          @player_b_count -= 1
        end
        puts "In Draw!!!".green if (index + 1) == board_size
      end
      index += 1
    end
  end
#Logic of the game where the player's turn is valided
Logic of the game where the player's turn is valided
Logic of the game where the player ' s turn is valided
def play(board, board_size, board_length, player)
    puts "The game has started".green
    index = player.to_i
    if player.to_i == 1
      board_size += 1
    end
    while index < board_size
      if index.odd?
        print "\nPlayer A -- Pick a number: ".cyan
        value = gets.chomp
        puts
        player_a = player_a(board, value)
        display_board(board, board_length.to_i)
        sign = "X"
        @player_a_count += 1
        if winner(board, sign, board_length)
          puts "PLAYER A - Congratulations!!! You are the winner\n".green
          @winners << "X"
          @player_a_count = 0
          break
        end
        unless player_a
          puts "Invalid number, please try again".red
          index -= 1
          @player_a_count -= 1
        end
        puts "In Draw!!!".green if (index + 1) == board_size
        @winners << "In Draw"
      else
        print "\nPlayer B -- Pick a number: ".cyan
        value = gets.chomp
        puts
        player_b = player_b(board, value)
        display_board(board, board_length.to_i)
        sign = "O"
        @player_b_count += 1
        if winner(board, sign, board_length)
          puts "PLAYER B - Congratulations!!! You are the winner\n".green
          @winners << "O"
          @player_b_count = 0
          break
        end
        unless player_b
          puts "Invalid number, please try again".red
          index -= 1
          @player_b_count -= 1
        end
        puts "In Draw!!!".green if (index + 1) == board_size
      end
      index += 1
    end
  end
def play ( board , board_size , board_length , player ) puts "The game has started" . green index = player . to_i if player . to_i == 1 board_size += 1 end while index < board_size if index . odd? print "\nPlayer A -- Pick a number: " . cyan value = gets . chomp puts player_a = player_a ( board , value ) display_board ( board , board_length . to_i ) sign = "X" @player_a_count += 1 if winner ( board , sign , board_length ) puts "PLAYER A - Congratulations!!! You are the winner\n" . green @winners << "X" @player_a_count = 0 break end unless player_a puts "Invalid number, please try again" . red index -= 1 @player_a_count -= 1 end puts "In Draw!!!" . green if ( index + 1 ) == board_size @winners << "In Draw" else print "\nPlayer B -- Pick a number: " . cyan value = gets . chomp puts player_b = player_b ( board , value ) display_board ( board , board_length . to_i ) sign = "O" @player_b_count += 1 if winner ( board , sign , board_length ) puts "PLAYER B - Congratulations!!! You are the winner\n" . green @winners << "O" @player_b_count = 0 break end unless player_b puts "Invalid number, please try again" . red index -= 1 @player_b_count -= 1 end puts "In Draw!!!" . green if ( index + 1 ) == board_size end index += 1 end end
Logic of the game where the player's turn is valided
Logic of the game where the player ' s turn is valided
board
board_size
board_length
player