Skip to content

Commit

Permalink
Update gems, fix rubocop offenses, fix CODECOV_TOKEN
Browse files Browse the repository at this point in the history
  • Loading branch information
pioz committed Aug 28, 2024
1 parent 9425fc3 commit 15b0f02
Show file tree
Hide file tree
Showing 22 changed files with 151 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Run tests
run: bundle exec rake test
env:
CODECOV: true
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# - name: Upload coverage report to Codecov
# uses: codecov/codecov-action@v1
# with:
Expand All @@ -45,7 +45,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2', '3.3']

steps:
- uses: actions/checkout@v2
Expand Down
12 changes: 12 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@ source 'http://rubygems.org'

# Specify your gem's dependencies in chess.gemspec
gemspec

gem 'bundler'
gem 'codecov'
gem 'debug'
gem 'minitest'
gem 'rake'
gem 'rubocop'
gem 'rubocop-minitest'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'simplecov'
gem 'yard', '>= 0.9.20'
90 changes: 55 additions & 35 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,71 +1,91 @@
PATH
remote: .
specs:
chess (0.3.4)
chess (0.3.5)

GEM
remote: http://rubygems.org/
specs:
ast (2.4.2)
byebug (11.1.3)
codecov (0.6.0)
simplecov (>= 0.15, < 0.22)
docile (1.4.0)
json (2.6.2)
minitest (5.16.2)
parallel (1.22.1)
parser (3.1.2.0)
debug (1.9.2)
irb (~> 1.10)
reline (>= 0.3.8)
docile (1.4.1)
io-console (0.7.2)
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.25.1)
parallel (1.26.3)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
psych (5.1.2)
stringio
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.5.0)
rexml (3.2.5)
rubocop (1.31.2)
rake (13.2.1)
rdoc (6.7.0)
psych (>= 4.0.0)
regexp_parser (2.9.2)
reline (0.5.9)
io-console (~> 0.5)
rexml (3.3.6)
strscan
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.19.1)
parser (>= 3.1.1.0)
rubocop-minitest (0.20.1)
rubocop (>= 0.90, < 2.0)
rubocop-performance (1.14.2)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.1)
parser (>= 3.3.1.0)
rubocop-minitest (0.35.1)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.21.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
unicode-display_width (2.2.0)
yard (0.9.35)
stringio (3.1.1)
strscan (3.1.0)
unicode-display_width (2.5.0)
yard (0.9.36)

PLATFORMS
ruby
x86_64-darwin-18
x86_64-darwin-19

DEPENDENCIES
bundler (~> 2)
byebug (~> 11)
bundler
chess!
codecov (~> 0)
minitest (~> 5)
rake (~> 13)
rubocop (~> 1)
rubocop-minitest (~> 0)
rubocop-performance (~> 1)
rubocop-rake (~> 0)
simplecov (~> 0)
codecov
debug
minitest
rake
rubocop
rubocop-minitest
rubocop-performance
rubocop-rake
simplecov
yard (>= 0.9.20)

BUNDLED WITH
Expand Down
11 changes: 0 additions & 11 deletions chess.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,4 @@ Gem::Specification.new do |s|
s.metadata['rubygems_mfa_required'] = 'true'

s.required_ruby_version = '>= 2.5'
s.add_development_dependency 'bundler', '~> 2'
s.add_development_dependency 'byebug', '~> 11'
s.add_development_dependency 'codecov', '~> 0'
s.add_development_dependency 'minitest', '~> 5'
s.add_development_dependency 'rake', '~> 13'
s.add_development_dependency 'rubocop', '~> 1'
s.add_development_dependency 'rubocop-minitest', '~> 0'
s.add_development_dependency 'rubocop-performance', '~> 1'
s.add_development_dependency 'rubocop-rake', '~> 0'
s.add_development_dependency 'simplecov', '~> 0'
s.add_development_dependency 'yard', '>= 0.9.20'
end
22 changes: 15 additions & 7 deletions lib/chess/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,8 @@ def expand_move(notation)
expand[:from] = match[2] if match[2] && match[2].size == 2

