find-endings.rs 825 B

1234567891011121314151617181920212223242526272829
  1. // Load a file of games and extract those games which contain 5-4 rook endings.
  2. //
  3. use pgn_filter;
  4. pub fn main () {
  5. // Create a database and add some games
  6. let mut db = pgn_filter::Games::new();
  7. db.add_games("examples/twic1356.pgn").unwrap();
  8. // Display some information
  9. println!("Database has {} game(s)", db.iter().count());
  10. // Create a position definition for 5-4 rook endings
  11. let filter = pgn_filter::Board::must_have()
  12. .exactly(1, "R")
  13. .exactly(1, "r")
  14. .exactly(5, "P")
  15. .exactly(4, "p");
  16. // Extract those games which at some point reach
  17. let selected = db.search(&filter);
  18. selected.to_file("rook-endings.pgn").unwrap();
  19. // Report and save result
  20. println!("Selected {} out of {} games", selected.iter().count(), db.iter().count());
  21. }