chess_validator 0.2.1 → 0.2.2

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: 1af34872a259842b2169becd1ee7570ceac96f7fc626e4c4306e7544fca7e25a
4
- data.tar.gz: 821da801fa31123bd8ec1a6d151bb14364da5ad60d833b11b129ef205ec51411
3
+ metadata.gz: 0e4f35f7365cba31d8882b494232dd0357745db3b3390d9da373225e9e378ee1
4
+ data.tar.gz: bab4ecf238d41abc2290e2f1a7bac33d727d14605140e57414cef484225d581f
5
5
  SHA512:
6
- metadata.gz: dae4d729c77310493648f7c3ec78ee954b3f04055b94a9a7410a74a3028d1b86918a6161e148bdaa27eaf75249a3a80e9ee9e2c54ed69cfcae8250740a62ba54
7
- data.tar.gz: d0dcfb4661d6c5f8b231207ad0cd96c7634ed84898c3d76331c10f64aad54f345d4ef10538e3f27fb428eadf686958f7ccd69ea48fbb18bd1ceb0d40a4bf2b05
6
+ metadata.gz: cde6774a3a7e10f367805944038f8ddafb61c1aa4054067d20de055171b062ed270081deee99a50e14f771a8fd9a4f71bee23eaa19faa0256ba374151e6605f2
7
+ data.tar.gz: fdec3d74fb38c1bd2a4ecbce08c2d1f7c11e705856f58b858868f0628dfab8d1917e4bb972afb4fb07d0c85ac755cae0f7d04685a427a3dcc8322ad5f15e37b2
@@ -1,2 +1 @@
1
- require 'move_logic'
2
- require 'game_logic'
1
+ require 'engine'
@@ -0,0 +1,29 @@
1
+ require 'move_logic'
2
+ require 'game_logic'
3
+
4
+ module ChessValidator
5
+ class Engine
6
+ class << self
7
+ def find_next_moves(fen_notation)
8
+ fen = PGN::FEN.new(fen_notation)
9
+ MoveLogic.next_moves(fen)
10
+ end
11
+
12
+ def find_next_moves_from_moves(moves)
13
+ fen = PGN::Game.new(moves).positions.last.to_fen
14
+ MoveLogic.next_moves(fen)
15
+ end
16
+
17
+ def make_random_move(fen_notation, pieces_with_moves)
18
+ piece_to_move = pieces_with_moves.sample
19
+ move = piece_to_move.valid_moves.sample
20
+ MoveLogic.make_move(piece_to_move, move, fen_notation)
21
+ end
22
+
23
+ def get_pieces(fen_notation)
24
+ fen = PGN::Game.new(moves).positions.last.to_fen
25
+ BoardLogic.build_board(fen).values
26
+ end
27
+ end
28
+ end
29
+ end
@@ -4,16 +4,6 @@ require 'pgn'
4
4
  module ChessValidator
5
5
  class MoveLogic
6
6
  class << self
7
- def find_next_moves(fen_notation)
8
- fen = PGN::FEN.new(fen_notation)
9
- next_moves(fen)
10
- end
11
-
12
- def find_next_moves_from_moves(moves)
13
- fen = PGN::Game.new(moves).positions.last.to_fen
14
- next_moves(fen)
15
- end
16
-
17
7
  def next_moves(fen)
18
8
  board = BoardLogic.build_board(fen)
19
9
  pieces = []
@@ -51,7 +41,8 @@ module ChessValidator
51
41
  def with_next_move(piece, board, move)
52
42
  index = INDEX_KEY[move]
53
43
  new_board = board.clone
54
- new_piece = Piece.new(piece.piece_type, index)
44
+ piece_type = resolve_piece_type(piece.piece_type, move)
45
+ new_piece = Piece.new(piece_type, index)
55
46
  new_board.delete(piece.square_index)
56
47
  new_board[index] = new_piece
57
48
  new_board = handle_castle(new_board, move) if castled?(piece, move)
@@ -59,6 +50,14 @@ module ChessValidator
59
50
  new_board
60
51
  end
61
52
 
53
+ def resolve_piece_type(piece_type, move)
54
+ if piece_type.downcase == 'p' && ['1', '8'].include?(move[1])
55
+ move[1] == '8' ? 'Q' : 'q'
56
+ else
57
+ piece_type
58
+ end
59
+ end
60
+
62
61
  def handle_en_passant(board, pawn_color, move)
63
62
  if pawn_color == 'w'
64
63
  index = INDEX_KEY[move[0] + '5']
@@ -1,4 +1,4 @@
1
- require_relative './constants/square_key'
1
+ require_relative './constants/move_key'
2
2
 
3
3
  module ChessValidator
4
4
  class Piece
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Ellison
@@ -18,7 +18,8 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/board_logic.rb
20
20
  - lib/chess_validator.rb
21
- - lib/constants/square_key.rb
21
+ - lib/constants/move_key.rb
22
+ - lib/engine.rb
22
23
  - lib/game_logic.rb
23
24
  - lib/move_logic.rb
24
25
  - lib/piece.rb