chessmate 0.6.0 → 0.6.1

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: 88b7cfdccb2b5fce2293f06f3087016f0f22c6c84d2bbd8b951b0f84d210c1a1
4
- data.tar.gz: d742775fb79b42df9f6da2e18ed3165af57bc55e0ee819a1a598759a0679c3e9
3
+ metadata.gz: 0a12cc267a107eb1cb19614549a1547fa12f5fac352bd72189957c8a8bfe05b8
4
+ data.tar.gz: 48dab37bce389168e88cdf2edaa9c65f355eb5ab751222118a2900296c23081a
5
5
  SHA512:
6
- metadata.gz: bb280c096c28c59ca304378af781d2147a106170565b5cc2ce21b63253ebc60832775cd6c2abcf5e444b06051087c5512f031b84ebf4c0c6f97215f3f04b0b13
7
- data.tar.gz: c089f65c76ff79418d7cbafa9089630fe9981310d264b0c3c0fd734eec26b855b01e068de404085a3cce7941703f17970c3e30028f6a4734bacf897106ca0f92
6
+ metadata.gz: 8f2939cd5d2afd626e6cc2f81d975cf1314da32d51bde6477c6dc658e8cec00212dd42cbb943c831e91e340630d1640692cc4b5da6510a6e311242e4750cd59f
7
+ data.tar.gz: c552a7377a72eb609a2c5d9c28f74a2287714398e2206c8304625f3d84ed88e8209ef9c3a4e78e0e2e7dda85d83921b33b0c1bde390851852e4f0ee992ecf927
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chessmate (0.5.0)
4
+ chessmate (0.6.1)
5
5
  deep_dup (~> 0)
6
6
 
7
7
  GEM
@@ -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
- move_double_on_first_turn && not_obstructed || basic_move
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
@@ -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'
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Porter