summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2024-03-20 14:24:42 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2024-03-20 14:24:42 +0100
commit4fe34a024c77df99b263f6b97c43f9870a9d3160 (patch)
treec2d7d09afe7303c739484dce324967bf6368aa82 /lib
parentad77e25eec96122f94fc6ae2db258c1aea984980 (diff)
downloadcolonial-twilight-4fe34a024c77df99b263f6b97c43f9870a9d3160.zip
colonial-twilight-4fe34a024c77df99b263f6b97c43f9870a9d3160.tar.gz
some rubocop cleanup
Diffstat (limited to 'lib')
-rw-r--r--lib/colonial_twilight.rb11
-rw-r--r--lib/colonial_twilight/board.rb4
-rw-r--r--lib/colonial_twilight/card_attributes.rb2
-rw-r--r--lib/colonial_twilight/cli.rb89
-rw-r--r--lib/colonial_twilight/colorized_string.rb3
-rw-r--r--lib/colonial_twilight/deck.rb3
-rw-r--r--lib/colonial_twilight/fln_bot_rules.rb4
-rw-r--r--lib/colonial_twilight/game.rb4
-rw-r--r--lib/colonial_twilight/gov_player.rb9
-rw-r--r--lib/colonial_twilight/spaces.rb3
10 files changed, 70 insertions, 62 deletions
diff --git a/lib/colonial_twilight.rb b/lib/colonial_twilight.rb
index 5785241..a975f05 100644
--- a/lib/colonial_twilight.rb
+++ b/lib/colonial_twilight.rb
@@ -1,10 +1,9 @@
#! /usr/bin/env ruby
-# -*- coding: UTF-8 -*-
+# frozen_string_literal: true
module ColonialTwilight
- MAJOR = 0
- MINOR = 1
- REVISION = 0
- VERSION = [MAJOR,MINOR,REVISION].join '.'
+ MAJOR = 0
+ MINOR = 1
+ REVISION = 0
+ VERSION = [MAJOR, MINOR, REVISION].join '.'
end
-
diff --git a/lib/colonial_twilight/board.rb b/lib/colonial_twilight/board.rb
index 78b3c76..c999c87 100644
--- a/lib/colonial_twilight/board.rb
+++ b/lib/colonial_twilight/board.rb
@@ -6,7 +6,9 @@ require 'colonial_twilight/spaces'
module ColonialTwilight
class Board
FRANCE_TRACK = %w[A B C D E F].freeze
- TRACKS = %i[support_commitment opposition_bases fln_resources gov_resources commitment france_track border_zone_track].freeze
+
+ TRACKS = %i[support_commitment opposition_bases fln_resources
+ gov_resources commitment france_track border_zone_track].freeze
attr_reader :spaces
diff --git a/lib/colonial_twilight/card_attributes.rb b/lib/colonial_twilight/card_attributes.rb
index bf339d8..08bb1ee 100644
--- a/lib/colonial_twilight/card_attributes.rb
+++ b/lib/colonial_twilight/card_attributes.rb
@@ -1,8 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: true
-# rubocop:disable Style/Documentation
-
module ColonialTwilight
module CardAttributes
MAX_CARD_NUM = 71
diff --git a/lib/colonial_twilight/cli.rb b/lib/colonial_twilight/cli.rb
index 8618508..ede551d 100644
--- a/lib/colonial_twilight/cli.rb
+++ b/lib/colonial_twilight/cli.rb
@@ -1,9 +1,8 @@
#! /usr/bin/env ruby
-# -*- coding: UTF-8 -*-
+# frozen_string_literal: true
-require 'colonial_twilight'
+require 'io/console'
require 'colonial_twilight/colorized_string'
-require 'colonial_twilight/game'
module ColonialTwilight
@@ -23,44 +22,59 @@ module ColonialTwilight
class Cli
- FRANCE_TRACK=[' A ',' B ',' C ',' D ',' E ',' F '].map {|e| e.white.on_blue}.freeze
+module ColonialTwilight
+ class Cli
+ LOGO = ' ____ _ _ _ _____ _ _ _ _ _ '"\n" \
+ ' / ___|___ | | ___ _ __ (_) __ _| | |_ _|_ _(_) (_) __ _| |__ | |_ '"\n" \
+ '| | / _ \| |/ _ \| \_ `| |/ _` | | | | \ \ /\ / / | | |/ _` | \_ `| __| '"\n" \
+ '| |__| (_) | | (_) | | | | | (_| | | | | \ V V /| | | | (_| | | | | |_ '"\n" \
+ ' \____\___/|_|\___/|_| |_|_|\__,_|_| |_| \_/\_/ |_|_|_|\__, |_| |_|\__| '"\n" \
+ ' |___/ '
+ FRANCE_TRACK = [' A ', ' B ', ' C ', ' D ', ' E ', ' F '].map { |e| e.white.on_blue }.freeze
TRACK = {
- :support_commitment => ' Support & Commitment '.white.on_blue,
- :opposition_bases => ' FLN bases & Opposition '.black.on_green
- }
+ gov_score: ' Support & Commitment '.blue.on_black,
+ gov_resources: ' Resources '.blue.on_black,
+ fln_score: ' FLN bases & Opposition '.green.on_black,
+ fln_resources: ' Resources '.green.on_black
+ }.freeze
FACTION = {
- :FLN => ' FLN '.black.on_green,
- :GOV => ' Government '.white.on_blue
+ FLN: ' FLN '.black.on_green,
+ GOV: ' Government '.white.on_blue
}.freeze
CONTROL = {
- :FLN => ' FLN '.black.on_green,
- :GOV => ' Government '.white.on_blue,
- :uncontrolled => ' Uncontrolled '.black.on_light_white
+ FLN: ' FLN '.black.on_green,
+ GOV: ' Government '.white.on_blue,
+ uncontrolled: ' Uncontrolled '.black.on_light_white
}.freeze
ALIGNMENT = {
- :oppose => ' Oppose '.black.on_green,
- :support => ' Support '.white.on_blue,
- :neutral => ' Neutral '.black.on_light_white
+ oppose: ' Oppose '.black.on_green,
+ support: ' Support '.white.on_blue,
+ neutral: ' Neutral '.black.on_light_white
}.freeze
BOXES = {
- :available => 'Available'.cyan,
- :out_of_play => 'Out Of Play'.cyan,
- :casualties => 'Casualties'.cyan,
- :france_track => 'France Track'.white.on_blue,
- :border_track => 'Border Track'.yellow.on_black,
+ available: 'Available'.cyan,
+ out_of_play: 'Out Of Play'.cyan,
+ casualties: 'Casualties'.cyan,
+ france_track: 'France Track'.white.on_blue,
+ border_track: 'Border Track'.yellow.on_black
}.freeze
FORCES = {
- :fln_active=>'Active Guerrillas'.red.on_black,
- :fln_underground=>'Underground Guerrillas'.green.on_black,
- :fln_base=>'FLN Base'.white.on_black,
- :french_troops=>'French Troops'.on_blue,
- :french_police=>'French Police'.black.on_light_blue,
- :gov_base=>'Government Base'.on_blue,
- :algerian_troops=>'Algerian Troops'.black.on_green,
- :algerian_police=>'Algerian Police'.black.on_light_green
+ fln_active: 'Active Guerrillas'.red.on_black,
+ fln_underground: 'Underground Guerrillas'.green.on_black,
+ fln_base: 'FLN Base'.white.on_black,
+ french_troops: 'French Troops'.on_blue,
+ french_police: 'French Police'.black.on_light_blue,
+ gov_base: 'Government Base'.on_blue,
+ algerian_troops: 'Algerian Troops'.black.on_green,
+ algerian_police: 'Algerian Police'.black.on_light_green
+ }.freeze
+ MARKERS = {
+ terror: 'Terror Marker'.yellow,
+ control: 'Control'.yellow,
+ alignment: 'Alignment'.yellow
}.freeze
- def initialize options
+ def initialize(options)
@options = options
@game = ColonialTwilight::Game.new options
end
@@ -91,11 +105,11 @@ module ColonialTwilight
puts String::CLS
end
- def turn_start turn, first, second
+ def turn_start(turn, first, second)
clear_screen if @options.clearscreen
puts
- puts ("=" * 80).white.bold.on_light_green
- puts " Turn : #{turn.to_s.red} ".black.on_white + "\t 1st Eligible : ".black.on_white + FACTION[first.faction]
+ puts ('=' * 80).white.bold.on_light_green
+ puts " Turn : #{turn.to} ".black.on_white << "\t 1st Eligible : ".black.on_white << FACTION[first.faction]
puts "\t\t 2nd Eligible : ".black.on_white + FACTION[second.faction]
end
@@ -266,14 +280,15 @@ module ColonialTwilight
def ask prompt, default=nil
puts
c = (default.nil? ? 'y/n' : (default ? 'Y/n' : 'y/N'))
- printf " => #{prompt.yellow} (#{c}) ? "
- while true
- ret = gets.chomp.downcase
+ print " => #{prompt.yellow} (#{c}) ? "
+ loop do
+ ret = gets.chomp.strip.downcase
return true if YES.include? ret
return false if NO.include? ret
- return default if not default.nil?
+ return default unless default.nil?
+
puts "\t\t\t\t'#{ret}' is not valid, (y/n) ?"
- printf "\t$ "
+ print "\t$ "
end
end
diff --git a/lib/colonial_twilight/colorized_string.rb b/lib/colonial_twilight/colorized_string.rb
index 2a63852..65f2623 100644
--- a/lib/colonial_twilight/colorized_string.rb
+++ b/lib/colonial_twilight/colorized_string.rb
@@ -93,7 +93,8 @@ class String
def resolve(key, var)
return self.class.color_codes[var] + 30 if key == :fg
return self.class.color_codes[var] + 40 if key == :bg
- return self.class.color_modes[var] if key == :mode
+
+ self.class.color_modes[var] if key == :mode
end
end
diff --git a/lib/colonial_twilight/deck.rb b/lib/colonial_twilight/deck.rb
index 8c58bf2..bca1135 100644
--- a/lib/colonial_twilight/deck.rb
+++ b/lib/colonial_twilight/deck.rb
@@ -1,9 +1,8 @@
#! /usr/bin/env ruby
# frozen_string_literal: true
-# rubocop:disable Style/Documentation
-
require 'colonial_twilight/card_attributes'
+
module ColonialTwilight
class Card
include ColonialTwilight::CardAttributes
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb
index 578cd49..3716a34 100644
--- a/lib/colonial_twilight/fln_bot_rules.rb
+++ b/lib/colonial_twilight/fln_bot_rules.rb
@@ -37,7 +37,7 @@ module ColonialTwilight
def rally1?(board = @board)
# rally would place a base (rally 1 or 2)
- r = board.available_fln_bases.positive? && board.has { |s| (may_rally_1_in?(s) || may_rally_2_in?(s)) }
+ r = board.available_fln_bases.positive? && board.has { |s| may_rally_1_in?(s) || may_rally_2_in?(s) }
dbg 'RALLY 1', r
r
end
@@ -102,7 +102,7 @@ module ColonialTwilight
if r
# may agitate if : FLN base or control after rally
n = already_rallied ? 0 : place_guerrillas_in(space).values.sum
- r &= (space.fln_bases.positive? || (space.gov < (space.fln + n)))
+ r &= space.fln_bases.positive? || (space.gov < (space.fln + n))
end
dbg " may_rally_6_in : #{space.name}", r
r
diff --git a/lib/colonial_twilight/game.rb b/lib/colonial_twilight/game.rb
index 33a30d7..a53ef7c 100644
--- a/lib/colonial_twilight/game.rb
+++ b/lib/colonial_twilight/game.rb
@@ -1,5 +1,5 @@
#! /usr/bin/env ruby
-# -*- coding: UTF-8 -*-
+# frozen_string_literal: true
require 'json'
@@ -10,7 +10,6 @@ require 'colonial_twilight/fln_bot'
require 'colonial_twilight/gov_player'
module ColonialTwilight
-
class Game
MAX_CARD = 71
@@ -168,5 +167,4 @@ module ColonialTwilight
name.to_json args
end
end
-
end
diff --git a/lib/colonial_twilight/gov_player.rb b/lib/colonial_twilight/gov_player.rb
index 3821b8c..180ddc6 100644
--- a/lib/colonial_twilight/gov_player.rb
+++ b/lib/colonial_twilight/gov_player.rb
@@ -1,11 +1,8 @@
#! /usr/bin/env ruby
-# -*- coding: UTF-8 -*-
module ColonialTwilight
-
class GOVPlayer < Player
-
- def play possible_actions
+ def play(possible_actions)
@possible_actions = possible_actions
_init
_start
@@ -14,10 +11,8 @@ module ColonialTwilight
private
def _start
- puts "FIXME"
+ puts 'FIXME'
exit 1
end
-
end
-
end
diff --git a/lib/colonial_twilight/spaces.rb b/lib/colonial_twilight/spaces.rb
index 83d9082..5c04250 100644
--- a/lib/colonial_twilight/spaces.rb
+++ b/lib/colonial_twilight/spaces.rb
@@ -15,6 +15,7 @@ module ColonialTwilight
def shift(val)
@v += val
raise "out of track #{@v}" if @v.negative? || @v > @max
+
@v
end
@@ -147,7 +148,7 @@ module ColonialTwilight
end
def shift_terror(num = 1)
- raise "terror cant be negative" if @terror.zero? and num.negative?
+ raise 'terror cant be negative' if @terror.zero? && num.negative?
@terror += num
end