# Support UCI protocol (Lichess)
if expand[:from] == 'e1' && self.board['e1'] == 'K'
expand[:to] = 'g1' if expand[:to] == 'h1' # UCI protocol (Lichess) white king short castling
expand[:to] = 'c1' if expand[:to] == 'a1' # UCI protocol (Lichess) white king long castling
elsif expand[:from] == 'e8' && self.board['e8'] == 'k'
expand[:to] = 'g8' if expand[:to] == 'h8' # UCI protocol (Lichess) black king short castling
expand[:to] = 'c8' if expand[:to] == 'a8' # UCI protocol (Lichess) black king long castling
end
uci_to_coord = uci_castling_to_coord(expand[:from], expand[:to])
expand[:to] = uci_to_coord if uci_to_coord

return expand
end
Expand All @@ -180,6 +175,19 @@ def expand_move(notation)

raise BadNotationError.new(notation)
end

# Support Castling notation valid in UCI (Universal Chess Interface)
# protocol (Lichess)
def uci_castling_to_coord(from, to)
if from == 'e1' && self.board['e1'] == 'K'
return 'g1' if to == 'h1' # UCI protocol (Lichess) white king short castling
return 'c1' if to == 'a1' # UCI protocol (Lichess) white king long castling
elsif from == 'e8' && self.board['e8'] == 'k'
return 'g8' if to == 'h8' # UCI protocol (Lichess) black king short castling
return 'c8' if to == 'a8' # UCI protocol (Lichess) black king long castling
end
return nil
end
end

