summaryrefslogtreecommitdiffstats
path: root/lib/colonial_twilight/player.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/colonial_twilight/player.rb')
-rw-r--r--lib/colonial_twilight/player.rb80
1 files changed, 74 insertions, 6 deletions
diff --git a/lib/colonial_twilight/player.rb b/lib/colonial_twilight/player.rb
index 16e0b04..bc91cd1 100644
--- a/lib/colonial_twilight/player.rb
+++ b/lib/colonial_twilight/player.rb
@@ -9,17 +9,85 @@ module ColonialTwilight
def initialize game, faction
@game = game
+ @board = game.board
+ @ui = game.ui
@faction = faction
+ @debug = game.options.debug_bot
+ @possible_actions = nil
end
- def to_s
- @faction.to_s
+ def _init
+ @card = @game.current_card
+ @operation = nil
+ @operation_count = 0
+ @special_activity = nil
+ @special_activity_count = 0
+
+ @selected_spaces = []
+ @expended_resources = 0
+ end
+
+ def conducted_action
+ a = nil
+ if not @card.nil?
+ raise "Operation #{@operation} conducted with event" if not @operation.nil?
+ raise "Special Activity #{@special_activity} conducted with event" if not @special_activity.nil?
+ a = :event
+ elsif not @special_activity.nil?
+ a = :ope_special
+ else
+ if @operation_count == 0
+ a = :pass
+ elsif @operation_count == 1
+ a = :ope_limited
+ else
+ a = :ope_only
+ end
+ end
+ raise "#{a} has been conducted but is not allowed" if not @possible_actions.include? a
+ puts "Conducted action is : #{a}" if @debug
+ a
+ end
+
+ private
+
+ def first_eligible?
+ @game.actions.size == 0
+ # @possible_actions.length == 5
+ end
+
+ def may_play_event?
+ not @card.nil? and @possible_actions.include? :event
+ end
+
+ def limited_ope_only?
+ (@possible_actions.size == 2 and @possible_actions.include? :ope_limited)
+ end
+
+ def limited_ope_done?
+ limited_ope_only? and @operation_count == 1
+ end
+
+ def may_conduct_special_activity? sp
+ r = @possible_actions.include? :ope_special
+ r &= (sp == @special_activity) if not @special_activity.nil?
+ r
+ end
+
+ def operation_done ope
+ raise "try to conduct ope #{ope} over #{@operation}" if not (@operation.nil? or @operation == ope)
+ raise "cannot conduct another" if @operation_count > 0 and limited_ope_only?
+ @card = nil
+ @operation = ope
+ @operation_count += 1
end
- def play possible_actions
- action = @game.ui.chose( 'Choose an action', possible_actions.values) { |s| a = s.split(':'); a[0] = a[0].yellow; a.join(':') }
- puts 'Player.play' # FIXME
- return action
+ def special_activity_done sp
+ raise "try to conduct special activity #{sp} over #{@special_activity}" if not (@special_activity.nil? or @special_activity == sp)
+ raise "cannot conduct a special activity" if not may_conduct_special_activity? sp
+ @card = nil
+ @special_activity = sp
+ @special_activity_count += 1
end
end