class ESBI::Evolutionary

Evolutionary Algorithm

Public Class Methods

reset_evo() click to toggle source
# File lib/ESBI.rb, line 387
def self.reset_evo
  # Gets the bot shape.
  bot_shape = File.readlines("evo_data/bot_shape/wings.txt")

  # Create a new input vector based on bot data size.
  bot_input = bot_shape.size.to_i

  # Reset user input to zero.
  reset_usr_input = 0

  open("evo_data/number/input.txt", "w") { |f|
    f.puts reset_usr_input
  }

  # Get random bot_input from bot reset.
  bot_reset = rand(bot_input)

  open("evo_data/bot_input/input.txt", "w") { |f|
    f.puts bot_reset
  }
end
reshape() click to toggle source
# File lib/ESBI.rb, line 441
def self.reshape
  system("clear")

  model_type = File.read("evo_data/model/model_type.txt").strip

  bot_choice = File.read("evo_data/bot_input/input.txt").strip.to_i
  number     = File.read("evo_data/number/input.txt").strip.to_i

  usr_wings = File.readlines("evo_data/usr_shape/wings.txt")
  bot_wings = File.readlines("evo_data/bot_shape/wings.txt")

  current_wingset  = usr_wings[number]
  current_botwings = bot_wings[bot_choice]

  puts "The user #{model_type} model is: #{current_wingset}"

  puts "The bot #{model_type} model is: #{current_botwings}"

  if current_wingset == current_botwings
    use_form
  else
    puts "Form status: Changing form..."

    sleep(3)

    new_value = number + 1

    open("evo_data/number/input.txt", "w") { |f|
      f.puts new_value
    }
  end

  ESBI::Evolutionary.reshape
end
use_form() click to toggle source
# File lib/ESBI.rb, line 409
def self.use_form
  model_type = File.read("evo_data/model/model_type.txt").strip

  puts 'Form status: Suitable...'

  sleep(3)

  number           = File.read("evo_data/number/input.txt").strip.to_i
  usr_wings        = File.readlines("evo_data/usr_shape/wings.txt")
  current_wingset  = usr_wings[number].strip

  puts "\nModel Type: #{model_type}\nAction: #{current_wingset}\n"

  sleep(3)

  # system("ruby #{current_wingset}.rb")

  if    current_wingset == "write_poetry"; ESBI::Creativity.write_poetry
  elsif current_wingset ==         "line"; ESBI::Symbolic.line
  elsif current_wingset ==       "square"; ESBI::Symbolic.square
  elsif current_wingset ==         "cube"; ESBI::Symbolic.cube
  elsif current_wingset ==        "hyper"; ESBI::Symbolic.hyper
  elsif current_wingset ==        "dTree"; ESBI::Dynamic.dTree
  elsif current_wingset ==         "eyes"; ESBI::Eyes.camera
  elsif current_wingset ==     "evaluate"; ESBI::Naive_Bayes.evaluate
  end

  reset_evo

  abort
end