Class: YumemoireHumanMode::HumanMode

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

Class Method Summary collapse

Class Method Details

.ai_decisionObject

AI Decision Making #



1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
# File 'lib/YumemoireFramework.rb', line 1994

def self.ai_decision
  cchoice = @choice

  ## Determining user data and user choice.
  value = File.read("lib/input/user/user_choice.txt").to_s.to_i

  user_data   = File.readlines("lib/data/user/candidates.txt")
  user_choice = user_data[value]

  ## Processing AI focused data
  ai_choice            = File.read("lib/data/ai/ai_choice.txt").to_s.to_i
  ai_initial_candidate = user_data[ai_choice]
  ai_search_limit      = user_data.size.to_i

  ## Create AI data from user data.
  ai_search_limit.times do
    if ai_choice == user_choice
      #puts "\e[38;2;187;127;118m  The specific candidate was found. Terminating selection..."

      ai_data      = user_data.slice!(ai_choice)

      open("lib/data/ai/candidates.txt", "w") { |f|
        f.puts ai_data
      }
    else
      puts "\e[38;2;187;127;118mL'ennemi découvre que vous n'avez pas fait ce choix...\e[0m"
    end

    sleep(1.5)
  end

  ## AI processing data.
  ai_choice            = File.read("lib/data/ai/ai_choice.txt").to_s.to_i
  ai_data              = File.readlines("lib/data/ai/candidates.txt")
  ai_search_limit      = ai_data.size.to_i
  ai_next_candidate    = ai_data[ai_choice]

  ai_search_limit.times do
    if ai_next_candidate == user_choice
      ai_final_candidate = ai_next_candidate

      puts "\e[38;2;187;127;118mCandidate found, processing input...\e[0m"; sleep(1)

      # Breaks the loop if an appropriate candidate is found.

      sleep(1.5)

      conditions = ["Sword", "Stone", "Tarp"]

      decision_made = conditions.sample

      puts "\e[38;2;187;127;118mBy process of elimination, the bot chose: #{ai_data}\e[0m"

      @cchoice = "#{ai_data}"

      puts $cchoice

      break
    else
      ai_choice            = File.read("lib/data/ai/ai_choice.txt").to_s.to_i
      ai_data              = File.readlines("lib/data/ai/candidates.txt")
      ai_search_limit      = ai_data.size.to_i
      ai_next_candidate    = ai_data[ai_choice]

      ai_data      = user_data.slice!(ai_choice).strip

      puts "\e[38;2;187;127;118mEnemy found the option #{ai_data}\e[0m"

      enemy_decision = ["choose", "skip"]

      decision_made = enemy_decision.sample

      if decision_made == "choose"
        puts "\e[38;2;187;127;118mThe enemy chose: #{ai_data}, but found it causes a stalemate. Makes a new decision\e[0m"

        @cchoice = "#{ai_data}"

        enemy_decision = ["Epee", "Ishi", "Bache"]

        decision_made = enemy_decision.sample

        if    decision_made == "Sword"
          @cchoice = "Epee"
        elsif decision_made == "Stone"
          @cchoice = "Ishi"
        elsif decision_made ==  "Tarp"
          @cchoice = "Bache"
        end

        break
      else
        puts "\e[38;2;187;127;118mEnemy weighed the option of choosing #{ai_data}, but decided to skip its turn.\e[0m"

        break
      end

      sleep(1.5)
 
      open("lib/data/ai/candidates.txt", "w") { |f|
        f.puts ai_data
      }
    end
  end
end

.parserObject



2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
# File 'lib/YumemoireFramework.rb', line 2099

