Class: ChessValidator::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/engine.rb

Class Method Summary collapse

Class Method Details

.defended_pieces(fen_notation) ⇒ Object


36
37
38
# File 'lib/engine.rb', line 36

def defended_pieces(fen_notation)
  MoveLogic.defended_pieces_by_square(fen_notation)
end

.find_next_moves(fen_notation) ⇒ Object


7
8
9
10
# File 'lib/engine.rb', line 7

def find_next_moves(fen_notation)
  fen = PGN::FEN.new(fen_notation)
  MoveLogic.next_moves(fen)
end

.find_next_moves_from_moves(moves) ⇒ Object


12
13
14
15
# File 'lib/engine.rb', line 12

def find_next_moves_from_moves(moves)
  fen = PGN::Game.new(moves).positions.last.to_fen
  MoveLogic.next_moves(fen)
end

.make_random_move(fen_notation, pieces_with_moves) ⇒ Object


17
18
19
20
21
# File 'lib/engine.rb', line 17

def make_random_move(fen_notation, pieces_with_moves)
  piece_to_move = pieces_with_moves.sample
  move = piece_to_move.valid_moves.sample
  MoveLogic.make_move(piece_to_move, move, fen_notation)
end

.move(piece, move, fen_notation) ⇒ Object


23
24
25
# File 'lib/engine.rb', line 23

def move(piece, move, fen_notation)
  MoveLogic.make_move(piece, move, fen_notation)
end

.pieces(fen_notation) ⇒ Object


27
28
29
30
# File 'lib/engine.rb', line 27

def pieces(fen_notation)
  fen = PGN::FEN.new(fen_notation)
  BoardLogic.build_board(fen).values
end

.result(fen_notation) ⇒ Object


32
33
34
# File 'lib/engine.rb', line 32

def result(fen_notation)
  GameLogic.find_game_result(fen_notation)
end