Class: DynamicAI::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamicAI.rb

Class Method Summary collapse

Class Method Details

.behavioursObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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