def self.parser
  loop do
    system("clear")

    if $current_day < $lunar_ticks
      this_day = 29

      puts "\e[38;2;187;127;118mLa prochaine phase lunaire est en cours: #{this_day - $current_day} days...\e[0m"
    else
      lunar_cycle

      # Reset lunar ticks to twenty days away.
      $current_day = 1
    end

    menu = File.read("lib/images/menus/main.txt")

    puts menu

    puts "\e[38;2;187;127;118m[ Currency is #{$player_franc} Francs And #{$player_yen} Yen ]\e[0m"

    puts "\e[38;2;187;127;118m\n[ Stalemates: #{$stalemates} ] [ Player Strikes: #{$player_struck} ] [ Enemy Strikes: #{$enemy_struck} ]\e[0m"
    puts "\e[38;2;187;127;118m  [ #{$player_lunario} Lunario ( You wont need this for most game functions. ) ]"

    puts "\e[38;2;187;127;118m\n\e[0m"
    puts "\e[38;2;187;127;118mSouer De Chaos ( Ana Nuveyatusuki ) HP: #{$player_hp} \e[0m"
    puts "\e[38;2;187;127;118m#{$current_monster_name} HP: #{$enemy_hp}\e[0m"
    #puts "\e[38;2;187;127;118mSouer De Commande ( Ana Nuveyatusuki ) HP: #{$enemy_hp}\e[0m"
    puts "\e[38;2;187;127;118m\n\e[0m"

    if $player_hp <= 0
      system("clear")

      puts "\e[38;2;187;127;118mYou've been zombiefied!\e[0m"

      sleep(1.5)

      YumemoireZombieMode::ZombieMode.parser
    elsif $enemy_hp <= 0
      puts "\e[38;2;187;127;118mYou won\e[0m"

      gets.chomp

      abort
    end

    conditions = {
      "Epee"  =>  "Ishi",
      "Ishi"  => "Bache",
      "Bache" =>  "Epee",
    }

    if $has_spider == true
      puts "\e[38;2;187;127;118mTo heal the player, type: Heal\e[0m"
    else
      puts "\e[38;2;187;127;118mTo heal the player, type: Sleep\e[0m"
    end

    print "\e[38;2;164;145;91m\nEpee, Ishi, or Bache >> \e[0m"
    @choice = gets.chomp.capitalize

    if    @choice == "Epee"
      File.open("lib/input/user/user_choice.txt", "w") { |f|
        f.puts "0"
      }

      # Records a history of player actions.
      File.open("lib/data/user/chosen_action.txt", "a") { |f|
        f.puts "0"
      }
    elsif @choice == "Ishi"
      File.open("lib/input/user/user_choice.txt", "w") { |f|
        f.puts "1"
      }

      # Records a history of player actions.
      File.open("lib/data/user/chosen_action.txt", "a") { |f|
        f.puts "1"
      }
    elsif @choice == "Bache"
      File.open("lib/input/user/user_choice.txt", "w") { |f|
        f.puts "2"
      }

      # Records a history of player actions.
      File.open("lib/data/user/chosen_action.txt", "a") { |f|
        f.puts "2"
      }
    elsif @choice == "Sleep"
      File.open("lib/input/user/user_choice.txt", "w") { |f|
        f.puts "2"
      }

      # Records a history of player actions. This one defaults to bache even though its a distinct action.
      File.open("lib/data/user/chosen_action.txt", "a") { |f|
        f.puts "2"
      }
    elsif @choice == "Heal"
      File.open("lib/input/user/user_choice.txt", "w") { |f|
        f.puts "2"
      }

      # Records a history of player actions. This one defaults to bache even though its a distinct action.
      File.open("lib/data/user/chosen_action.txt", "a") { |f|
        f.puts "2"
      }
    end

    puts " "
    sleep(1.5)

    # Experiment with using an enemy that learns from player's decisions.'
    YumemoireHumanMode::HumanMode.ai_decision

    if conditions[@choice] == @cchoice
      #puts "\e[38;2;187;127;118m  You were struck by the enemy!"

      $enemy_struck = $enemy_struck + 1

      # The amount of damage player gets is based on the enemies attack power.
      #$player_hp = $player_hp - $enemy_atk
      YumemoireFramework::DamageFormulas.enemy_damage_rate
    elsif @cchoice == @choice
      puts "\e[38;2;187;127;118mYou reach a stalemate.\e[0m"

      $stalemates = $stalemates + 1
    elsif conditions[@cchoice] == @choice
      #puts "\e[38;2;187;127;118m  You struck the enemy!"

      $player_struck = $player_struck + 1

      # The amount of damage enemy recieves is based on the player's attack power.
      #$enemy_hp = $enemy_hp - $player_atk
      YumemoireFramework::DamageFormulas.player_damage_rate
    elsif @choice == "Sleep"
      puts "\e[38;2;187;127;118mYou've opted to stay at an inn...'\e[0m"

      sleep(1.5)

      stay_at_inn
    elsif @choice == "Heal"
      puts "\e[38;2;187;127;118mThink quickly or you wont be able to heal properly....'\e[0m"

      sleep(1.5)

      spider_pig_farmer
    else
      puts "\e[38;2;187;127;118m#{@choice} is not a valid option\e[0m"
    end

    $current_day = $current_day + 1
  end
end