chess_validator 0.2.14 → 0.2.15

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/board_logic.rb +9 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae31a40890e32644ea7bab6a82407dea4d40f155a6557777b401b260b18d41d0
4
- data.tar.gz: ce29175b6af41591075e5158488c26bffc4cb92ee040d7389d6f751fa8117679
3
+ metadata.gz: 755cc8b1ad78feff8ad130c8a3e5c11803263d8ccf41db3ec1c67fa7a08427aa
4
+ data.tar.gz: b926a815e705bda86df14da9269533229c76c36d2bc0301a5c18200d5cf1e9f4
5
5
  SHA512:
6
- metadata.gz: fc687efb628401bcf9f5f3374b877a4eca8c4d496004dafdff545e66332416565aaa17a988eaf6e83750e39357f2dea684638402f6c641427a0c4460caebefae
7
- data.tar.gz: 3fcb3650f113f585147f3afa567134564717f4952af4794de1c0c4b4d3c6cb25ddcd2ae041fc1300c14a45cf1f58279c728578f06aa5b81d220e9774136dce7e
6
+ metadata.gz: 9bc14f5b3a08834a3a80da545fcd9612a5624ff6f869918dc6d1a4798320708034a0120d2c6b9509f9746f532dbfdfeccf4f0c8ae07d28e05bf3084345aff996
7
+ data.tar.gz: ab77aa9915b79663a765596d3f31bb792363feb393e49b618a1c35c5ab46cdac5591cd60a8c781f2bb4449f9e82d2de799eafafe3bcb7456cfcf5fb5b76b5b44
@@ -20,7 +20,7 @@ module ChessValidator
20
20
  def self.to_fen_notation(board, previous_fen, piece, move)
21
21
  notation = handle_position(board)
22
22
  notation += find_turn(previous_fen.active)
23
- notation += handle_castle(previous_fen.castling, piece)
23
+ notation += handle_castle(previous_fen.castling, piece, board)
24
24
  notation += handle_en_passant(piece, move)
25
25
  notation += handle_half_move_clock(board.size, previous_fen, piece)
26
26
  notation += piece.color == 'b' ? previous_fen.fullmove.next : previous_fen.fullmove
@@ -35,17 +35,15 @@ module ChessValidator
35
35
  end
36
36
  end
37
37
 
38
- def self.handle_castle(castling, piece)
38
+ def self.handle_castle(castling, piece, board)
39
39
  return castling if castling == '-'
40
- if ['K', 'Q', 'k', 'q'].include?(piece.piece_type)
41
- castling.size == 1 ? '-' : castling.delete(piece.piece_type)
42
- elsif piece.piece_type.downcase == 'r'
43
- castle_side = piece.position[0] == 'a' ? 'q' : 'k'
44
- castle_side = castle_side.capitalize if piece.color == 'w'
45
- castling.size == 1 ? '-' : castling.delete(castle_side)
46
- else
47
- castling
48
- end
40
+ castling.delete!('K') if board[64].nil? || board[64].piece_type != 'R'
41
+ castling.delete!('K') if board[61].nil? || board[61].piece_type != 'K'
42
+ castling.delete!('Q') if board[57].nil? || board[57].piece_type != 'R'
43
+ castling.delete!('k') if board[8].nil? || board[8].piece_type != 'r'
44
+ castling.delete!('k') if board[5].nil? || board[5].piece_type != 'k'
45
+ castling.delete!('q') if board[1].nil? || board[1].piece_type != 'r'
46
+ castling.size == 1 ? '-' : castling
49
47
  end
50
48
 
51
49
  def self.handle_en_passant(piece, move)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chess_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Ellison