class DynamicAI::Generate

Public Class Methods

behaviours() click to toggle source
# File lib/dynamicAI.rb, line 16
def self.behaviours
  old_action = File.read("data/action/history.txt")

  # Creates a list of behaviours the AI does.
  behaviours = File.readlines("data/script/behaviours.txt")

  # Determines a reset limit based on the maximum behaviour list size.
  size_limit_file = behaviours.size.to_i
  size_limit      = size_limit_file - 1

  # Takes an input from a number file.
  number     = File.read("data/input/number.txt").strip.to_i

  # If the number file exceeds the size limit, reset to zeo.
  if number > size_limit
    number = 0
  end

  # Dettermines the action to be written to file and ran.
  new_action = behaviours[number]

  # Writes the action to a temp ruby.
  open("temp.rb", "w") { |f|
    f.puts new_action
    f.puts old_action
  }

  # Append new action to old_action.
  open("data/action/history.txt", "w") { |f|
    f.puts new_action
    f.puts old_action
  }

  # Add one increment to number file.
  open("data/input/number.txt", "w") { |f|
    f.puts number = number + 1
  }
end