philosophers_studio_game_revamped 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 91fff9d28255b5cf32c9b6056f3f4d2e8b223542
4
+ data.tar.gz: 350d6b051f08141ef4e0d7890041df6943a81b0d
5
+ SHA512:
6
+ metadata.gz: 55c4315ebc29cf657f027223b8f3185d2ea3d81d53d7c91867e29d36b6d6021d6161047b8b82fd1174b908513517bf1e39b2e6a7817d2e09bb89a8ccba6e2dee
7
+ data.tar.gz: 389cb4f638f4178e22aa2a252690f12e8c11f02b75618b8946eb4c93d6fcbcc6aa1da5be3983291909a888df8f814f5ecd5bcea8828137253d561047bfdb471f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012 The Pragmatic Studio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ - You may not use this Software in other training contexts.
11
+
12
+ - The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,15 @@
1
+ This is an example application used in The Pragmatic Studio's
2
+ Ruby Programming course, as described at
3
+
4
+ http://pragmaticstudio.com
5
+
6
+ Philosophers compete for the highest score through philosophical discovery (treasures are philosophical epiphanies).
7
+
8
+ New features: Philosophers who loose all their health will “fall” and can no longer acquire points (“blams” are -20 health and “w00ts” are + 15 health).
9
+
10
+ Philosophers who acquire 8 berserker knowledge points will be subsequently w00ted an additional two times per turn for the rest of the game.
11
+
12
+ Philosophers who engage in sloppy thinking will lose 100 points.
13
+
14
+ This code is Copyright 2012 The Pragmatic Studio. See the LICENSE file.
15
+
@@ -0,0 +1,3 @@
1
+ Sartre,100
2
+ Camus,95
3
+ Heidegger,110
@@ -0,0 +1,6 @@
1
+ Socrates,100
2
+ Aristotle,130
3
+ Descartes, 110
4
+ Leibniz,90
5
+ Hume,90
6
+ Kant,120
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/studio_game/philosopher'
4
+ require_relative '../lib/studio_game/game'
5
+ require_relative '../lib/studio_game/sloppy_philosopher'
6
+ require_relative '../lib/studio_game/berserk_player'
7
+
8
+ module StudioGame
9
+ #player1 = Philosopher.new("socrates")
10
+ #player2 = Philosopher.new("aristotle", 130)
11
+ #player3 = Philosopher.new("descartes", 110)
12
+ #player4 = Philosopher.new("leibniz", 90)
13
+ #player5 = Philosopher.new("hume", 90)
14
+ #player6 = Philosopher.new("kant")
15
+ #player7 = Philosopher.new("sartre")
16
+ klutz = SloppyPhilosopher.new("Klutz", 205)
17
+ berserker = BerserkPlayer.new("berserker", 60)
18
+
19
+ curmudgeons = StudioGame::Game.new("curmudgeons")
20
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
21
+ curmudgeons.load_players (ARGV.shift || default_player_file)
22
+ curmudgeons.add_player(klutz)
23
+ curmudgeons.add_player(berserker)
24
+
25
+ loop do
26
+ puts "\nHow many game rounds? ('quit' to exit)"
27
+ answer = gets.chomp.downcase
28
+ case answer
29
+ when /^\d+$/
30
+ curmudgeons.play(answer.to_i)
31
+ when 'quit', 'exit'
32
+ curmudgeons.print_stats
33
+ break
34
+ else
35
+ puts "Please enter a number or 'quit'"
36
+ end
37
+ end
38
+
39
+ curmudgeons.save_high_scores
40
+
41
+ #curmudgeons.play(25) do
42
+ #curmudgeons.total_points >= 10000
43
+ #end
44
+
45
+
46
+ #great_philosophers = Game.new("great_philosophers")
47
+ #great_philosophers.add_player(player1)
48
+ #great_philosophers.add_player(player2)
49
+ #great_philosophers.add_player(player3)
50
+ #great_philosophers.play(1)
51
+ #great_philosophers.print_stats
52
+ end
53
+
54
+
@@ -0,0 +1,64 @@
1
+ require_relative 'epiphany_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Philosopher
6
+ include Playable
7
+
8
+ attr_accessor :health
9
+ attr_accessor :name
10
+
11
+ def initialize(name, health=100)
12
+ @name = name.capitalize
13
+ @health = health
14
+ @discovered_epiphanies = Hash.new(0)
15
+ end
16
+
17
+ def self.from_csv(string)
18
+ name, health = string.split(',')
19
+ Philosopher.new(name, Integer(health))
20
+ end
21
+
22
+ def name=(new_name)
23
+ @name = new_name.capitalize
24
+ end
25
+
26
+ def to_s
27
+ "\nI'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
28
+ end
29
+
30
+ def discovered_epiphanies(epiphany)
31
+ @discovered_epiphanies[epiphany.name] += epiphany.points
32
+ puts "#{@name} discovered #{epiphany.name} for #{epiphany.points} points."
33
+ puts "#{@name}'s discoveries: #{@discovered_epiphanies}"
34
+ end
35
+
36
+ def each_discovered_epiphany
37
+ @discovered_epiphanies.each do |name, points|
38
+ yield Epiphany.new(name, points)
39
+ end
40
+ end
41
+
42
+ def points
43
+ @discovered_epiphanies.values.reduce(0, :+)
44
+ end
45
+
46
+ def score
47
+ points + @health
48
+ end
49
+
50
+ def <=>(other)
51
+ other.score <=> score
52
+ end
53
+ end
54
+
55
+ if __FILE__ == $0
56
+ player = Philosopher.new("camus")
57
+ puts player.name
58
+ puts player.health
59
+ player.w00t
60
+ puts player.health
61
+ player.blam
62
+ puts player.health
63
+ end
64
+ end
@@ -0,0 +1,9 @@
1
+ require_relative 'die'
2
+
3
+ module StudioGame
4
+ module Auditable
5
+ def audit
6
+ puts "\nRolled a #{self.number} (#{self.class})"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'philosopher'
2
+
3
+ module StudioGame
4
+ class BerserkPlayer < Philosopher
5
+ def initialize(name, health=100)
6
+ super(name, health)
7
+ @w00t_count = 0
8
+ end
9
+
10
+ def berserk?
11
+ @w00t_count > 5
12
+ end
13
+
14
+ def w00t
15
+ super
16
+ @w00t_count += 1
17
+ puts "#{@name} has gone berserk!" if berserk?
18
+ end
19
+
20
+ def blam
21
+ berserk? ? w00t : super
22
+ end
23
+ end
24
+
25
+ if __FILE__ == $0
26
+ berserker = BerserkPlayer.new("berserker", 60)
27
+ 6.times { berserker.w00t }
28
+ 2.times {berserker.blam }
29
+ puts berserker.health
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class Die
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ @number = rand(1..6)
11
+ audit
12
+ @number
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module StudioGame
2
+ Epiphany = Struct.new(:name, :points)
3
+ end
4
+
5
+ module StudioGame
6
+ module EpiphanyTrove
7
+ EPIPHANIES = [
8
+ Epiphany.new(:sloppy_thinking, -100),
9
+ Epiphany.new(:berserker_knowledge, 2),
10
+ Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5),
11
+ Epiphany.new(:the_problem_of_the_one_and_the_many, 20),
12
+ Epiphany.new(:logic, 30),
13
+ Epiphany.new(:an_indubitable_truth, 50),
14
+ Epiphany.new(:the_authentic_self, 80),
15
+ Epiphany.new(:a_monad, 100),
16
+ Epiphany.new(:why_something_exists_rather_than_nothing, 150),
17
+ Epiphany.new(:the_problem_of_induction, 200),
18
+ Epiphany.new(:the_distinction_between_the_noumena_and_the_phenomena, 400)
19
+ ]
20
+
21
+ def self.random
22
+ EPIPHANIES.sample
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,126 @@
1
+ require_relative 'philosopher'
2
+ require_relative 'die'
3
+ require_relative 'game_turn'
4
+ require_relative 'epiphany_trove'
5
+ require_relative 'berserk_player'
6
+ require_relative 'sloppy_philosopher'
7
+
8
+ module StudioGame
9
+ class Game
10
+ attr_reader :title
11
+
12
+ def initialize(title)
13
+ @title = title.capitalize
14
+ @philosophers = []
15
+ end
16
+
17
+ def load_players(from_file)
18
+ File.readlines(from_file).each do |line|
19
+ add_player(Philosopher.from_csv(line))
20
+ end
21
+ end
22
+
23
+ def add_player(player)
24
+ @philosophers << (player)
25
+ end
26
+
27
+ def play(rounds)
28
+ puts "There are #{@philosophers.size} players in #{@title}:"
29
+
30
+ @philosophers.each do |player|
31
+ puts player
32
+ end
33
+
34
+ epiphanies = EpiphanyTrove::EPIPHANIES
35
+
36
+ puts "\nThere are #{epiphanies.size} discoveries to be made:"
37
+ epiphanies.each do |epiphany|
38
+ puts "Discovering #{epiphany.name} is worth #{epiphany.points} points"
39
+ end
40
+
41
+ 1.upto(rounds) do |round|
42
+ if block_given?
43
+ break if yield
44
+ end
45
+ puts "\nRound #{round}:"
46
+ @philosophers.each do |player|
47
+ if player.alive?
48
+ GameTurn.take_turn(player)
49
+ case
50
+ when player.berserk?
51
+ 2.times {player.w00t}
52
+ puts "#{player.name} has gone berserk!"
53
+ #puts player
54
+ when player.alive?
55
+ puts player
56
+ else puts "\n#{player.name.upcase} has fallen!"
57
+ end
58
+ else puts "\n#{player.name} can no longer acquire points."
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def print_name_and_health(player)
65
+ puts "#{player.name} (#{player.health})"
66
+ end
67
+
68
+ def print_stats
69
+ puts "\n#{@title} Statistics:"
70
+
71
+ strong_players, weak_players = @philosophers.partition { |player| player.strong? }
72
+
73
+ puts "\n#{strong_players.size} strong players:"
74
+ strong_players.each do |player|
75
+ print_name_and_health(player)
76
+ end
77
+
78
+ puts "\n#{weak_players.size} weak players:"
79
+ weak_players.each do |player|
80
+ print_name_and_health(player)
81
+ end
82
+
83
+ @philosophers.each do |player|
84
+ puts "\n#{player.name}'s point totals:"
85
+ player.each_discovered_epiphany do |epiphany|
86
+ puts "#{epiphany.points} total points from discovering #{epiphany.name}"
87
+ end
88
+
89
+ puts "#{player.points} grand total points"
90
+ end
91
+
92
+ puts "#{total_points} total points from philosophical discoveries"
93
+
94
+ puts "\n#{@title} High Scores:"
95
+ @philosophers.sort.each do |player|
96
+ puts high_score_entry(player)
97
+ end
98
+ end
99
+
100
+ def total_points
101
+ @philosophers.reduce(0) { |sum, player| sum + player.points }
102
+ end
103
+
104
+ def high_score_entry(player)
105
+ formatted_name = player.name.ljust(20, '.')
106
+ "#{formatted_name} #{player.score}"
107
+ end
108
+
109
+ def save_high_scores(to_file="high_scores.txt")
110
+ File.open(to_file, "w") do |file|
111
+ file.puts "#{@title} High Scores:"
112
+ @philosophers.sort.each do |player|
113
+ file.puts high_score_entry(player)
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ if __FILE__ == $0
120
+ great_philosophers = Game.new("great_philosophers")
121
+ player1 = Philosopher.new("moe")
122
+ great_philosophers.add_player(player1)
123
+ great_philosophers.play(3)
124
+ great_philosophers.print_stats
125
+ end
126
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'philosopher'
2
+ require_relative 'die'
3
+ require_relative 'epiphany_trove'
4
+ require_relative 'loaded_die'
5
+
6
+ module StudioGame
7
+ module GameTurn
8
+ def self.take_turn(player)
9
+ die = Die.new
10
+ case die.roll
11
+ when 1..2
12
+ player.blam
13
+ when 3..4
14
+ puts "\n#{player.name} was skipped."
15
+ else
16
+ player.w00t
17
+ end
18
+
19
+ epiphany = EpiphanyTrove.random
20
+ player.discovered_epiphanies(epiphany)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class LoadedDie
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ numbers = [1, 1, 2, 5, 6, 6]
11
+ @number = numbers.sample
12
+ audit
13
+ @number
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ module StudioGame
2
+ module Playable
3
+ def blam
4
+ self.health -= 20
5
+ puts "\n#{name} got blammed!"
6
+ end
7
+
8
+ def w00t
9
+ self.health += 15
10
+ puts "\n#{name} got w00ted!"
11
+ end
12
+
13
+ def strong?
14
+ @health > 100
15
+ end
16
+
17
+ def weak?
18
+ @health <= 100
19
+ end
20
+
21
+ def alive?
22
+ @health > 0
23
+ end
24
+
25
+ def berserk?
26
+ @discovered_epiphanies[:berserker_knowledge] >= 8
27
+ end
28
+
29
+ def sloppy_thinking?
30
+ @discovered_epiphanies[:sloppy_thinking] == -5
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'philosopher'
2
+
3
+ module StudioGame
4
+ class SloppyPhilosopher < Philosopher
5
+ def initialize(name, health=100)
6
+ super(name, health)
7
+ @w00t_count = 0
8
+ end
9
+
10
+ def discovered_epiphanies(epiphany)
11
+ sloppy_thinking = Epiphany.new(epiphany.name, epiphany.points / 2.0)
12
+ super(sloppy_thinking)
13
+ end
14
+
15
+ def bonus_w00ts?
16
+ @w00t_count % 3 == 0
17
+ end
18
+
19
+ def w00t
20
+ super
21
+ @w00t_count += 1
22
+ 2.times { w00t } if bonus_w00ts?
23
+ end
24
+ end
25
+
26
+ if __FILE__ == $0
27
+ clumsy = SloppyPhilosopher.new("klutz", 205)
28
+
29
+ an_indubitable_truth = Epiphany.new(:an_indubitable_truth, 50)
30
+ clumsy.discovered_epiphanies(an_indubitable_truth)
31
+ clumsy.discovered_epiphanies(an_indubitable_truth)
32
+ clumsy.discovered_epiphanies(an_indubitable_truth)
33
+
34
+ the_problem_of_induction = Epiphany.new(:the_problem_of_induction, 200)
35
+ clumsy.discovered_epiphanies(the_problem_of_induction)
36
+
37
+ clumsy.each_discovered_epiphany do |epiphany|
38
+ puts "#{epiphany.points} total points from discovering #{epiphany.name}"
39
+ end
40
+ puts "#{clumsy.points} grand total points"
41
+
42
+ puts clumsy.health
43
+ 3.times { clumsy.w00t }
44
+ puts clumsy.health
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require 'studio_game/berserk_player'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module StudioGame
5
+ describe BerserkPlayer do
6
+
7
+ before do
8
+ @initial_health = 60
9
+ @player = BerserkPlayer.new("berserker", @initial_health)
10
+ $stdout = StringIO.new
11
+ end
12
+
13
+ it "does not go berserk when w00ted up to 5 times" do
14
+ 1.upto(5) { @player.w00t }
15
+
16
+ @player.berserk?.should be_falsey
17
+
18
+ # or if using Rspec 3.0:
19
+ # @player.berserk?.should be_falsey
20
+ end
21
+
22
+ it "goes berserk when w00ted more than 5 times" do
23
+ 1.upto(6) { @player.w00t }
24
+
25
+ @player.berserk?.should be_truthy
26
+
27
+ # or if using Rspec 3.0:
28
+ # @player.berserk?.should be_truthy
29
+ end
30
+
31
+ it "gets w00ted instead of blammed when it's gone berserk" do
32
+ 1.upto(6) { @player.w00t }
33
+ 1.upto(2) { @player.blam }
34
+
35
+ @player.health.should == @initial_health + (8 * 15)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,78 @@
1
+ require 'studio_game/epiphany_trove'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module StudioGame
5
+ describe Epiphany do
6
+
7
+ before do
8
+ @epiphany = Epiphany.new(:that_thinking_necessitates_existing, 50)
9
+ end
10
+
11
+ it "has a name attribute" do
12
+ @epiphany.name.should == :that_thinking_necessitates_existing
13
+ end
14
+
15
+ it "has a points attribute" do
16
+ @epiphany.points.should == 50
17
+ end
18
+
19
+ end
20
+
21
+ describe EpiphanyTrove do
22
+
23
+ it "has eleven epiphanies" do
24
+ EpiphanyTrove::EPIPHANIES.size.should == 11
25
+ end
26
+
27
+ it "has an epiphany worth -100 points" do
28
+ EpiphanyTrove::EPIPHANIES[0].should == Epiphany.new(:sloppy_thinking, -100)
29
+ end
30
+
31
+ it "has an epiphany worth 2 points" do
32
+ EpiphanyTrove::EPIPHANIES[1].should == Epiphany.new(:berserker_knowledge, 2)
33
+ end
34
+
35
+ it "has an epiphany worth 5 points" do
36
+ EpiphanyTrove::EPIPHANIES[2].should == Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5)
37
+ end
38
+
39
+ it "has an epiphany worth 25 points" do
40
+ EpiphanyTrove::EPIPHANIES[3].should == Epiphany.new(:the_problem_of_the_one_and_the_many, 20)
41
+ end
42
+
43
+ it "has an epiphany worth 25 points" do
44
+ EpiphanyTrove::EPIPHANIES[4].should == Epiphany.new(:logic, 30)
45
+ end
46
+
47
+ it "has an epiphany worth 50 points" do
48
+ EpiphanyTrove::EPIPHANIES[5].should == Epiphany.new(:an_indubitable_truth, 50)
49
+ end
50
+
51
+ it "has an epiphany worth 80 points" do
52
+ EpiphanyTrove::EPIPHANIES[6].should == Epiphany.new(:the_authentic_self, 80)
53
+ end
54
+
55
+ it "has an epiphany worth 100 points" do
56
+ EpiphanyTrove::EPIPHANIES[7].should == Epiphany.new(:a_monad, 100)
57
+ end
58
+
59
+ it "has an epiphany worth 150 points" do
60
+ EpiphanyTrove::EPIPHANIES[8].should == Epiphany.new(:why_something_exists_rather_than_nothing, 150)
61
+ end
62
+
63
+ it "has an epiphany worth 200 points" do
64
+ EpiphanyTrove::EPIPHANIES[9].should == Epiphany.new(:the_problem_of_induction, 200)
65
+ end
66
+
67
+ it "has an epiphany worth 400 points" do
68
+ EpiphanyTrove::EPIPHANIES[10].should == Epiphany.new(:the_distinction_between_the_noumena_and_the_phenomena, 400)
69
+ end
70
+
71
+ it "returns a random treasure" do
72
+ epiphany = EpiphanyTrove.random
73
+
74
+ EpiphanyTrove::EPIPHANIES.should include(epiphany)
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,73 @@
1
+ require 'studio_game/game'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module StudioGame
5
+ describe Game do
6
+
7
+ before do
8
+ @game = Game.new("Curmudgeons")
9
+
10
+ @initial_health = 100
11
+ @player = Philosopher.new("camus", @initial_health)
12
+
13
+ @game.add_player(@player)
14
+ $stdout = StringIO.new
15
+
16
+ @rounds = 3
17
+ end
18
+
19
+ it "w00ts a player if a high number is rolled" do
20
+ Die.any_instance.stub(:roll).and_return(5)
21
+
22
+ @game.play(@rounds)
23
+
24
+ @player.health.should == @initial_health + (15 * @rounds)
25
+ end
26
+
27
+ it "skips a player if a medium number is rolled" do
28
+ Die.any_instance.stub(:roll).and_return(3)
29
+
30
+ @game.play(@rounds)
31
+
32
+ @player.health.should == @initial_health
33
+ end
34
+
35
+ it "blams a player if a low number is rolled" do
36
+ Die.any_instance.stub(:roll).and_return(1)
37
+
38
+ @game.play(@rounds)
39
+
40
+ @player.health.should == @initial_health - (20 * @rounds)
41
+ end
42
+
43
+ it "assigns an epiphany for points during a player's turn" do
44
+ game = Game.new("the_great_philosophers")
45
+ player = Philosopher.new("camus")
46
+
47
+ game.add_player(player)
48
+
49
+ game.play(1)
50
+
51
+ player.points.should_not be_zero
52
+
53
+ # or use alternate expectation syntax:
54
+ # expect(player.points).not_to be_zero
55
+ end
56
+
57
+ it "computes total points as the sum of all player points" do
58
+ game = Game.new("the_great_philosophers")
59
+
60
+ player1 = Philosopher.new("camus")
61
+ player2 = Philosopher.new("sartre")
62
+
63
+ game.add_player(player1)
64
+ game.add_player(player2)
65
+
66
+ player1.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
67
+ player1.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
68
+ player2.discovered_epiphanies(Epiphany.new(:the_problem_of_induction, 200))
69
+
70
+ game.total_points.should == 300
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,136 @@
1
+ require 'studio_game/philosopher'
2
+ require 'studio_game/spec_helper'
3
+ require 'studio_game/epiphany_trove'
4
+
5
+ module StudioGame
6
+ describe Philosopher do
7
+ before do
8
+ @initial_health = 150
9
+ @player = Philosopher.new("camus", @initial_health)
10
+ $stdout = StringIO.new
11
+ end
12
+
13
+ it "can be created from a CSV string" do
14
+ player = Philosopher.from_csv("Camus,150")
15
+
16
+ player.name.should == "Camus"
17
+ player.health.should == 150
18
+ end
19
+
20
+ it "has a capitalized name" do
21
+ @player.name.should == "Camus"
22
+ end
23
+
24
+ it "has an initial health" do
25
+ @player.health.should == 150
26
+ end
27
+
28
+ it "has a string representation" do
29
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
30
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
31
+
32
+ @player.to_s.should == "\nI'm Camus with health = 150, points = 100, and score = 250."
33
+ end
34
+
35
+ it "computes a score as the sum of its health and points" do
36
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
37
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
38
+
39
+ @player.score.should == 250
40
+ end
41
+
42
+ it "increases health by 15 when w00ted" do
43
+ @player.w00t
44
+
45
+ @player.health.should == (@initial_health + 15)
46
+ end
47
+
48
+ it "decreases health by 20 when blammed" do
49
+ @player.blam
50
+
51
+ @player.health.should == (@initial_health - 20)
52
+ end
53
+
54
+ context "with a health greater than 100" do
55
+ before do
56
+ @player = Philosopher.new("camus", 150)
57
+ end
58
+
59
+ it "is strong" do
60
+ @player.should be_strong
61
+ end
62
+ end
63
+
64
+ it "computes points as the sum of all epiphany points" do
65
+ @player.points.should == 0
66
+
67
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
68
+
69
+ @player.points.should == 50
70
+
71
+ @player.discovered_epiphanies(Epiphany.new(:the_problem_of_induction, 200))
72
+
73
+ @player.points.should == 250
74
+
75
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
76
+
77
+ @player.points.should == 300
78
+ end
79
+
80
+ it "yields each discovered epiphany and its total points" do
81
+ @player.discovered_epiphanies(Epiphany.new(:a_monad, 100))
82
+ @player.discovered_epiphanies(Epiphany.new(:a_monad, 100))
83
+ @player.discovered_epiphanies(Epiphany.new(:an_indubitable_truth, 50))
84
+ @player.discovered_epiphanies(Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5))
85
+ @player.discovered_epiphanies(Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5))
86
+ @player.discovered_epiphanies(Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5))
87
+ @player.discovered_epiphanies(Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5))
88
+ @player.discovered_epiphanies(Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 5))
89
+
90
+ yielded = []
91
+ @player.each_discovered_epiphany do |epiphany|
92
+ yielded << epiphany
93
+ end
94
+
95
+ yielded.should == [
96
+ Epiphany.new(:a_monad, 200),
97
+ Epiphany.new(:an_indubitable_truth, 50),
98
+ Epiphany.new(:that_the_unexamined_life_is_not_worth_living, 25)
99
+ ]
100
+ end
101
+
102
+ context "with a health less than 100" do
103
+ before do
104
+ @player = Philosopher.new("camus", 100)
105
+ end
106
+
107
+ it "is weak" do
108
+ @player.should be_weak
109
+ end
110
+ end
111
+
112
+ context "with a health greater than 0" do
113
+ before do
114
+ @player = Philosopher.new("camus", 100)
115
+ end
116
+
117
+ it "is alive" do
118
+ @player.should be_alive
119
+ end
120
+ end
121
+
122
+ context "in a collection of players" do
123
+ before do
124
+ @player1 = Philosopher.new("moe", 100)
125
+ @player2 = Philosopher.new("larry", 200)
126
+ @player3 = Philosopher.new("curly", 300)
127
+
128
+ @players = [@player1, @player2, @player3]
129
+ end
130
+
131
+ it "is sorted by decreasing score" do
132
+ @players.sort.should == [@player3, @player2, @player1]
133
+ end
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,50 @@
1
+ require 'studio_game/sloppy_philosopher'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module StudioGame
5
+ describe SloppyPhilosopher do
6
+ before do
7
+ @player = SloppyPhilosopher.new("klutz")
8
+ $stdout = StringIO.new
9
+ end
10
+
11
+ it "only gets half the point value for each treasure" do
12
+ @player.points.should == 0
13
+
14
+ an_indubitable_truth = Epiphany.new(:an_indubitable_truth, 50)
15
+ @player.discovered_epiphanies(an_indubitable_truth)
16
+ @player.discovered_epiphanies(an_indubitable_truth)
17
+ @player.discovered_epiphanies(an_indubitable_truth)
18
+
19
+ @player.points.should == 75
20
+
21
+ the_problem_of_induction = Epiphany.new(:the_problem_of_induction, 200)
22
+ @player.discovered_epiphanies(the_problem_of_induction)
23
+
24
+ @player.points.should == 175
25
+
26
+ yielded = []
27
+
28
+ @player.each_discovered_epiphany do |epiphany|
29
+ yielded << epiphany
30
+ end
31
+
32
+ yielded.should == [Epiphany.new(:an_indubitable_truth, 75), Epiphany.new(:the_problem_of_induction, 100)]
33
+ end
34
+
35
+ context "it gets wooted extra times" do
36
+ before do
37
+ @initial_health = 200
38
+ @player = SloppyPhilosopher.new("klutz", @initial_health)
39
+ end
40
+
41
+ it "gets wooted 2 extra times every three times it is w00ted" do
42
+ 3.times { @player.w00t }
43
+
44
+ @player.health.should == @initial_health + (15 * 5)
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+
@@ -0,0 +1,10 @@
1
+ module StudioGame
2
+ RSpec.configure do |config|
3
+ config.expect_with :rspec do |c|
4
+ c.syntax = [:should, :expect]
5
+ end
6
+ config.mock_with :rspec do |c|
7
+ c.syntax = [:should, :expect]
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: philosophers_studio_game_revamped
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Charles Ellison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: "This is an example application used in The Pragmatic Studio's \nRuby
28
+ Programming course, as described at\n\n http://pragmaticstudio.com\n\nPhilosophers
29
+ compete for the highest score through philosophical discovery (treasures are philosophical
30
+ epiphanies).\n\nNew features: Philosophers who loose all their health will “fall”
31
+ and can no longer acquire points (“blams” are -20 health and “w00ts” are + 15 health).\n\nPhilosophers
32
+ who acquire 8 berserker knowledge points will be subsequently w00ted an additional
33
+ two times per turn for the rest of the game.\n\nPhilosophers who engage in sloppy
34
+ thinking will lose 100 points.\n\nThis code is Copyright 2012 The Pragmatic Studio.
35
+ See the LICENSE file.\n\n"
36
+ email: chad.ellison0123@gmail.com
37
+ executables:
38
+ - studio_game
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - LICENSE
43
+ - README
44
+ - bin/existentialists.csv
45
+ - bin/players.csv
46
+ - bin/studio_game
47
+ - lib/studio_game/Philosopher.rb
48
+ - lib/studio_game/auditable.rb
49
+ - lib/studio_game/berserk_player.rb
50
+ - lib/studio_game/die.rb
51
+ - lib/studio_game/epiphany_trove.rb
52
+ - lib/studio_game/game.rb
53
+ - lib/studio_game/game_turn.rb
54
+ - lib/studio_game/loaded_die.rb
55
+ - lib/studio_game/playable.rb
56
+ - lib/studio_game/sloppy_philosopher.rb
57
+ - spec/studio_game/berserk_player_spec.rb
58
+ - spec/studio_game/epiphany_trove_spec.rb
59
+ - spec/studio_game/game_spec.rb
60
+ - spec/studio_game/philosopher_spec.rb
61
+ - spec/studio_game/sloppy_philosopher_spec.rb
62
+ - spec/studio_game/spec_helper.rb
63
+ homepage: http://pragmaticstudio.com
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: philosophers compete for the highest score through philosophical discoveries
87
+ test_files:
88
+ - spec/studio_game/berserk_player_spec.rb
89
+ - spec/studio_game/epiphany_trove_spec.rb
90
+ - spec/studio_game/game_spec.rb
91
+ - spec/studio_game/philosopher_spec.rb
92
+ - spec/studio_game/sloppy_philosopher_spec.rb
93
+ - spec/studio_game/spec_helper.rb