chessmate 0.6.0 → 0.6.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/pieces/pawn.rb +9 -2
- data/spec/chessmate_spec.rb +21 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a12cc267a107eb1cb19614549a1547fa12f5fac352bd72189957c8a8bfe05b8
|
4
|
+
data.tar.gz: 48dab37bce389168e88cdf2edaa9c65f355eb5ab751222118a2900296c23081a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f2939cd5d2afd626e6cc2f81d975cf1314da32d51bde6477c6dc658e8cec00212dd42cbb943c831e91e340630d1640692cc4b5da6510a6e311242e4750cd59f
|
7
|
+
data.tar.gz: c552a7377a72eb609a2c5d9c28f74a2287714398e2206c8304625f3d84ed88e8209ef9c3a4e78e0e2e7dda85d83921b33b0c1bde390851852e4f0ee992ecf927
|
data/Gemfile.lock
CHANGED
data/lib/pieces/pawn.rb
CHANGED
@@ -27,12 +27,13 @@ class Pawn < Piece
|
|
27
27
|
return true
|
28
28
|
end
|
29
29
|
|
30
|
-
not_obstructed = !obstructed?(orig, dest, board)
|
30
|
+
not_obstructed = !obstructed?(orig, dest, board) && !dest_occupied?(dest, board)
|
31
31
|
|
32
32
|
basic_move = ((orig_y - dest_y) * direction == 1 && orig_x == dest_x)
|
33
33
|
move_double_on_first_turn = (orig_y - dest_y == (2 * direction)) && (orig_x == dest_x)
|
34
34
|
|
35
|
-
|
35
|
+
# binding.pry
|
36
|
+
not_obstructed && ( move_double_on_first_turn || basic_move )
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.en_passant(orig, dest, board, en_passant)
|
@@ -54,4 +55,10 @@ class Pawn < Piece
|
|
54
55
|
end
|
55
56
|
false
|
56
57
|
end
|
58
|
+
|
59
|
+
def self.dest_occupied?(dest, board)
|
60
|
+
dest_y = dest[0]
|
61
|
+
dest_x = dest[1]
|
62
|
+
!board[dest_y][dest_x].nil?
|
63
|
+
end
|
57
64
|
end
|
data/spec/chessmate_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'pry'
|
3
4
|
require 'spec_helper'
|
4
5
|
require_relative '../lib/chessmate'
|
5
6
|
require_relative '../lib/helpers/notation_parser'
|
@@ -398,6 +399,26 @@ describe ChessMate do
|
|
398
399
|
)
|
399
400
|
end
|
400
401
|
|
402
|
+
it 'should not allow for capturing forwards' do
|
403
|
+
board = Array.new(8) { Array.new(8, nil) }
|
404
|
+
board[5][4] = 'WP'
|
405
|
+
board[4][4] = 'BP'
|
406
|
+
chess = ChessMate.new(board: board)
|
407
|
+
chess.move('e3', 'e4')
|
408
|
+
expect(chess.board).to eql(
|
409
|
+
[
|
410
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
411
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
412
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
413
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
414
|
+
[nil, nil, nil, nil, 'BP', nil, nil, nil],
|
415
|
+
[nil, nil, nil, nil, 'WP', nil, nil, nil],
|
416
|
+
[nil, nil, nil, nil, nil, nil, nil, nil],
|
417
|
+
[nil, nil, nil, nil, nil, nil, nil, nil]
|
418
|
+
]
|
419
|
+
)
|
420
|
+
end
|
421
|
+
|
401
422
|
it 'should not allow pawns to move backwards to capture' do
|
402
423
|
board = Array.new(8) { Array.new(8, nil) }
|
403
424
|
board[4][4] = 'WP'
|