Class: Doctor
- Defined in:
- lib/were_wolf/player/doctor.rb
Direct Known Subclasses
Instance Method Summary collapse
- #accuse(players) ⇒ Object
- #choose_a_player_to_save(players) ⇒ Object
- #forget_all! ⇒ Object
-
#initialize ⇒ Doctor
constructor
A new instance of Doctor.
- #remember_innocent(player) ⇒ Object
Constructor Details
#initialize ⇒ Doctor
Returns a new instance of Doctor.
2 3 4 5 |
# File 'lib/were_wolf/player/doctor.rb', line 2 def initialize super forget_all! end |
Instance Method Details
#accuse(players) ⇒ Object
23 24 25 26 27 |
# File 'lib/were_wolf/player/doctor.rb', line 23 def accuse(players) forget_all! if players.alive_players.count == @known_innocents.count + 1 return (players.alive_players - [self] - @known_innocents).sample end |
#choose_a_player_to_save(players) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/were_wolf/player/doctor.rb', line 7 def choose_a_player_to_save(players) # Save myself when ther eare only 2 players,a s the other player # should be a wolf return self if players.alive_players.count == 2 # Assumption: Doctor saves him/her self 50% of the times if rand < 0.5 return self else return players.alive_players.sample end end |
#forget_all! ⇒ Object
29 30 31 |
# File 'lib/were_wolf/player/doctor.rb', line 29 def forget_all! @known_innocents = [] end |
#remember_innocent(player) ⇒ Object
19 20 21 |
# File 'lib/were_wolf/player/doctor.rb', line 19 def remember_innocent(player) @known_innocents.push(player) end |