Class: Battle::AI::MoveHeuristicBase

Inherits:
Object
  • Object
show all
Defined in:
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00002 Rest.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00004 CuringMoves.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00003 HealingMoves.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00005 ReflectMoves.rb

Overview

Class responsive of handling the heuristics of moves

Direct Known Subclasses

CuringMove, HealingMoves, ReflectMoves, Rest

Defined Under Namespace

Classes: CuringMove, HealingMoves, ReflectMoves, Rest

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ignore_effectiveness = false, ignore_power = false, overwrite_move_kind_flag = false) ⇒ MoveHeuristicBase

Create a new MoveHeusristicBase

Parameters:

  • ignore_effectiveness (Boolean) (defaults to: false)

    if this heuristic ignore effectiveness (wants to compute it themself)

  • ignore_power (Boolean) (defaults to: false)

    if this heuristic ignore power (wants to compute it themself)

  • overwrite_move_kind_flag (Boolean) (defaults to: false)

    if the effect overwrite (to true) the can see move kind flag



12
13
14
15
16
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 12

def initialize(ignore_effectiveness = false, ignore_power = false, overwrite_move_kind_flag = false)
  @ignore_effectiveness = ignore_effectiveness
  @ignore_power = ignore_power
  @overwrite_move_kind_flag = overwrite_move_kind_flag
end

Class Method Details

.new(db_symbol, level) ⇒ MoveHeuristicBase

Get a MoveHeuristic by db_symbol and level

Parameters:

  • db_symbol (Symbol)

    db_symbol of the move

  • level (Integer)

    level of the current AI

Returns:



65
66
67
68
69
70
71
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 65

def new(db_symbol, level)
  klass = @move_heuristics[db_symbol]&.find { |entry| entry[:min_level] <= level }
  klass = klass ? klass[:klass] : self
  heuristic = klass.allocate
  heuristic.send(:initialize)
  return heuristic
end

.register(db_symbol, klass, min_level = 0)

Note:

If there's several min_level, the highest condition matching with current AI level is choosen.

Register a new move heuristic

Parameters:

  • db_symbol (Symbol)

    db_symbol of the move

  • klass (Class<MoveHeuristicBase>, nil)

    klass holding the logic for this heuristic

  • min_level (Integer) (defaults to: 0)

    minimum level when the heuristic acts



54
55
56
57
58
59
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 54

def register(db_symbol, klass, min_level = 0)
  @move_heuristics[db_symbol] ||= []
  @move_heuristics[db_symbol].delete_if { |entry| entry[:min_level] == min_level }
  @move_heuristics[db_symbol] << { min_level: min_level, klass: klass } if klass
  @move_heuristics[db_symbol].sort_by! { |entry| -entry[:min_level] } # This will help to fetch the first min level matching with .find
end

Instance Method Details

#compute(move, user, target, ai) ⇒ Float

Compute the heuristic

Parameters:

Returns:

  • (Float)


42
43
44
45
46
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 42

def compute(move, user, target, ai)
  return 1.0 if move.status?

  return Math.sqrt(move.special? ? user.ats_basis / target.dfs_basis.to_f : user.atk_basis / target.dfe_basis.to_f)
end

#ignore_effectiveness?Boolean

Is this heuristic ignoring effectiveness

Returns:

  • (Boolean)


20
21
22
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 20

def ignore_effectiveness?
  return @ignore_effectiveness
end

#ignore_power?Boolean

Is this heuristic ignoring power

Returns:

  • (Boolean)


26
27
28
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 26

def ignore_power?
  return @ignore_power
end

#overwrite_move_kind_flag?Boolean

Is this heuristic ignoring power

Returns:

  • (Boolean)


32
33
34
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00001 MoveHeuristic/00001 MoveHeuristicBase.rb', line 32

def overwrite_move_kind_flag?
  return @overwrite_move_kind_flag
end