chessmate 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/chessmate.rb +3 -3
- data/lib/helpers/{logger.rb → chess_logger.rb} +1 -1
- data/spec/logger_spec.rb +22 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4320f3ff2c0dbac49fb6b11753cf8938f0c15f3777b875af02c708b46772f10
|
4
|
+
data.tar.gz: e28d1a784d8a824cae0a5bc61918bb83d63d54cf009ea9498f8613059bd2f4e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7f3f1928d0584c5bd5f80a7abd7357a1f20170f8280afd987a2a8b50ddf2c7e019abbedfaee572798a2ce60af71c7ede9c2ab2aefbd9cb0bf8dc61ce3363556
|
7
|
+
data.tar.gz: 713289a71b4b42625de6e98af40a8419b51f7539288e5ee5576837cff48dada6e6176ed1d0d27b06207e9d2ebb1db90ce2a9e570231af622ebfffac5c7acd2bc
|
data/Gemfile.lock
CHANGED
data/lib/chessmate.rb
CHANGED
@@ -11,7 +11,7 @@ class ChessMate
|
|
11
11
|
require 'pieces/queen'
|
12
12
|
require 'pieces/king'
|
13
13
|
require 'helpers/default'
|
14
|
-
require 'helpers/
|
14
|
+
require 'helpers/chess_logger'
|
15
15
|
|
16
16
|
attr_reader :board,
|
17
17
|
:turn,
|
@@ -92,7 +92,7 @@ class ChessMate
|
|
92
92
|
@promotable = dest if piece_type[1] == 'P' && promote?(orig)
|
93
93
|
|
94
94
|
unless @ignore_logging
|
95
|
-
logger =
|
95
|
+
logger = ChessLogger.new(orig, dest, @board)
|
96
96
|
@move_history << logger.log_move
|
97
97
|
end
|
98
98
|
|
@@ -282,7 +282,7 @@ class ChessMate
|
|
282
282
|
|
283
283
|
return if @ignore_logging
|
284
284
|
|
285
|
-
logger =
|
285
|
+
logger = ChessLogger.new(nil, nil, nil, promotion_type: piece_type, history: @move_history)
|
286
286
|
@move_history[-1] += logger.log_promotion
|
287
287
|
end
|
288
288
|
end
|
data/spec/logger_spec.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
-
require_relative '../lib/helpers/
|
4
|
+
require_relative '../lib/helpers/chess_logger'
|
5
5
|
require 'chessmate'
|
6
6
|
|
7
|
-
describe '
|
7
|
+
describe 'ChessLogger' do
|
8
8
|
before :each do
|
9
9
|
@normal_moves_board = [
|
10
10
|
[nil, nil, nil, nil, nil, nil, nil, nil],
|
@@ -64,105 +64,105 @@ describe 'Logger' do
|
|
64
64
|
|
65
65
|
context 'pawn moves' do
|
66
66
|
it 'should log normal pawn moves' do
|
67
|
-
logger =
|
67
|
+
logger = ChessLogger.new([6, 0], [5, 0], @normal_moves_board)
|
68
68
|
expect(logger.log_move).to eql('a3')
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should log capturing moves' do
|
72
|
-
logger =
|
72
|
+
logger = ChessLogger.new([6, 0], [5, 1], @capture_moves_board)
|
73
73
|
expect(logger.log_move).to eql('axb3')
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'should log en passant moves' do
|
77
|
-
logger =
|
77
|
+
logger = ChessLogger.new([3, 6], [2, 7], @capture_moves_board, en_passant: true)
|
78
78
|
expect(logger.log_move).to eql('gxh6')
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
context 'knight moves' do
|
83
83
|
it 'should log normal knight moves' do
|
84
|
-
logger =
|
84
|
+
logger = ChessLogger.new([6, 1], [4, 0], @normal_moves_board)
|
85
85
|
expect(logger.log_move).to eql('Na4')
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should log capturing moves' do
|
89
|
-
logger =
|
89
|
+
logger = ChessLogger.new([6, 1], [4, 0], @capture_moves_board)
|
90
90
|
expect(logger.log_move).to eql('Nxa4')
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
94
|
context 'bishop moves' do
|
95
95
|
it 'should log normal bishop moves' do
|
96
|
-
logger =
|
96
|
+
logger = ChessLogger.new([6, 2], [5, 1], @normal_moves_board)
|
97
97
|
expect(logger.log_move).to eql('Bb3')
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should log capturing moves' do
|
101
|
-
logger =
|
101
|
+
logger = ChessLogger.new([6, 2], [5, 1], @capture_moves_board)
|
102
102
|
expect(logger.log_move).to eql('Bxb3')
|
103
103
|
end
|
104
104
|
end
|
105
105
|
|
106
106
|
context 'queen moves' do
|
107
107
|
it 'should log normal queen moves' do
|
108
|
-
logger =
|
108
|
+
logger = ChessLogger.new([6, 3], [5, 3], @normal_moves_board)
|
109
109
|
expect(logger.log_move).to eql('Qd3')
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'should log capturing moves' do
|
113
|
-
logger =
|
113
|
+
logger = ChessLogger.new([6, 3], [5, 3], @capture_moves_board)
|
114
114
|
expect(logger.log_move).to eql('Qxd3')
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
context 'king moves' do
|
119
119
|
it 'should log normal king moves' do
|
120
|
-
logger =
|
120
|
+
logger = ChessLogger.new([6, 4], [5, 4], @normal_moves_board)
|
121
121
|
expect(logger.log_move).to eql('Ke3')
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should log capturing moves' do
|
125
|
-
logger =
|
125
|
+
logger = ChessLogger.new([6, 4], [5, 3], @capture_moves_board)
|
126
126
|
expect(logger.log_move).to eql('Kxd3')
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
130
|
context 'ambiguous moves' do
|
131
131
|
it 'should add file info to log moves with pieces in same file' do
|
132
|
-
logger =
|
132
|
+
logger = ChessLogger.new([7, 0], [5, 0], @ambiguous_moves_board)
|
133
133
|
expect(logger.log_move).to eql('R1a3')
|
134
134
|
end
|
135
135
|
|
136
136
|
it 'should add rank info to log moves with pieces in same rank' do
|
137
|
-
logger =
|
137
|
+
logger = ChessLogger.new([0, 3], [0, 5], @ambiguous_moves_board)
|
138
138
|
expect(logger.log_move).to eql('Rdf8')
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'should add file and rank info to log moves with multiple pieces in same file and rank' do
|
142
|
-
logger =
|
142
|
+
logger = ChessLogger.new([4, 7], [7, 4], @ambiguous_moves_board)
|
143
143
|
expect(logger.log_move).to eql('Qh4e1')
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'should handle knights/bishops/queens with ability to move to dest square' do
|
147
|
-
logger =
|
147
|
+
logger = ChessLogger.new([2, 3], [0, 1], @ambiguous_moves_board)
|
148
148
|
expect(logger.log_move).to eql('Bdb8')
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
152
|
context 'specialty moves' do
|
153
153
|
it 'should log kingside castles' do
|
154
|
-
logger =
|
154
|
+
logger = ChessLogger.new([7, 4], [7, 6], @specialty_moves_board)
|
155
155
|
expect(logger.log_move).to eql('0-0')
|
156
156
|
end
|
157
157
|
|
158
158
|
it 'should log queenside castles' do
|
159
|
-
logger =
|
159
|
+
logger = ChessLogger.new([7, 4], [7, 2], @specialty_moves_board)
|
160
160
|
expect(logger.log_move).to eql('0-0-0')
|
161
161
|
end
|
162
162
|
|
163
163
|
it 'should log pawn promotion' do
|
164
164
|
%w[R N B Q].each do |piece|
|
165
|
-
logger =
|
165
|
+
logger = ChessLogger.new(nil, nil, nil, promotion_type: piece)
|
166
166
|
expect(logger.log_promotion).to eql("=(#{piece})")
|
167
167
|
end
|
168
168
|
end
|
@@ -170,12 +170,12 @@ describe 'Logger' do
|
|
170
170
|
|
171
171
|
context 'game status indications' do
|
172
172
|
it 'should log check' do
|
173
|
-
logger =
|
173
|
+
logger = ChessLogger.new([5, 0], [6, 2], @check_board)
|
174
174
|
expect(logger.log_move).to eql('Nc2+')
|
175
175
|
end
|
176
176
|
|
177
177
|
it 'should log checkmate' do
|
178
|
-
logger =
|
178
|
+
logger = ChessLogger.new([0, 3], [0, 4], @check_board)
|
179
179
|
expect(logger.log_move).to eql('Qe8#')
|
180
180
|
end
|
181
181
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chessmate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Porter
|
@@ -78,8 +78,8 @@ files:
|
|
78
78
|
- LICENSE
|
79
79
|
- README.md
|
80
80
|
- lib/chessmate.rb
|
81
|
+
- lib/helpers/chess_logger.rb
|
81
82
|
- lib/helpers/default.rb
|
82
|
-
- lib/helpers/logger.rb
|
83
83
|
- lib/helpers/notation_parser.rb
|
84
84
|
- lib/pieces/bishop.rb
|
85
85
|
- lib/pieces/king.rb
|