1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
use crate::bitboard::*; use crate::constants::*; use crate::piece::*; use crate::square::*; use std::io::{self, BufRead}; pub struct Uci { pub engine_name: String, pub engine_author: String, } pub fn create_default_uci() -> Uci { Uci { engine_name: "rustengine".to_string(), engine_author: "easychessanimations".to_string(), } } pub fn demo() { let x: Bitboard = 0xffff00000000ffff; println!("{}", x.pretty_print_string()); let sq: Square = rank_file(RANK_3, FILE_D); println!("square {} file {} rank {}", sq.uci(), sq.file(), sq.rank()); let fig: Figure = LANCERNE; println!("\nfigure {} symbol {}", fig, fig.symbol()); let p: Piece = color_figure(WHITE, LANCERNE); println!( "\npiece {} fen symbol {} san symbol {} uci symbol {} san letter {}", p, p.fen_symbol(), p.san_symbol(), p.uci_symbol(), p.san_letter() ); let mut bb: Bitboard = sq.bitboard() | SQUARE_G6.bitboard(); loop { println!("\n{}", bb.pretty_print_string()); let (sq, ok) = bb.pop_square(); if ok { println!("{}", sq.uci()); } else { println!("no square could be popped\n"); break; } } println!( "{}", jump_attack(SQUARE_E4, &KNIGHT_DELTAS, SQUARE_F6.bitboard()).pretty_print_string() ); println!( "{}", sliding_attack(SQUARE_E4, &QUEEN_DELTAS, SQUARE_G6.bitboard()).pretty_print_string() ); println!("{}", BISHOP_ATTACK[SQUARE_C7].pretty_print_string()); println!("{}", KING_AREA[SQUARE_G8].pretty_print_string()); } pub fn enum_occup_demo() { let occup = BISHOP_ATTACK[SQUARE_C7]; let mut mask: usize = 0; loop { if mask < occup.variation_count() { println!( "{}\n{}", mask, translate_mask_to_occupancy(mask, occup).pretty_print_string() ); mask += 1; } else { break; } } } pub fn mobility_demo() { println!( "{}", queen_mobility( MoveGenMode::All, SQUARE_E4, SQUARE_G6.bitboard() | SQUARE_C4.bitboard(), SQUARE_D5.bitboard() | SQUARE_E7.bitboard() ) .pretty_print_string() ) } pub fn magic_space() { let tb = total_magic_space(BISHOP_MAGICS); let sb = tb * std::mem::size_of::<Bitboard>(); println!("total bishop magic space {} bytes", sb); let tr = total_magic_space(ROOK_MAGICS); let sr = tr * std::mem::size_of::<Bitboard>(); println!("total rook magic space {} bytes", sr); println!( "\ngrand total magic space {} bytes = {:0.2} MiBs", sb + sr, (sb + sr) as f32 / 1e6 ); println!("magic units bishop {} rook {} total {}", tb, tr, tb + tr); } impl Uci { pub fn process_uci_command(&self, line: String) -> bool { let parts: Vec<&str> = line.split(" ").collect(); let command = parts[0]; if command == "quit" || command == "q" || command == "exit" || command == "x" { return false; } if command == "demo" { let mut arg = ""; if parts.len() > 0 { arg = parts[0]; } match arg { "occup" => enum_occup_demo(), "mob" => mobility_demo(), "space" => magic_space(), _ => demo(), } } true } pub fn welcome(&self, build_info: &str) { println!( "{} bitboard multi variant uci chess analysis engine by {} [ {} ]", self.engine_name, self.engine_author, build_info ); } pub fn uci_loop(&self) { let stdin = io::stdin(); for line in stdin.lock().lines() { if !self.process_uci_command(line.unwrap()) { break; } } } }