class KevinsPropietaryBrain::Brain
All Brains must be put in the PlayerBrain module to allow them to be picked up by the game initalizer
Attributes
Public Class Methods
The brain is instantiated with it's role. So that it can be used later in the game
# File lib/kevins_propietary_brain.rb, line 8 def initialize(role) @role = role end
Public Instance Methods
After instantiation the Game will pass the brain two characters from the characters in the models/characters folder, the choose_character
method must return one of the two characters.
# File lib/kevins_propietary_brain.rb, line 18 def choose_character(character_1, character_2) character_1 end
This method is called if your hand is over the hand limit, it returns the card that you would like to discard.
Returning nil or a card you don't have is a very bad idea. Bad things will happen to you.
# File lib/kevins_propietary_brain.rb, line 38 def discard player.hand.first end
you have the option of picking from many cards, pick the best one.
# File lib/kevins_propietary_brain.rb, line 13 def pick(number, *cards) cards.flatten.first(number) end
This is the method that is called on your turn.
# File lib/kevins_propietary_brain.rb, line 43 def play bang = player.from_hand(Card.bang_card) if bang left_player = player.players.first if left_player && left_player.distance_to <= 1 player.play_card(bang, left_player) end end end
This method is called on your brain when you are the target of a card that has a bang action (a missable attack). Your brain is given the card that attacked them. The method should return a card from your hand
# File lib/kevins_propietary_brain.rb, line 23 def target_of_bang(card, targetter, missed_needed) if player.hand.count{ |x| x.type == Card.missed_card } >= missed_needed player.hand.select{|x| x.type == Card.missed_card}.first(missed_needed) else [] end end
# File lib/kevins_propietary_brain.rb, line 33 def target_of_duel(card, targetter) player.from_hand(Card.bang_card) end
# File lib/kevins_propietary_brain.rb, line 30 def target_of_indians(card, targetter) player.from_hand(Card.bang_card) end