Class: GreenPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/prisoners-dilemma/players/green.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGreenPlayer

Returns a new instance of GreenPlayer.



4
5
6
# File 'lib/prisoners-dilemma/players/green.rb', line 4

def initialize
  @log = []
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



2
3
4
# File 'lib/prisoners-dilemma/players/green.rb', line 2

def log
  @log
end

Instance Method Details

#cooperate?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'lib/prisoners-dilemma/players/green.rb', line 8

def cooperate?
  if @log.empty? # 1st round
    true
  else
    @log.last[0] ? true : false
  end
end