MOVE_REGEXP = /^([RNBQK])?([a-h]|[1-8]|[a-h][1-8])?(?:x)?([a-h][1-8])(?:=?([RrNnBbQq]))?(?:ep)?(?:\+|\#)?$/.freeze
Expand Down
3 changes: 2 additions & 1 deletion lib/chess/gnuchess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def gen_pgn(file_to_save, moves = [])
until done
pipe.write("go\n")
while (line = pipe.gets)
break if /My move is : /.match?(line) || / : resign/.match?(line)
break if line.include?('My move is : ')
break if line.include?(' : resign')

if / : 1-0 {White mates}/.match?(line)
done = :white_won
Expand Down
4 changes: 2 additions & 2 deletions lib/chess/pgn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def load(filename, check_moves: false)
def load_from_string(str, check_moves: false)
str.gsub!(/\{.*?\}/, '') # remove comments
TAGS.each do |t|
instance_variable_set("@#{t}", str.match(/^\[#{t.capitalize} ".*"\]\s?$/).to_s.strip[t.size + 3..-3])
instance_variable_set(:"@#{t}", str.match(/^\[#{t.capitalize} ".*"\]\s?$/).to_s.strip[t.size + 3..-3])
end
@result = '1/2-1/2' if @result == '1/2'
game_index = str.index(/^1\./)
Expand All @@ -82,7 +82,7 @@ def load_from_string(str, check_moves: false)
def to_s
s = ''
TAGS.each do |t|
tag = instance_variable_defined?("@#{t}") ? instance_variable_get("@#{t}") : ''
tag = instance_variable_defined?(:"@#{t}") ? instance_variable_get(:"@#{t}") : ''
s << "[#{t.capitalize} \"#{tag}\"]\n"
end
s << "\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/chess/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# The Chess library module.
module Chess
# The library version.
VERSION = '0.3.4'.freeze
VERSION = '0.3.5'.freeze
end
2 changes: 1 addition & 1 deletion test/test_big_pgn_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ChessTest < Minitest::Test
path = File.join(TestHelper::BIG_PGN_COLLECTION, filename)
break unless File.exist?(path)

define_method "test_big_pgn_#{filename}" do
define_method :"test_big_pgn_#{filename}" do
pgn = Chess::Pgn.new(path)
game = Chess::Game.new(pgn.moves)
assert(game.checkmate?) if pgn.moves.last.match?(/\#$/)
Expand Down
4 changes: 3 additions & 1 deletion test/test_checkmate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ class ChessTest < Minitest::Test
TestHelper.pgns('checkmate').each do |file|
name = File.basename(file, '.pgn')
win = file.include?('white') ? 'white' : 'black'
define_method "test_#{win}_checkmate_#{name}" do

define_method :"test_#{win}_checkmate_#{name}" do
pgn = Chess::Pgn.new(file)
game = Chess::Game.new(pgn.moves)

assert(game.board.checkmate?)
if file.include?('white_won')
assert_equal('1-0', game.result)
Expand Down
4 changes: 3 additions & 1 deletion test/test_fifty_rule_move.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
class ChessTest < Minitest::Test
TestHelper.pgns('fifty_move_rule').each do |file|
name = File.basename(file, '.pgn')
define_method "test_fifty_move_rule_#{name}" do

define_method :"test_fifty_move_rule_#{name}" do
pgn = Chess::Pgn.new(file)
game = Chess::Game.new(pgn.moves)

assert game.board.fifty_move_rule?
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/test_game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ class ChessTest < Minitest::Test
def test_moves
game = Chess::Game.new
game.moves = %w[e4 e5]

assert_equal %w[e4 e5], game.moves
end

def test_active_player
game = Chess::Game.new
game << 'a3'

assert_equal :black, game.active_player
end

def test_inactive_player
game = Chess::Game.new
game.moves = %w[a3 f5]

assert_equal :black, game.inactive_player
end

def test_status_white_won_resign
game = Chess::Game.new
game.resign(:black)

assert_equal :white_won_resign, game.status
assert game.over?
assert_equal '1-0', game.result
Expand All @@ -31,6 +35,7 @@ def test_status_black_won_resign
game = Chess::Game.new
game << 'e4'
game.resign(:white)

assert_equal :black_won_resign, game.status
assert game.over?
assert_equal '0-1', game.result
Expand All @@ -39,26 +44,30 @@ def test_status_black_won_resign
def test_status_insufficient_material
pgn = TestHelper.pick_pgn('insufficient_material/0001.pgn')
game = Chess::Game.new(pgn.moves)

assert_equal :insufficient_material, game.status
end

def test_status_fifty_move_rule
pgn = TestHelper.pick_pgn('fifty_move_rule/0001.pgn')
game = Chess::Game.new(pgn.moves)
game.draw

assert_equal :fifty_move_rule, game.status
end

def test_status_threefold_repetition
pgn = TestHelper.pick_pgn('threefold_repetition/0001.pgn')
game = Chess::Game.new(pgn.moves)
game.draw

assert_equal :threefold_repetition, game.status
end

def test_pgn
pgn = TestHelper.pick_pgn('valid/0001.pgn')
game = Chess::Game.new(pgn.moves)

expected_pgn = <<~PGN
[Event ""]
[Site ""]
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
SimpleCov.start do
add_filter 'lib/chess/gnuchess.rb'
end
if ENV['CODECOV'] == 'true'
if ENV['CODECOV_TOKEN'].present?
require 'codecov'
SimpleCov.formatter = SimpleCov::Formatter::Codecov
end

require 'chess'
require 'debug'
require 'minitest/autorun'
require 'byebug'

module TestHelper
PGN_COLLECTION = 'test/pgn_collection'.freeze
Expand Down
1 change: 1 addition & 0 deletions test/test_illegal_moves.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
class ChessTest < Minitest::Test
def test_illegal_moves
game = Chess::Game.new

%w[Qf6 Rd4 Nc3=Q].each do |move|
assert_raises(Chess::IllegalMoveError) do
game << move
Expand Down
Loading

0 comments on commit 15b0f02

Please sign in to comment.