bchess 0.1.2 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 370d493302b50f3cd02153f733ab46e43fd27727
4
- data.tar.gz: 0436a659709ec9710be92eaa3f54747f6359eda6
2
+ SHA256:
3
+ metadata.gz: 6ee977b4ad266d30e964e008cce9ac2004295ffe1af8dea97d8f8c2b9810219f
4
+ data.tar.gz: 61ba542136ff29506701d5e1dc4b2048d5b7648192235c5cd6374260ae08839d
5
5
  SHA512:
6
- metadata.gz: d824f7dd402d8c83a327f31ab0d63acd88fd0063277897395a402720fd0f23e2def762d0a182747fae6b36a6818fc67806ed8e63738ac55b1967dd106c4c801f
7
- data.tar.gz: c3758e3249590c239c537fc36f1a3b526e7089067685cc136bdbb3fa5f612a099299151584fe03f3fe33f910b74c72925e0a8a5df123aeadcff3d6faaf4a6f59
6
+ metadata.gz: 5542959193b43cdd80623440f293082c42fe0a1434ad74db240c1c371fdf10cf9b2338a508ebb1e560d0cef4d22994ef1bc7b0ff0a03d7274e861ccd2280c529
7
+ data.tar.gz: ac2616bae4d854b15c003f4938d7a48c66caf4a7c63a37fcad76bf1c52e4bc36ca9c024fb5c7b84b7d0647feb8a717ea26dcf3439c83bac103c0c64dd0099a83
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.6', '2.7', '3.0', '3.1']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rake spec
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+
13
+ JetBrains iDeA config files
14
+ /.idea/
data/Gemfile.lock CHANGED
@@ -1,33 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bchess (0.1.2)
4
+ bchess (0.1.4)
5
+ treetop (~> 1.6, >= 1.6.11)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
- coderay (1.1.2)
10
- diff-lcs (1.3)
11
- method_source (0.9.0)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ method_source (1.0.0)
12
13
  polyglot (0.3.5)
13
- pry (0.11.3)
14
- coderay (~> 1.1.0)
15
- method_source (~> 0.9.0)
16
- rake (10.5.0)
17
- rspec (3.7.0)
18
- rspec-core (~> 3.7.0)
19
- rspec-expectations (~> 3.7.0)
20
- rspec-mocks (~> 3.7.0)
21
- rspec-core (3.7.1)
22
- rspec-support (~> 3.7.0)
23
- rspec-expectations (3.7.0)
14
+ pry (0.14.1)
15
+ coderay (~> 1.1)
16
+ method_source (~> 1.0)
17
+ rake (13.0.6)
18
+ rspec (3.11.0)
19
+ rspec-core (~> 3.11.0)
20
+ rspec-expectations (~> 3.11.0)
21
+ rspec-mocks (~> 3.11.0)
22
+ rspec-core (3.11.0)
23
+ rspec-support (~> 3.11.0)
24
+ rspec-expectations (3.11.0)
24
25
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.7.0)
26
- rspec-mocks (3.7.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-mocks (3.11.1)
27
28
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.7.0)
29
- rspec-support (3.7.1)
30
- treetop (1.6.10)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-support (3.11.0)
31
+ treetop (1.6.11)
31
32
  polyglot (~> 0.3)
32
33
 
33
34
  PLATFORMS
@@ -37,9 +38,9 @@ DEPENDENCIES
37
38
  bchess!
38
39
  bundler (~> 1.16)
39
40
  pry
40
- rake (~> 10.0)
41
+ rake (~> 13.0)
41
42
  rspec (~> 3.0)
42
43
  treetop (~> 1.6)
43
44
 
44
45
  BUNDLED WITH
45
- 1.16.1
46
+ 1.17.3
data/bchess.gemspec CHANGED
@@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
+ spec.add_dependency 'treetop', '~> 1.6', '>= 1.6.11'
24
+
23
25
  spec.add_development_dependency 'bundler', '~> 1.16'
24
26
  spec.add_development_dependency 'pry'
25
- spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rake', '~> 13.0'
26
28
  spec.add_development_dependency 'rspec', '~> 3.0'
27
29
  spec.add_development_dependency 'treetop', '~> 1.6'
28
30
  end
@@ -1,9 +1,5 @@
1
1
  module Bchess
2
2
  module BoardHelpers
3
- def field(column, row)
4
- (column + 97).chr + (row + 1).to_s
5
- end
6
-
7
3
  def invalid_data?(piece, column, row)
8
4
  piece.nil? || !(0..7).cover?(column) || !(0..7).cover?(row)
9
5
  end
@@ -1,3 +1,3 @@
1
1
  module Bchess
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
data/lib/bchess.rb CHANGED
@@ -1,28 +1,28 @@
1
- require 'bchess/helpers/board_helpers'
2
- require 'bchess/helpers/fen_helpers'
3
- require 'bchess/helpers/board_helpers'
4
- require 'bchess/helpers/castle_helpers'
5
- require 'bchess/helpers/validations'
6
- require 'bchess/helpers/en_passant_helpers'
7
- require 'bchess/helpers/field_between_helpers'
1
+ require_relative 'bchess/helpers/board_helpers'
2
+ require_relative 'bchess/helpers/fen_helpers'
3
+ require_relative 'bchess/helpers/board_helpers'
4
+ require_relative 'bchess/helpers/castle_helpers'
5
+ require_relative 'bchess/helpers/validations'
6
+ require_relative 'bchess/helpers/en_passant_helpers'
7
+ require_relative 'bchess/helpers/field_between_helpers'
8
8
 
