Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use attacked_players to determine who is susceptible to an attack

  • Loading branch information...
commit 77c07717ae0eea04ed7654859de4d32b37b22561 1 parent 3889cfd
Carter Thaxton authored
Showing with 21 additions and 23 deletions.
  1. +9 −11 README.md
  2. +8 −8 lib/cards.rb
  3. +4 −0 lib/game.rb
  4. +0 −4 lib/player.rb
20 README.md
View
@@ -180,16 +180,16 @@ Examples:
- PlayerB has a Watchtower in hand, and a Lighthouse in play
- When the Witch is played, before executing it, go through the other players, and ask to reveal any reactions
- Don't bother asking about the Moat if attack_prevented is true (in this case because of Lighthouse, but it might be because Moat was already played. This extra rule just makes reactions less annoying)
-- In the DSL, 'player.gain Curse, :attack => true' is called
-- There are four possible outcomes here:
- 1. Supply pile contains no Curses, no attack
- 2. reacts_to? :attack, Lighthouse available, PlayerB plays Lighthouse, attack is unsuccessful.
- 3. reacts_to? :attack, Lighthouse available, PlayerB does not play Lighthouse, reacts_to? :gain, Watchtower available, PlayerB plays Watchtower, Curse is trashed
- 4. reacts_to? :attack, Lighthouse available, PlayerB does not play Lighthouse, reacts_to? :gain, Watchtower available, PlayerB does not play Watchtower, Curse is gained by PlayerB from supply
+- There are five possible outcomes here:
+ 1. PlayerB previously played Lighthouse, attack is unsuccessful, Curse stays in supply
+ 2. PlayerB didn't play Lighthouse, PlayerB reveals Watchtower and chooses trash, Curse is trashed
+ 3. PlayerB didn't play Lighthouse, PlayerB reveals Watchtower and chooses deck, Curse is gained to deck
+ 4. PlayerB didn't play Lighthouse, PlayerB doesn't reveal Watchtower, Curse is gained to discard
+ 5. Curse supply pile is empty - attack may still occur (so other reactions may still apply), but no Curse is gained
-Note that 2 and 3 are different, because a Curse is trashed in 3, but left in the supply in 2.
-I have no idea how I'm going to program a computer to make this choice intelligently. :)
+Note that 1 and 2 are different, because a Curse is trashed in 2, but left in the supply in 1.
+If Moat and Watchtower are both in hand, you can choose which to reveal first. I have no idea how I'm going to program a computer to make this choice intelligently. :)
Inversion of Control
@@ -209,7 +209,5 @@ call stack.
Players need a proxy, so human vs simulator can be easily plugged in. Every time the player has to make
a choice, it can call out to the proxy.
-Addendum: I found a simple way to handle this. Just use blocks in the card code.
-If we really need to stash the call stack, we'll save the block as a variable in the game, and keep some state
-like waiting_for_response? or whatever.
+Addendum: I found a better way to handle this. Use fibers in the player strategy, so that the rest of the code uses straight up synchronous calling style. Keeps it much cleaner.
16 lib/cards.rb
View
@@ -158,8 +158,8 @@ class Bureaucrat < Card
def on_play
gain Silver, :to => :deck
- other_players.each do |player|
- card = player.reveal :type => :victory, :attack => true
+ attacked_players.each do |player|
+ card = player.reveal :type => :victory
player.put card, :to => :deck if card
end
end
@@ -270,8 +270,8 @@ class Witch < Card
cards 2
def on_play
- other_players.each do |player|
- player.gain Curse, :attack => true
+ attacked_players.each do |player|
+ player.gain Curse
end
end
end
@@ -598,8 +598,8 @@ class Familiar < Card
actions 1
def on_play
- other_players.each do |player|
- player.gain Curse, :attack => true
+ attacked_players.each do |player|
+ player.gain Curse
end
end
end
@@ -702,8 +702,8 @@ class Mountebank < Card
coins 2
def on_play
- other_players.each do |player|
- curse = player.reveal :type => Curse, :attack => true
+ attacked_players.each do |player|
+ curse = player.reveal :type => Curse
if curse
player.discard curse
else
4 lib/game.rb
View
@@ -97,6 +97,10 @@ def num_players
def other_players
@players.reject { |p| p == current_player }
end
+
+ def attacked_players
+ other_players.reject { |p| p.attack_prevented }
+ end
def player_to_left
player_to_left_of current_player
4 lib/player.rb
View
@@ -223,8 +223,6 @@ def discard_hand
end
def gain(card_class, options = {})
- return nil if options[:attack] && attack_prevented
-
to = options.fetch :to, :discard
card = draw_from_supply(card_class, self)
if card
@@ -337,8 +335,6 @@ def choose(options)
end
def reveal(options = {})
- return nil if options[:attack] && attack_prevented
-
type = options[:type]
card = find_card_in_hand(type)
if card
Please sign in to comment.
Something went wrong with that request. Please try again.