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 +5 -5
- data/.github/workflows/ruby.yml +35 -0
- data/.gitignore +3 -0
- data/Gemfile.lock +23 -22
- data/bchess.gemspec +3 -1
- data/lib/bchess/helpers/board_helpers.rb +0 -4
- data/lib/bchess/version.rb +1 -1
- data/lib/bchess.rb +23 -23
- data/lib/pgn/game_body.rb +3 -1
- data/lib/pgn/game_header.rb +14 -2
- data/lib/pgn/parser.rb +5 -5
- data/lib/pgn/pgn_nodes.rb +2 -0
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6ee977b4ad266d30e964e008cce9ac2004295ffe1af8dea97d8f8c2b9810219f
|
4
|
+
data.tar.gz: 61ba542136ff29506701d5e1dc4b2048d5b7648192235c5cd6374260ae08839d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/Gemfile.lock
CHANGED
@@ -1,33 +1,34 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bchess (0.1.
|
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.
|
10
|
-
diff-lcs (1.
|
11
|
-
method_source (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.
|
14
|
-
coderay (~> 1.1
|
15
|
-
method_source (~>
|
16
|
-
rake (
|
17
|
-
rspec (3.
|
18
|
-
rspec-core (~> 3.
|
19
|
-
rspec-expectations (~> 3.
|
20
|
-
rspec-mocks (~> 3.
|
21
|
-
rspec-core (3.
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-expectations (3.
|
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.
|
26
|
-
rspec-mocks (3.
|
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.
|
29
|
-
rspec-support (3.
|
30
|
-
treetop (1.6.
|
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 (~>
|
41
|
+
rake (~> 13.0)
|
41
42
|
rspec (~> 3.0)
|
42
43
|
treetop (~> 1.6)
|
43
44
|
|
44
45
|
BUNDLED WITH
|
45
|
-
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', '~>
|
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
|
data/lib/bchess/version.rb
CHANGED
data/lib/bchess.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
|
data/lib/pgn/game_header.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Bchess
|
2
2
|
module PGN
|
3
3
|
class GameHeader
|
4
|
-
attr_reader :header
|
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['
|
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('
|
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 =
|
19
|
+
@tree = @parser.parse(input)
|
20
20
|
elsif input.is_a?(Bchess::PGN::PGNFile)
|
21
|
-
@tree =
|
21
|
+
@tree = @parser.parse(input.load_games)
|
22
22
|
end
|
23
23
|
|
24
24
|
unless tree
|
25
|
-
raise PGN::ParserException, "Parse error
|
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
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.
|
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:
|
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: '
|
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: '
|
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
|
-
|
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.
|