1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
require 'colonial_twilight/board'
require 'colonial_twilight/cards'
require 'colonial_twilight/player'
require 'colonial_twilight/fln_bot'
module ColonialTwilight
class Game
@scenarios = ['Short: 1960-1962: The End Game',
'Medium: 1957-1962: Midgame Development',
'Full: 1955-1962: Algérie Francaise!'].freeze
@rules = ['Standard Rules - No Support Phase in final Propaganda round',
'Optional Rule 8.5.1 - Conduct Support Phase in final Propaganda round'].freeze
@actions = {
:event => 'Event: execute the Event card',
:ope_special => 'Operation & Special Activity: conduct an Operation in any number of spaces with a Special Activity',
:ope_only => 'Operation Only: conduct an Operation in any number of spaces without a Special Activity',
:ope_limited => 'Limited Operation: conduct an Operation in 1 space without a Special Activity',
:pass => 'Pass: increase your Resources'
}.freeze
@swap_actions= [:ope_special, :ope_limited]
class << self
attr_reader :scenarios, :rules, :actions, :cards
end
def rules; Game.rules end
def scenarios; Game.scenarios end
def possible_actions used=nil
ks = Game.actions.keys
if not used.nil?
if used == :event
ks.delete :event
ks.delete :ope_only
ks.delete :ope_limited
elsif used == :ope_special
ks.delete :ope_special
ks.delete :ope_only
elsif used == :ope_limited
ks.delete :ope_limited
ks.delete :event
elsif used == :ope_only
ks.delete :ope_only
ks.delete :event
ks.delete :ope_special
end
end
Game.actions.select { |k,v| ks.include? k }
end
attr_reader :options, :scenario, :ruleset, :board, :ui, :cards, :actions
def initialize options
@options = options
@board = ColonialTwilight::Board.new
@deck = ColonialTwilight::Deck.new
end
def start ui, s, rs
@ui = ui
@ruleset = rs
@scenario = s
@board.load [:short, :medium, :long][s]
@max_card = 71
@turn = 1
@cards = []
@actions = []
@players = [FLNBot.new(self, :FLN), Player.new(self, :GOV)]
play
end
def play
while true
ui.turn_start @turn, *@players
c = ui.pull_card @max_card
c = 1 # FIXME
@cards << @deck.pull(c)
ui.show_card @cards[-1]
ui.continue? @players[0].instance_of? FLNBot
ui.player @players[0], true
@actions[0] = @players[0].play @cards[-1], 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]
@ui.adjust_track @board.compute_victory_points
@cards.shift if @cards.length > 2
@turn += 1
if eligibility_swap?
@players[0], @players[1] = @players[1], @players[0]
end
@actions.clear
end
end
def eligibility_swap?
Game.swap_actions.include? @actions[0]
end
end
end
|