diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-09-02 16:17:56 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-09-02 16:17:56 +0200 |
commit | 314b20c23a1362eef24efc6f80c7005ec24e878d (patch) | |
tree | 7ac4ffcc70b30fcadf0f2378f2f4abc1d316ce22 | |
parent | f5b0433c59d772ba8cf6470a38c60279491e53c0 (diff) | |
download | colonial-twilight-314b20c23a1362eef24efc6f80c7005ec24e878d.zip colonial-twilight-314b20c23a1362eef24efc6f80c7005ec24e878d.tar.gz |
get ready for GOVPlayer
-rw-r--r-- | lib/colonial_twilight/fln_bot.rb | 91 | ||||
-rw-r--r-- | lib/colonial_twilight/game.rb | 9 | ||||
-rw-r--r-- | lib/colonial_twilight/gov_player.rb | 23 | ||||
-rw-r--r-- | lib/colonial_twilight/player.rb | 80 |
4 files changed, 105 insertions, 98 deletions
diff --git a/lib/colonial_twilight/fln_bot.rb b/lib/colonial_twilight/fln_bot.rb index 42d3883..ae4536b 100644 --- a/lib/colonial_twilight/fln_bot.rb +++ b/lib/colonial_twilight/fln_bot.rb @@ -3,100 +3,13 @@ module ColonialTwilight - class Player - - attr_reader :faction - - def initialize game, faction - @game = game - @board = game.board - @ui = game.ui - @faction = faction - @debug = game.options.debug_bot - @possible_actions = nil - 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 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 - # Country.independant class FLNBot < Player - def play card, possible_actions - @card = card + def play possible_actions @possible_actions = possible_actions - - @operation = nil - @operation_count = 0 - @special_activity = nil - @special_activity_count = 0 - - @selected_spaces = [] - @expended_resources = 0 - + _init _start end diff --git a/lib/colonial_twilight/game.rb b/lib/colonial_twilight/game.rb index a211b3d..6578eb4 100644 --- a/lib/colonial_twilight/game.rb +++ b/lib/colonial_twilight/game.rb @@ -5,6 +5,7 @@ require 'colonial_twilight/board' require 'colonial_twilight/cards' require 'colonial_twilight/player' require 'colonial_twilight/fln_bot' +require 'colonial_twilight/gov_player' module ColonialTwilight @@ -66,10 +67,12 @@ module ColonialTwilight @turn = 1 @cards = [] @actions = [] - @players = [FLNBot.new(self, :FLN), Player.new(self, :GOV)] + @players = [FLNBot.new(self, :FLN), GOVPlayer.new(self, :GOV)] play end + def current_card; @cards[-1] end + def play while true ui.turn_start @turn, *@players @@ -80,12 +83,12 @@ module ColonialTwilight ui.continue? @players[0].instance_of? FLNBot ui.player @players[0], true - @actions[0] = @players[0].play @cards[-1], possible_actions + @actions[0] = @players[0].play possible_actions @ui.adjust_track @board.compute_victory_points ui.continue? @players[1].instance_of? FLNBot ui.player @players[1], false - @actions[1] = @players[1].play possible_actions @cards[-1], @actions[0] + @actions[1] = @players[1].play possible_actions @actions[0] @ui.adjust_track @board.compute_victory_points @cards.shift if @cards.length > 2 diff --git a/lib/colonial_twilight/gov_player.rb b/lib/colonial_twilight/gov_player.rb new file mode 100644 index 0000000..3821b8c --- /dev/null +++ b/lib/colonial_twilight/gov_player.rb @@ -0,0 +1,23 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- + +module ColonialTwilight + + class GOVPlayer < Player + + def play possible_actions + @possible_actions = possible_actions + _init + _start + end + + private + + def _start + puts "FIXME" + exit 1 + end + + end + +end 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 |