9
- require 'bchess/version'
10
- require 'bchess/piece'
11
- require 'bchess/king'
12
- require 'bchess/rook'
13
- require 'bchess/bishop'
14
- require 'bchess/queen'
15
- require 'bchess/knight'
16
- require 'bchess/pawn'
17
- require 'bchess/board'
9
+ require_relative 'bchess/version'
10
+ require_relative 'bchess/piece'
11
+ require_relative 'bchess/king'
12
+ require_relative 'bchess/rook'
13
+ require_relative 'bchess/bishop'
14
+ require_relative 'bchess/queen'
15
+ require_relative 'bchess/knight'
16
+ require_relative 'bchess/pawn'
17
+ require_relative 'bchess/board'
18
18
 
19
- require 'pgn/parser'
20
- require 'pgn/pgn_file'
21
- require 'pgn/pgn_nodes'
22
- require 'pgn/game'
23
- require 'pgn/game_header'
24
- require 'pgn/game_body'
25
- require 'pgn/move_info_parser'
19
+ require_relative 'pgn/parser'
20
+ require_relative 'pgn/pgn_file'
21
+ require_relative 'pgn/pgn_nodes'
22
+ require_relative 'pgn/game'
23
+ require_relative 'pgn/game_header'
24
+ require_relative 'pgn/game_body'
25
+ require_relative 'pgn/move_info_parser'
26
26
 
27
27
  module Bchess
28
28
  class InvalidMoveException < StandardError; end
data/lib/pgn/game_body.rb CHANGED
@@ -29,8 +29,10 @@ module Bchess
29
29
  next
30
30
  end
31
31
 
32
+ piece = move_info.fetch(:piece)
33
+ column, row = piece.column, piece.row
32
34
  board.move(*move_info.values)
33
- @moves << move_info
35
+ @moves << move_info.merge( { piece: piece.class.new(piece.color, column, row) })
34
36
  end
35
37
  end
36
38
 
@@ -1,7 +1,7 @@
1
1
  module Bchess
2
2
  module PGN
3
3
  class GameHeader
4
- attr_reader :header, :player_white, :player_black
4
+ attr_reader :header
5
5
 
6
6
  def initialize(header)
7
7
  @header = header
@@ -40,13 +40,25 @@ module Bchess
40
40
  end
41
41
 
42
42
  def eco
43
- @eco ||= values['Eco']
43
+ @eco ||= values['ECO']
44
44
  end
45
45
 
46
46
  def result
47
47
  @result ||= values['Result']
48
48
  end
49
49
 
50
+ def opening
51
+ @opening ||= values['Opening']
52
+ end
53
+
54
+ def variation
55
+ @variation ||= values['Variation']
56
+ end
57
+
58
+ def plycount
59
+ @plycount ||= values['PlyCount']
60
+ end
61
+
50
62
  def values
51
63
  @values ||= header.create_value_hash
52
64
  end
data/lib/pgn/parser.rb CHANGED
@@ -7,22 +7,22 @@ module Bchess
7
7
  class Parser
8
8
  attr_reader :input, :output, :error, :tree
9
9
 
10
- Treetop.load('./lib/pgn/pgn_rules.treetop')
11
- @@parser = SexpParser.new
10
+ Treetop.load(File.expand_path('pgn_rules.treetop', __dir__))
12
11
 
13
12
  def initialize(input)
13
+ @parser = SexpParser.new
14
14
  @input = input
15
15
  end
16
16
 
17
17
  def parse
18
18
  if input.is_a?(String)
19
- @tree = @@parser.parse(input)
19
+ @tree = @parser.parse(input)
20
20
  elsif input.is_a?(Bchess::PGN::PGNFile)
21
- @tree = @@parser.parse(input.load_games)
21
+ @tree = @parser.parse(input.load_games)
22
22
  end
23
23
 
24
24
  unless tree
25
- raise PGN::ParserException, "Parse error at offset: #{@@parser.index}"
25
+ raise PGN::ParserException, "Parse error: #{@parser.failure_reason}"
26
26
  end
27
27
 
28
28
  sanitize_tree(tree)
data/lib/pgn/pgn_nodes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'treetop'
2
+
1
3
  module Sexp
2
4
  class PAllGames < Treetop::Runtime::SyntaxNode
3
5
  end
metadata CHANGED
@@ -1,15 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bchess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Staszek Zawadzki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-23 00:00:00.000000000 Z
11
+ date: 2023-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: treetop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.11
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.11
13
33
  - !ruby/object:Gem::Dependency
14
34
  name: bundler
15
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +64,14 @@ dependencies:
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '10.0'
67
+ version: '13.0'
48
68
  type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '10.0'
74
+ version: '13.0'
55
75
  - !ruby/object:Gem::Dependency
56
76
  name: rspec
57
77
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +107,7 @@ executables: []
87
107
  extensions: []
88
108
  extra_rdoc_files: []
89
109
  files:
110
+ - ".github/workflows/ruby.yml"
90
111
  - ".gitignore"
91
112
  - ".rspec"
92
113
  - ".travis.yml"
@@ -145,8 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
166
  - !ruby/object:Gem::Version
146
167
  version: '0'
147
168
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.6.14
169
+ rubygems_version: 3.3.7
150
170
  signing_key:
151
171
  specification_version: 4
152
172
  summary: Parsing chess PGN games.