fen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/fen +3 -0
- data/fen.gemspec +33 -0
- data/lib/fen.rb +7 -0
- data/lib/fen/chess_constants.rb +7 -0
- data/lib/fen/cli.rb +12 -0
- data/lib/fen/display.rb +162 -0
- data/lib/fen/version.rb +3 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8873bc81601ea709b1e59a2f9894ac69b15071ee52072aabd5e1c99db23da8ea
|
4
|
+
data.tar.gz: 20c82a80c665fd821895b7c38ceb5d711b9c456596baea247c875ede66cdb9de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d13f75fb533bec2391762af05fe7caf375ff72217f40b76e8e4091638af9f59c553035b9706863ed21e15ae8a056304f0515aeb9575f1d474012b0239ffa49b8
|
7
|
+
data.tar.gz: a1091892079135f5de6f07ee925d87bab3d939623c3e27729a7db88af68385b604ec4756119be316f142063d230431e279ad03742b624e257b67920a7c7cf346
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fen (0.1.0)
|
5
|
+
thor
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
aruba (1.0.0.pre.alpha.4)
|
11
|
+
childprocess (~> 1.0)
|
12
|
+
contracts (~> 0.13)
|
13
|
+
cucumber (>= 2.4, < 4.0)
|
14
|
+
ffi (~> 1.9)
|
15
|
+
rspec-expectations (~> 3.4)
|
16
|
+
thor (~> 0.19)
|
17
|
+
backports (3.15.0)
|
18
|
+
builder (3.2.3)
|
19
|
+
childprocess (1.0.1)
|
20
|
+
rake (< 13.0)
|
21
|
+
contracts (0.16.0)
|
22
|
+
cucumber (3.1.2)
|
23
|
+
builder (>= 2.1.2)
|
24
|
+
cucumber-core (~> 3.2.0)
|
25
|
+
cucumber-expressions (~> 6.0.1)
|
26
|
+
cucumber-wire (~> 0.0.1)
|
27
|
+
diff-lcs (~> 1.3)
|
28
|
+
gherkin (~> 5.1.0)
|
29
|
+
multi_json (>= 1.7.5, < 2.0)
|
30
|
+
multi_test (>= 0.1.2)
|
31
|
+
cucumber-core (3.2.1)
|
32
|
+
backports (>= 3.8.0)
|
33
|
+
cucumber-tag_expressions (~> 1.1.0)
|
34
|
+
gherkin (~> 5.0)
|
35
|
+
cucumber-expressions (6.0.1)
|
36
|
+
cucumber-tag_expressions (1.1.1)
|
37
|
+
cucumber-wire (0.0.1)
|
38
|
+
diff-lcs (1.3)
|
39
|
+
ffi (1.11.1)
|
40
|
+
gherkin (5.1.0)
|
41
|
+
multi_json (1.14.1)
|
42
|
+
multi_test (0.1.2)
|
43
|
+
rake (10.5.0)
|
44
|
+
rspec-expectations (3.9.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.9.0)
|
47
|
+
rspec-support (3.9.0)
|
48
|
+
thor (0.20.3)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
aruba (~> 1.0.0.pre.alpha.4)
|
55
|
+
bundler (~> 1.17)
|
56
|
+
fen!
|
57
|
+
rake (~> 10.0)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Dominic Lupo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# fen
|
2
|
+
|
3
|
+
fen is a command line tool to work with chess fen or pgn.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
Command line interface to convert fen into unicode chessboard with
|
8
|
+
file and rank notation.
|
9
|
+
|
10
|
+
## TODO
|
11
|
+
|
12
|
+
pgn parser
|
13
|
+
|
14
|
+
pgn to fen converter
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'fen'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install fen
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
$ fen display r1bqk2r/pppp1ppp/2n2n2/2b1p3/2BPP3/2P2N2/PP3PPP/RNBQK2R b KQkq - 0 5
|
35
|
+
```
|
36
|
+
a b c d e f g h
|
37
|
+
┌──┬──┬──┬──┬──┬──┬──┬──┐
|
38
|
+
8 │♜ │ │♝ │♛ │♚ │ │ │♜ │ 8
|
39
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
40
|
+
7 │♟ │♟ │♟ │♟ │ │♟ │♟ │♟ │ 7
|
41
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
42
|
+
6 │ │ │♞ │ │ │♞ │ │ │ 6
|
43
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
44
|
+
5 │ │ │♝ │ │♟ │ │ │ │ 5
|
45
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
46
|
+
4 │ │ │♗ │♙ │♙ │ │ │ │ 4
|
47
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
48
|
+
3 │ │ │♙ │ │ │♘ │ │ │ 3
|
49
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
50
|
+
2 │♙ │♙ │ │ │ │♙ │♙ │♙ │ 2
|
51
|
+
├──┼──┼──┼──┼──┼──┼──┼──┤
|
52
|
+
1 │♖ │♘ │♗ │♕ │♔ │ │ │♖ │ 1
|
53
|
+
└──┴──┴──┴──┴──┴──┴──┴──┘
|
54
|
+
a b c d e f g h
|
55
|
+
```
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/DomPSU/fen.
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fen"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/fen
ADDED
data/fen.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "fen/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fen"
|
8
|
+
spec.version = Fen::VERSION
|
9
|
+
spec.authors = ["Dominic Lupo"]
|
10
|
+
spec.email = ["DominicLupo5318@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "fen is a command line tool to work with chess fen or pgn."
|
13
|
+
spec.description = "Currently fen supports a command line tool to convert"\
|
14
|
+
"fen to a unicode chess board with rank and file notation"\
|
15
|
+
"Future versions will include a pgn parser and a pgn to fen"\
|
16
|
+
"converter."
|
17
|
+
|
18
|
+
spec.homepage = "https://github.com/DomPSU/fen"
|
19
|
+
spec.license = "MIT"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_dependency "thor"
|
33
|
+
end
|
data/lib/fen.rb
ADDED
data/lib/fen/cli.rb
ADDED
data/lib/fen/display.rb
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
require_relative 'chess_constants'
|
2
|
+
|
3
|
+
class Display
|
4
|
+
attr_accessor :fen
|
5
|
+
attr_reader :piece_array
|
6
|
+
|
7
|
+
def initialize(fen)
|
8
|
+
@fen = fen
|
9
|
+
@piece_array = convert_fen_to_piece_array
|
10
|
+
end
|
11
|
+
|
12
|
+
def convert_fen_to_piece_array
|
13
|
+
fen_array = @fen.split("/")
|
14
|
+
|
15
|
+
first_rank_and_details = fen_array.last.split(" ")
|
16
|
+
first_rank = first_rank_and_details[0]
|
17
|
+
|
18
|
+
piece_array = fen_array
|
19
|
+
piece_array[-1] = first_rank
|
20
|
+
|
21
|
+
@piece_array = piece_array
|
22
|
+
end
|
23
|
+
|
24
|
+
def board
|
25
|
+
board = file_notation_row
|
26
|
+
board += top_row
|
27
|
+
|
28
|
+
ChessConstants::RANK_ARRAY.reverse.each do |rank|
|
29
|
+
board += piece_row(rank.to_i)
|
30
|
+
board += line_row unless rank.to_i == 1
|
31
|
+
end
|
32
|
+
|
33
|
+
board += bottom_row
|
34
|
+
board += file_notation_row
|
35
|
+
end
|
36
|
+
|
37
|
+
def file_notation_row
|
38
|
+
file_notation_row = " "
|
39
|
+
ChessConstants::FILE_ARRAY.each { |value| file_notation_row += "#{value} "}
|
40
|
+
file_notation_row += "\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def top_row
|
44
|
+
counter = 0
|
45
|
+
top_row = " "
|
46
|
+
top_row += unicode_board(:top_left_corner)
|
47
|
+
top_row += unicode_board(:horizontal)
|
48
|
+
top_row += unicode_board(:horizontal)
|
49
|
+
|
50
|
+
loop do
|
51
|
+
top_row += unicode_board(:top_mid)
|
52
|
+
top_row += unicode_board(:horizontal)
|
53
|
+
top_row += unicode_board(:horizontal)
|
54
|
+
counter += 1
|
55
|
+
break if counter == ChessConstants::NUMBER_OF_COLUMNS - 1
|
56
|
+
end
|
57
|
+
top_row += unicode_board(:top_right_corner)
|
58
|
+
top_row += "\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
def piece_row(rank_notation)
|
62
|
+
piece_row = rank_notation.to_s
|
63
|
+
piece_row += " "
|
64
|
+
|
65
|
+
@piece_array.reverse[rank_notation - 1].each_char do |board_square|
|
66
|
+
piece_row += unicode_board(:vertical)
|
67
|
+
|
68
|
+
if board_square.to_i > 1
|
69
|
+
(board_square.to_i - 1).times do
|
70
|
+
piece_row += " "
|
71
|
+
piece_row += unicode_board(:vertical)
|
72
|
+
end
|
73
|
+
|
74
|
+
piece_row += " "
|
75
|
+
elsif board_square.to_i == 1
|
76
|
+
piece_row += " "
|
77
|
+
else
|
78
|
+
piece_row += unicode_piece(board_square.to_sym)
|
79
|
+
end
|
80
|
+
piece_row += " "
|
81
|
+
end
|
82
|
+
|
83
|
+
piece_row += unicode_board(:vertical)
|
84
|
+
|
85
|
+
piece_row += " "
|
86
|
+
piece_row += rank_notation.to_s
|
87
|
+
piece_row += "\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
def line_row
|
91
|
+
counter = 0
|
92
|
+
|
93
|
+
line_row = " "
|
94
|
+
line_row += unicode_board(:left_mid)
|
95
|
+
line_row += unicode_board(:horizontal)
|
96
|
+
line_row += unicode_board(:horizontal)
|
97
|
+
|
98
|
+
loop do
|
99
|
+
line_row += unicode_board(:cross)
|
100
|
+
line_row += unicode_board(:horizontal)
|
101
|
+
line_row += unicode_board(:horizontal)
|
102
|
+
counter += 1
|
103
|
+
break if counter == ChessConstants::NUMBER_OF_COLUMNS - 1
|
104
|
+
end
|
105
|
+
line_row += unicode_board(:right_mid)
|
106
|
+
line_row += "\n"
|
107
|
+
end
|
108
|
+
|
109
|
+
def bottom_row
|
110
|
+
|
111
|
+
counter = 0
|
112
|
+
|
113
|
+
bottom_row = " "
|
114
|
+
bottom_row += unicode_board(:bottom_left_corner)
|
115
|
+
bottom_row += unicode_board(:horizontal)
|
116
|
+
bottom_row += unicode_board(:horizontal)
|
117
|
+
|
118
|
+
loop do
|
119
|
+
bottom_row += unicode_board(:bottom_mid)
|
120
|
+
bottom_row += unicode_board(:horizontal)
|
121
|
+
bottom_row += unicode_board(:horizontal)
|
122
|
+
counter += 1
|
123
|
+
break if counter == ChessConstants::NUMBER_OF_COLUMNS - 1
|
124
|
+
end
|
125
|
+
bottom_row += unicode_board(:bottom_right_corner)
|
126
|
+
bottom_row += "\n"
|
127
|
+
end
|
128
|
+
|
129
|
+
def unicode_board(key)
|
130
|
+
hash = {horizontal: "\u2500",
|
131
|
+
vertical: "\u2502",
|
132
|
+
top_left_corner: "\u250C",
|
133
|
+
top_right_corner: "\u2510",
|
134
|
+
bottom_left_corner: "\u2514",
|
135
|
+
bottom_right_corner: "\u2518",
|
136
|
+
top_mid: "\u252c",
|
137
|
+
left_mid: "\u251c",
|
138
|
+
right_mid: "\u2524",
|
139
|
+
bottom_mid: "\u2534",
|
140
|
+
cross: "\u253c"}
|
141
|
+
|
142
|
+
return hash.fetch(key).encode('utf-8')
|
143
|
+
end
|
144
|
+
|
145
|
+
def unicode_piece(piece)
|
146
|
+
|
147
|
+
hash = {K: "\u2654",
|
148
|
+
Q: "\u2655",
|
149
|
+
R: "\u2656",
|
150
|
+
B: "\u2657",
|
151
|
+
N: "\u2658",
|
152
|
+
P: "\u2659",
|
153
|
+
k: "\u265A",
|
154
|
+
q: "\u265B",
|
155
|
+
r: "\u265C",
|
156
|
+
b: "\u265D",
|
157
|
+
n: "\u265E",
|
158
|
+
p: "\u265F"}
|
159
|
+
|
160
|
+
return hash.fetch(piece).encode('utf-8')
|
161
|
+
end
|
162
|
+
end
|
data/lib/fen/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dominic Lupo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Currently fen supports a command line tool to convertfen to a unicode
|
56
|
+
chess board with rank and file notationFuture versions will include a pgn parser
|
57
|
+
and a pgn to fenconverter.
|
58
|
+
email:
|
59
|
+
- DominicLupo5318@gmail.com
|
60
|
+
executables:
|
61
|
+
- fen
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- ".gitignore"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- exe/fen
|
74
|
+
- fen.gemspec
|
75
|
+
- lib/fen.rb
|
76
|
+
- lib/fen/chess_constants.rb
|
77
|
+
- lib/fen/cli.rb
|
78
|
+
- lib/fen/display.rb
|
79
|
+
- lib/fen/version.rb
|
80
|
+
homepage: https://github.com/DomPSU/fen
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubygems_version: 3.0.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: fen is a command line tool to work with chess fen or pgn.
|
103
|
+
test_files: []
|