chessmate 0.6.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cf6df76e1f2de6a990d213a7c9eec3f5e7dbd5d7642acac8414dab0f73575d4
4
- data.tar.gz: 7c8d65759a617103e16dc6ebc33b3b54a57b9c72b3dc2f831049a4334eb298c7
3
+ metadata.gz: d93cf15b660549aaf0e458ec3f190900be90dde590893e521ef75115f00394c5
4
+ data.tar.gz: 576c2b0d4ea1c210610f03539fcc6bbaf95b7d1b7e6d04f277f862168fae2825
5
5
  SHA512:
6
- metadata.gz: 6725ea4abc447701912c3ecda587e3d7d60c8077f0f81616ee957d57a5a7aa8cab3149475e81164a1ea668475f5baf6e682b8d14f94130fc127d0035eab44c4f
7
- data.tar.gz: 71f848ba3ff938afbd33cc0777a9707383e97ec75b19e66ed1f3837baaddfe81acb2daf8a62730c2ab2f263a6f2fc42ea585ace23d4deed420e561e7f7249834
6
+ metadata.gz: 835c31648c2c01fdb5bf15a4c9ea50c933260601e53f3ae660113dd29d4d4831d638c9ccaef863f0bd94d8e468ee23e89fdce277ef27ecae9bc3c35eaed6faec
7
+ data.tar.gz: 3e8061129daa7964e07e8cadf09a560faa5897ac3b2180721423ea9e3784e6363dc49888d01a975a4571773f46243f7c6558c5cd890aad0baa3c69d20a9920dd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chessmate (0.6.1)
4
+ chessmate (0.7.0)
5
5
  deep_dup (~> 0)
6
6
 
7
7
  GEM
data/lib/chessmate.rb CHANGED
@@ -12,20 +12,29 @@ class ChessMate
12
12
  require 'pieces/king'
13
13
  require 'helpers/default'
14
14
 
15
- attr_reader :board, :turn, :in_check, :promotable, :en_passant, :castling
15
+ attr_reader :board, :turn, :in_check, :promotable, :en_passant, :castling, :allow_out_of_turn
16
16
 
17
17
  def initialize(board: nil,
18
18
  turn: nil,
19
19
  promotable: nil,
20
20
  en_passant: nil,
21
21
  castling: nil,
22
- in_check: nil)
22
+ in_check: nil,
23
+ allow_out_of_turn: nil)
23
24
  @board = board || DEFAULT[:board].map(&:dup)
24
25
  @turn = turn || DEFAULT[:turn]
25
26
  @promotable = promotable || DeepDup.deep_dup(DEFAULT[:promotable])
26
27
  @en_passant = en_passant || DeepDup.deep_dup(DEFAULT[:en_passant])
27
28
  @castling = castling || DeepDup.deep_dup(DEFAULT[:castling])
28
29
  @in_check = in_check || DeepDup.deep_dup(DEFAULT[:in_check])
30
+
31
+ @allow_out_of_turn = if allow_out_of_turn.nil?
32
+ ENV['TEST'] == 'true' || false
33
+ elsif [true, false].include?(allow_out_of_turn)
34
+ allow_out_of_turn
35
+ else
36
+ false
37
+ end
29
38
  end
30
39
 
31
40
  def update(orig, dest = nil)
@@ -118,6 +127,9 @@ class ChessMate
118
127
 
119
128
  piece = @board[orig_y][orig_x]
120
129
  piece_type = piece[1]
130
+ allowed_turn = piece[0] == "W" ? :odd? : :even?
131
+
132
+ return false unless @allow_out_of_turn || @turn.send(allowed_turn)
121
133
 
122
134
  board = test_board.nil? ? @board : test_board
123
135
  valid_move = case piece_type
@@ -47,6 +47,11 @@ describe ChessMate do
47
47
  chess = ChessMate.new(in_check: in_check)
48
48
  expect(chess.in_check).to eql(in_check)
49
49
  end
50
+
51
+ it 'for allow_out_of_turn' do
52
+ chess = ChessMate.new(allow_out_of_turn: true)
53
+ expect(chess.allow_out_of_turn).to eql(true)
54
+ end
50
55
  end
51
56
 
52
57
  context 'no custom parameters' do
@@ -207,6 +212,21 @@ describe ChessMate do
207
212
  @chess = ChessMate.new
208
213
  end
209
214
 
215
+ context 'allow out of turn' do
216
+ it 'by default should not let players move out of turn' do
217
+ chess = ChessMate.new(allow_out_of_turn: false)
218
+ expect(chess.move('a7', 'a6')).to eql(false)
219
+ expect(chess.board).to eql(DEFAULT[:board])
220
+ expect(chess.move('a2','a3')).to eql(true)
221
+ expect(chess.move('a3','a4')).to eql(false)
222
+ end
223
+
224
+ it 'option to allow players to move out of turn' do
225
+ chess = ChessMate.new(allow_out_of_turn: true)
226
+ expect(chess.move('a7', 'a6')).to eql(true)
227
+ end
228
+ end
229
+
210
230
  it 'should test that the king is not in check before moving' do
211
231
  board = Array.new(8) { Array.new(8, nil) }
212
232
  board[7][4] = 'WK'
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,11 @@
16
16
  #
17
17
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
18
  RSpec.configure do |config|
19
+ config.before(:suite) do
20
+ ENV.fetch('TEST', 'true')
21
+ ENV['TEST'] = 'true'
22
+ end
23
+ config.after(:suite) { ENV.delete('TEST') }
19
24
  # rspec-expectations config goes here. You can use an alternate
20
25
  # assertion/expectation library such as wrong or the stdlib/minitest
21
26
  # assertions if you prefer.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chessmate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Porter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-20 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry