Permalink
Browse files

Add Treasury and Smugglers

  • Loading branch information...
1 parent 29ee883 commit 4004f566de3c7e5dbe6cefbfb986416458f49235 @carter-thaxton committed Aug 18, 2012
Showing with 106 additions and 1 deletion.
  1. +22 −0 lib/cards.rb
  2. +4 −0 lib/game.rb
  3. +22 −1 lib/player.rb
  4. +58 −0 test/test_cards.rb
View
@@ -935,6 +935,16 @@ def on_play
class Smugglers < Card
set :seaside
+ type :action
+ cost 3
+
+ def on_play
+ candidates = player_to_right.cards_gained_last_turn.select {|c| c.cost < 6}.map(&:card_class).uniq
+ if candidates.any?
+ card = choose_card "Choose a card gained by #{player_to_right} last turn", :restrict_to => candidates
+ gain card
+ end
+ end
end
class Warehouse < Card
@@ -1099,6 +1109,18 @@ class Tactician < Card
class Treasury < Card
set :seaside
+ type :action
+ cost 5
+ cards 1
+ actions 1
+ coins 1
+
+ def on_cleanup
+ bought_victory = cards_bought_this_turn.any? &:victory?
+ if !bought_victory && ask("Return Treasury to deck?")
+ put_on_deck self
+ end
+ end
end
class Wharf < Card
View
@@ -108,6 +108,10 @@ def player_to_left_of(player)
players[(player.position + 1) % num_players]
end
+ def player_to_right_of(player)
+ players[(player.position - 1) % num_players]
+ end
+
def all_players_cards
players.each do |player|
(player.cards_in_play + player.hand).each do |card|
View
@@ -16,7 +16,8 @@ class Player
:actions_in_play_from_previous_turn,
:actions_available, :coins_available, :buys_available,
:actions_played, :vp_tokens, :pirate_ship_tokens,
- :turn, :card_in_play
+ :turn, :card_in_play,
+ :cards_bought_this_turn, :cards_gained_this_turn, :cards_gained_last_turn
def initialize(game, position, identity, strategy)
@game = game
@@ -38,6 +39,9 @@ def initialize(game, position, identity, strategy)
@turn = 0
@card_in_play = nil
@attack_prevented = false
+ @cards_bought_this_turn = []
+ @cards_gained_this_turn = []
+ @cards_gained_last_turn = []
end
def prepare(options = {})
@@ -61,6 +65,10 @@ def player_to_left
game.player_to_left_of self
end
+ def player_to_right
+ game.player_to_right_of self
+ end
+
def cards_in_play
actions_in_play + treasures_in_play + actions_in_play_from_previous_turn
end
@@ -88,6 +96,8 @@ def start_turn
@actions_available = 1
@coins_available = 0
@buys_available = 1
+ @cards_bought_this_turn = []
+ @cards_gained_this_turn = []
# Play duration cards again, accounting for Throne Room and King's Court
@actions_in_play_from_previous_turn.each do |card|
@@ -127,11 +137,18 @@ def end_turn
c.played_by = nil
end
+ # Only discard those cards that weren't put somewhere else on cleanup
+ to_discard = to_discard.select {|c| !deck.include?(c) && !trash_pile.include?(c)}
+
@discard_pile += to_discard
@actions_in_play_from_previous_turn = Set.new(actions_to_keep)
@actions_in_play = Set.new
@treasures_in_play = Set.new
+ @cards_gained_last_turn = @cards_gained_this_turn
+ @cards_gained_this_turn = []
+ @cards_bought_this_turn = []
+
@discard_pile += @hand
@hand = []
@@ -353,6 +370,8 @@ def gain(cards_or_classes, options = {})
when :hand
@hand << card
end
+
+ @cards_gained_this_turn << card
end
card
end
@@ -376,6 +395,7 @@ def buy(card_or_class)
@coins_available -= card.cost
@buys_available -= 1
+ @cards_bought_this_turn << card
card
end
@@ -404,6 +424,7 @@ def can_buy(card_class, options = {})
return false
end
+ # pretend for a moment that the card is owned by the player, now ask the card if it can be bought
orig_player = card.player
begin
card.player = self
View
@@ -930,5 +930,63 @@ def test_ghost_ship
assert_card_ownership game
end
+
+ def test_treasury
+ game = Game.new :num_players => 1, :no_cards => true, :kingdom_cards => [Treasury]
+ player = game.current_player
+
+ player.gain [Treasury, Treasury, Treasury], :to => :hand
+ player.gain [Estate, Estate, Estate, Estate, Estate, Gold, Gold, Duchy, Duchy, Duchy, Duchy, Duchy, Duchy], :to => :deck
+ player.play Treasury
+ player.play Treasury
+ player.play Treasury
+
+ player.buy Silver
+ assert player.cards_bought_this_turn.any?(&:treasure?), "#{player} should have bought a treasure this turn"
+ assert !player.cards_bought_this_turn.any?(&:victory?), "#{player} should not have bought a victory this turn"
+
+ player.strategy = respond_with true, false, true
+ player.end_turn
+
+ assert_has_count Treasury, player.hand, 2
+ assert_has_count Treasury, player.discard_pile, 1
+ assert_has_a Silver, player.discard_pile
+
+ player.play Treasury
+ player.play Treasury
+ player.play_all_treasures
+ player.buy Province
+ assert !player.cards_bought_this_turn.any?(&:treasure?), "#{player} should not have bought a treasure this turn"
+ assert player.cards_bought_this_turn.any?(&:victory?), "#{player} should have bought a victory this turn"
+
+ player.end_turn
+ assert_has_no Treasury, player.hand
+
+ assert_card_ownership game
+ end
+
+ def test_smugglers
+ game = Game.new :num_players => 3, :no_cards => true, :kingdom_cards => [Smugglers]
+ p1 = game.players[0]
+ p2 = game.players[1]
+ p3 = game.players[2]
+
+ p1.gain [Silver, Silver], :to => :hand
+ p1.play_all_treasures
+ p1.buy Silver
+
+ assert !p1.cards_gained_last_turn.any? {|c| c.is_a? Silver}, "#{p1} should not have gained a Silver last turn"
+ assert p1.cards_gained_this_turn.any? {|c| c.is_a? Silver}, "#{p1} should have gained a Silver this turn"
+ p1.end_turn
+ assert p1.cards_gained_last_turn.any? {|c| c.is_a? Silver}, "#{p1} should have gained a Silver last turn"
+ assert !p1.cards_gained_this_turn.any? {|c| c.is_a? Silver}, "#{p1} should not have gained a Silver this turn"
+
+ p2.gain Smugglers, :to => :hand
+ p2.play Smugglers, :choice => Silver
+
+ assert_has_a Silver, p2.discard_pile
+
+ assert_card_ownership game
+ end
end

0 comments on commit 4004f56

Please sign in to comment.