were_wolf 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/were_wolf/game.rb +19 -3
- data/lib/were_wolf/game_suggestor.rb +2 -1
- data/lib/were_wolf/player/doctor.rb +3 -0
- data/lib/were_wolf/player/player_collection.rb +10 -0
- data/lib/were_wolf/player/witch.rb +40 -0
- data/lib/were_wolf/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a63c18b5139dcf4282bbc79aa18bd08df03b654d
|
4
|
+
data.tar.gz: 6ff720629a4862574e3e68f92d151e5f26e2b2f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea4e4bc2cc2102a967d9445f8db83aa330f8023b983bb6ce845c896b44352710f40265139b0ed09da282ebc5f375372a1af096a67252adc709c94ac7a347f5f2
|
7
|
+
data.tar.gz: 6b9370e4d9f1c1d7ac869639ed7cb4bf26f274e6e6f3db0d2618f53c221e2c6db6b4a0a7eca634376fbc8318df1b030c9f3ab4f189ed49889874aba48533de47
|
data/lib/were_wolf/game.rb
CHANGED
@@ -31,9 +31,14 @@ private
|
|
31
31
|
# Cop identifies a person
|
32
32
|
cop = @players.cop
|
33
33
|
cop.identify_a_player(@players) if cop
|
34
|
+
saved_people = []
|
34
35
|
# Doctor chooses to save a person
|
35
36
|
doctor = @players.doctor
|
36
|
-
|
37
|
+
saved_people.push(doctor.choose_a_player_to_save(@players)) if doctor
|
38
|
+
# Witch chooses to save a person once in the entire game
|
39
|
+
witch = @players.witch
|
40
|
+
person_saved_by_witch = witch.choose_a_player_to_save(@players) if witch
|
41
|
+
saved_people.push(person_saved_by_witch) if witch && person_saved_by_witch
|
37
42
|
# Wolves kill a villager
|
38
43
|
wolves_victim = villagers_alive.sample
|
39
44
|
# Rogue kills a players once in the entire game
|
@@ -41,12 +46,23 @@ private
|
|
41
46
|
rogues_victim = rogue.choose_victim(@players) if rogue
|
42
47
|
|
43
48
|
# Don't kill the person if the doctor saved the person
|
44
|
-
@players.kill(wolves_victim) unless wolves_victim
|
49
|
+
@players.kill(wolves_victim) unless saved_people.include?(wolves_victim)
|
45
50
|
# Don't kill the person again, if the wolves have already killed the person
|
46
|
-
@players.kill(rogues_victim) unless (rogues_victim
|
51
|
+
@players.kill(rogues_victim) unless (saved_people.include?(rogues_victim)) || (rogues_victim == wolves_victim)
|
47
52
|
end
|
48
53
|
|
49
54
|
def day_mode
|
55
|
+
# Witch can kill a player once in the entire game
|
56
|
+
witch = @players.witch
|
57
|
+
if witch
|
58
|
+
witchs_victim = witch.choose_a_player_to_kill(@players)
|
59
|
+
if witchs_victim
|
60
|
+
@players.kill(witchs_victim) if witchs_victim
|
61
|
+
return if over?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Run voting to kick out a player
|
50
66
|
victim = run_voting
|
51
67
|
if victim == DRAW
|
52
68
|
@draw = true
|
@@ -34,7 +34,8 @@ private
|
|
34
34
|
players['cops'] = 1
|
35
35
|
players['doctors'] = 1 if @players_count - wolves_count > 1
|
36
36
|
players['rogues'] = 1 if @players_count - wolves_count > 2
|
37
|
-
players['
|
37
|
+
players['witches'] = 1 if @players_count - wolves_count > 3
|
38
|
+
players['villagers'] = (@players_count - wolves_count - 4) if @players_count - wolves_count > 4
|
38
39
|
|
39
40
|
probabilities = {}
|
40
41
|
probabilities['wolves_win'] = (100.0*(best_wins[Game::WOLF] || 0)/@no_of_runs)
|
@@ -1,5 +1,8 @@
|
|
1
1
|
class Doctor < Villager
|
2
2
|
def choose_a_player_to_save(players)
|
3
|
+
# Save myself when ther eare only 2 players,a s the other player
|
4
|
+
# should be a wolf
|
5
|
+
return self if players.alive_players.count == 2
|
3
6
|
# Assumption: Doctor saves him/her self 50% of the times
|
4
7
|
if rand < 0.5
|
5
8
|
return self
|
@@ -3,6 +3,7 @@ require_relative 'villager'
|
|
3
3
|
require_relative 'cop'
|
4
4
|
require_relative 'doctor'
|
5
5
|
require_relative 'rogue'
|
6
|
+
require_relative 'witch'
|
6
7
|
|
7
8
|
class PlayerCollection
|
8
9
|
def initialize(no_of_wolves, no_of_villagers)
|
@@ -25,6 +26,9 @@ class PlayerCollection
|
|
25
26
|
elsif i == 3
|
26
27
|
villager = Rogue.new
|
27
28
|
@rogue = villager
|
29
|
+
elsif i == 4
|
30
|
+
villager = Witch.new
|
31
|
+
@witch = villager
|
28
32
|
else
|
29
33
|
villager = Villager.new
|
30
34
|
end
|
@@ -51,7 +55,9 @@ class PlayerCollection
|
|
51
55
|
promote_rogue_to_wolf
|
52
56
|
else
|
53
57
|
@cop = nil if player.is_a?(Cop)
|
58
|
+
@doctor = nil if player.is_a?(Doctor)
|
54
59
|
@rogue = nil if player.is_a?(Rogue)
|
60
|
+
@witch = nil if player.is_a?(Witch)
|
55
61
|
collection = @villagers
|
56
62
|
end
|
57
63
|
collection.delete(player)
|
@@ -71,6 +77,10 @@ class PlayerCollection
|
|
71
77
|
@rogue
|
72
78
|
end
|
73
79
|
|
80
|
+
def witch
|
81
|
+
@witch
|
82
|
+
end
|
83
|
+
|
74
84
|
private
|
75
85
|
def promote_rogue_to_wolf
|
76
86
|
return if @wolves.count > 0
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Witch < Doctor
|
2
|
+
def initialize
|
3
|
+
super
|
4
|
+
@save_power_used = false
|
5
|
+
@kill_power_used = false
|
6
|
+
end
|
7
|
+
|
8
|
+
def choose_a_player_to_save(players)
|
9
|
+
return if @save_power_used
|
10
|
+
|
11
|
+
if choose_to_use_power?(players)
|
12
|
+
# Choose a person to save
|
13
|
+
@save_power_used = true
|
14
|
+
return super(players)
|
15
|
+
else
|
16
|
+
# Save the save power for a later round
|
17
|
+
return nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def choose_a_player_to_kill(players)
|
22
|
+
return if @kill_power_used
|
23
|
+
|
24
|
+
if choose_to_use_power?(players)
|
25
|
+
@kill_power_used = true
|
26
|
+
return (players.alive_players - [self]).sample
|
27
|
+
else
|
28
|
+
return
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def choose_to_use_power?(players)
|
34
|
+
# Always use the power if there is only one another player in the game,
|
35
|
+
# as the other player should be a wolf
|
36
|
+
return true if players.alive_players.count == 2
|
37
|
+
|
38
|
+
rand < (1.0/(players.alive_wolves.count + 1))
|
39
|
+
end
|
40
|
+
end
|
data/lib/were_wolf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: were_wolf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BV Satyaram
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/were_wolf/player/player_collection.rb
|
63
63
|
- lib/were_wolf/player/rogue.rb
|
64
64
|
- lib/were_wolf/player/villager.rb
|
65
|
+
- lib/were_wolf/player/witch.rb
|
65
66
|
- lib/were_wolf/player/wolf.rb
|
66
67
|
- lib/were_wolf/version.rb
|
67
68
|
- were_wolf.gemspec
|