Class: Linotype::Strategy
- Inherits:
-
Object
- Object
- Linotype::Strategy
- Defined in:
- lib/linotype/strategy.rb
Constant Summary collapse
- EDGE_AND_CORNER =
->(move) do score = move.score[:covered] + move.score[:defended] + move.score[:edges] + move.score[:corners] score += 100000 if move.winning_move? score end
- CORNER_LOVER =
->(move) do score = move.score[:covered] + move.score[:defended] + move.score[:edges] + move.score[:corners] score += 10 if move.first_covered_corner? score += 100000 if move.winning_move? score end
- MAX_SIX_LETTERS =
->(move) do move.word.length <= 6 ? move.word.length + move.score[:covered] : 0 end
- MAX_FIVE_LETTERS =
->(move) do move.word.length <= 5 ? move.word.length + move.score[:covered] : 0 end
- MAX_THREE_LETTERS =
->(move) do move.word.length <= 3 ? move.word.length + move.score[:covered] : 0 end
Instance Attribute Summary collapse
-
#scoring_algorithm ⇒ Object
Returns the value of attribute scoring_algorithm.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(scoring_algorithm) ⇒ Strategy
constructor
A new instance of Strategy.
- #score(move) ⇒ Object
Constructor Details
#initialize(scoring_algorithm) ⇒ Strategy
Returns a new instance of Strategy.
31 32 33 |
# File 'lib/linotype/strategy.rb', line 31 def initialize(scoring_algorithm) self.scoring_algorithm = scoring_algorithm end |
Instance Attribute Details
#scoring_algorithm ⇒ Object
Returns the value of attribute scoring_algorithm.
29 30 31 |
# File 'lib/linotype/strategy.rb', line 29 def scoring_algorithm @scoring_algorithm end |
Class Method Details
.predefined(strategy_name) ⇒ Object
39 40 41 |
# File 'lib/linotype/strategy.rb', line 39 def self.predefined(strategy_name) new(const_get(strategy_name)) end |
Instance Method Details
#score(move) ⇒ Object
35 36 37 |
# File 'lib/linotype/strategy.rb', line 35 def score(move) scoring_algorithm.call move end |