//////////////////////////// D A B B A B A //////////////////////////// #define MET1 #define noMET2 #define noCOMPACT #define noCHECKHASH #define noHASHDOUBLECHECK #define noTVHASH #define noMENUPOSITIONS #define MINIMAINMENU not-used-yet #define EVERPLAY not-used-yet #define SPECOPTIONS not-used-yet #define noVARIANTS #define MENU4TXT #define noEXTINCT #define noQUIETEXPERIMENT // bem‘rk ant.sel.ply i mellemtiden er ‘ndret fra 8 til 6..... #define noONLYFORJENS #define noCHECKJENSPCTIME #define noCHECKALL #define noCHECKSQAVOID #define MENUDIV #define noBREAKPOINT #define noFILTRACE #define noFILTRACEMOVES #define noSCHOOP #define PLAYEARLYGAMEFAST #define noRANDOM4 #define noRANDOM16 #define noRANDOMOFF #define noSAMERANDOM #define noDAB4KORR // used for easier play of e-mailgames #define BLANKHAPPENS // blank tracemarks on the time-line #define noPREVAL #define PREVALPLYTRACE 1 // 1,(2,3).... se b-prevalue-moves() #define noHIDEINFO // omits score, mainline and pb-move on the screen for 'even play' #define PBSILLY // :ok og :bad i games.txt affects play! #define USEBESTMOVE1 // *stop *ok *mob=0 i games.txt affects play! #define CHECKBESTMOVE1 // 2 tr‘k i games.txt n†r de ikke er ens... happens[8] #define GUESSED // note n†r Dabbaba har g‘ttet modstanderens tr‘k #define MSGOOD // note i games.txt n†r Dabbaba har fundet noget godt i matesearch #define TRACEMONITORANDGO #include "time.h" #include "math.h" #include "stdio.h" #include "stdlib.h" #include "string.h" #include "ctype.h" //#include //#include #include //#include #include //#include #define a1 21 #define b1 22 #define c1 23 #define d1 24 #define e1 25 #define f1 26 #define g1 27 #define h1 28 #define a2 31 #define b2 32 #define c2 33 #define d2 34 #define e2 35 #define f2 36 #define g2 37 #define h2 38 #define a3 41 #define b3 42 #define c3 43 #define d3 44 #define e3 45 #define f3 46 #define g3 47 #define h3 48 #define a4 51 #define b4 52 #define c4 53 #define d4 54 #define e4 55 #define f4 56 #define g4 57 #define h4 58 #define a5 61 #define b5 62 #define c5 63 #define d5 64 #define e5 65 #define f5 66 #define g5 67 #define h5 68 #define a6 71 #define b6 72 #define c6 73 #define d6 74 #define e6 75 #define f6 76 #define g6 77 #define h6 78 #define a7 81 #define b7 82 #define c7 83 #define d7 84 #define e7 85 #define f7 86 #define g7 87 #define h7 88 #define a8 91 #define b8 92 #define c8 93 #define d8 94 #define e8 95 #define f8 96 #define g8 97 #define h8 98 #define equal == #define or || #define exor ^ #define and && #define false 0 #define true 1 #define no_good_found 22222 #define int_min -30000 #define int_max +30000 int mate_ply; // used for taking an extra iteration when a mate is found // hoping to see a shorter mate and get the game finished... int port=0; // bruges af auto232 int save_games=false; // skal filen games.txt dannes char p99[99]; // tekster editeres over i dette felt og udskrives int sqwidth=35; int hvid=1, boardcolor; int board_x, board_y=10; // br‘ttets ›verste venstre hj›rne ('nordvest') int square_x, square_y; char ch, nr[2]; int /*gdriver=VGA, gmode=VGAHI,*/ errorcode; int xi, yi, r; // bruges i computer-and-display og computer-x()..... int gem_full_evalu; int q_test, keyboard_stop, time_stop; int it_out, move_out; /* udskriv hvor dyb en s›gning der blev lavet */ int noprint=false; int sound_on=false; int evermoves_160=160; int mpc=0; //move-ply-count //int draw50move=0; // draw by 50 move rule //int hnode; // skal slettes igen..... double mslim[5]; /* mate-search limits (mslim[0] is last ply)*/ signed char wbauern[10]; /* Anzahl der weisse Bauern auf einer Linie */ signed char wtuerme[10]; /* Anzahl der weisse Tuerme auf einer Linie */ signed char sbauern[10]; /* Anzahl der schwarze Bauern auf einer Linie */ signed char stuerme[10]; /* Anzahl der schwarze Tuerme auf einer Linie */ int limitpawnscore, pawninfo=false; int wpawn=4; int quiet_depth=1; double pawnexceed=0, totalexcd=0; int speedfactor; // is 10 on a 50 mhz 486 double pctid; double startmovetime; int tpct_it_zero; // how many pct of the time was spent in the matesearch signed char chess_variant; #define normal 0 #define stationary 1 #define knightmate 2 #define q_is_rn 3 #define q_is_bn 4 #define nightrider 5 #define knightwazir 6 #define knightferz 7 #define knightdabbaba 8 #define knightalfil 9 #define gridchess 11 #define pawnfreeze 12 #define more_goals 50 #define rooksquare 51 #define extinct 52 #define stop 111 /* denne bruges ogs† som stopklods i move_fr-array */ #define one_step 1 #define more_steps 7 char men_letter[9] ={'P', ' ', ' ', 'N', 'B', 'R', 'Q', 'K', '\0'}; //int nc_men_value[8] ={0, 0, 90, 300, 300, 475, 950, 6666}; int nc_men_value[8] ={0, 0, 100, 300, 305, 490, 1000, 6666}; signed char nc_king[20] ={one_step, -1, 9, 10, 11, 1, -9, -10, -11, stop }; signed char nc_queen[20] ={more_steps, -1, 9, 10, 11, 1, -9, -10, -11, stop}; signed char nc_rook[20] ={more_steps, -1, 10, 1, -10, stop}; signed char nc_bishop[20] ={more_steps, 9, 11, -9, -11, stop}; signed char nc_knight[20]={one_step, 8, 19, 21, 12, -8, -19, -21, -12, stop}; signed char wazir[5] ={ -1, +10, +1, -10, stop}; signed char ferz[5] ={ -9, +11, +9, -11, stop}; signed char dabbaba[5] ={ -2, +20, +2, -20, stop}; signed char alfil[5] ={ -18, +22, +18, -22, stop}; int men_value[8]; signed char king[20]; signed char queen[20]; signed char rook[20]; signed char bishop[20]; signed char knight[20]; signed char *gangart; /* bruges som pointer i ovenstående 5 arrays */ //char fatal_tekst[60]; /* hop ud af programmet med denne meddelelse.. */ signed char gen_moves_mode; #define move_and_attack 2 #define only_attack 1 signed char status, normal_game=0, monitor=1, autoplay=2, self_play=3, everplay=4; signed char gameplay_info=false; char *arr1; // f›rste pr›ve p† hashtables... signed char w_antselply=0; signed char ant_sel_ply; /* antal selektive ply i en iteration. */ signed char last_sel_ply=4; /* antal selektive ply i sidste iteration*/ signed char first_sel_ply; /* tidligst mulige selektive ply */ signed char sel_ply_now; /* true/false: er dette ply selektivt */ signed char iteration; /* dybde igangv‘rende iteration */ signed char sgn_wh_bl; /* 1/-1. 1 if white when ply==iteration */ signed char last_iteration=4; /* dybde sidste iteration */ signed char only_recapture; /* skal kun generobringer pr›ves */ int iterativ=1; /* +1 = der k›res iterativ s›gning */ int s_kill=3; /* 0=bruges ikke; */ int always_cut=1; /* +1 = ja, 0 = nej, 2 = auto */ int always; /* +1 = ja, 0 = nej */ int check_search=0; /* depth in ply */ int gem_check_search; /* depth in ply */ //long mate_ search; /* number of positions */ int mate_search=10; /* number of positions in 1000's */ //int swrepeat4; /* */ int wrand=8; /* */ int magic=0; /* funny and test purposes.... */ int qdynamic; /* gr‘nse for udl›sning af quiet move... */ int it4_qdyn=50; /* qdynamic i 4. iteration. */ int skift=1; /* +1 = initiativ kan skifte i sel search*/ int full_evalu=1; /* +1 = yes. 0=no=only materiel */ int wmobil=16; /* v‘gt for mobilitet */ int wcentr=4; /* v‘gt for centralisering */ int wopen=8; /* v‘gt for †bningstips */ int wkingsaf=8; /* v‘gt for king safety */ int bishoppair=30; int king_centre=1; // king in centre in early endgame int king_corner=1; // get opponents king into the corner int Q_near_enemy_K=1; // int rook_placement=1; // int exchf=50; // exchange factor int filtrace; /* true/false */ int gameplay=false; /* true/false */ int dummy_search=false; // to avoid best-move-so-far in dummy-search int info_out=1; /* +1 = vis informationer p† sk‘rmen */ //int top_kill; /* +1 = brug top_kill */ int black_8; /* antal originale sorte brikker p† 8. r‘kke */ int matesearch_score, matelvl_score; signed char matelvl_stop=true; int maxpawn=0; int vu; int whole_menu=false; signed char intern_a=32; signed char intern_b=64; signed char intern; signed char intern_c=7; signed char intern_d=15; const signed char grid[h8+1] = { /** A B C D E F G H **/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, /* A1 ... H1 */ 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, /* A2 ... H2 */ 0, 5, 5, 6, 6, 7, 7, 8, 8, 0, /* A3 ... H3 */ 0, 5, 5, 6, 6, 7, 7, 8, 8, 0, /* A4 ... H4 */ 0, 9, 9, 10, 10, 11, 11, 12, 12, 0, /* A5 ... H5 */ 0, 9, 9, 10, 10, 11, 11, 12, 12, 0, /* A6 ... H6 */ 0, 13, 13, 14, 14, 15, 15, 16, 16, 0, /* A7 ... H7 */ 0, 13, 13, 14, 14, 15, 15, 16, 16}; /* A8 ... H8 */ const int centrum[h8+1] = { /** A B C D E F G H **/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 8, 12, 12, 8, 0, 4, 0, /* A1 ... H1 */ 0, 4, 8, 12, 16, 16, 12, 8, 4, 0, /* A2 ... H2 */ 0, 8, 12, 16, 20, 20, 16, 12, 8, 0, /* A3 ... H3 */ 0, 12, 16, 20, 24, 24, 20, 16, 12, 0, /* A4 ... H4 */ 0, 12, 16, 20, 24, 24, 20, 16, 12, 0, /* A5 ... H5 */ 0, 8, 12, 16, 20, 20, 16, 12, 8, 0, /* A6 ... H6 */ 0, 4, 8, 12, 16, 16, 12, 8, 4, 0, /* A7 ... H7 */ 0, 4, 0, 8, 12, 12, 8, 0, 4}; /* A8 ... H8 */ /** *** Bewertung der Felder fuer Bauern. *** Wird in Stellungsbewertung verwendet. **/ //const int wBFeldWert[h8]= { /* weisse Bauern */ ///** A B C D E F G H **/ // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A1..H1 (nicht moeglich) */ // /* Zentrumsbauern sind auf 2-ter Reihe schlecht (gehoeren nach vorne) */ // /* f-h Bauern sollen wegen Koenigsschutz hinten bleiben */ // 0, 4, 4, 0, 0, 0, 6, 6, 6, 0, // 0, 6, 6, 8, 8, 8, 4, 6, 6, 0, /* A3 ... H3 */ // 0, 8, 8, 16, 22, 22, 4, 4, 4, 0, /* A4 ... H4 */ // 0, 10, 10, 20, 26, 26, 10, 10, 10, 0, /* A5 ... H5 */ // 0, 12, 12, 22, 28, 28, 14, 14, 14, 0, /* A6 ... H6 */ // 0, 18, 18, 28, 32, 32, 20, 20, 20}; /* A7 ... H7 */ // /* Auf 8-ter Reihe kann kein Bauer stehen */ //const int sBFeldWert[h8]= { /* schwarze Bauern */ ///** A B C D E F G H **/ // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* A1..H1 (nicht moeglich) */ // 0, 18, 18, 28, 32, 32, 20, 20, 20, 0, /* A2 ... H2 */ // 0, 12, 12, 22, 28, 28, 14, 14, 14, 0, /* A3 ... H3 */ // 0, 10, 10, 20, 26, 26, 10, 10, 10, 0, /* A4 ... H4 */ // 0, 8, 8, 16, 22, 22, 4, 4, 4, 0, /* A5 ... H5 */ // 0, 6, 6, 8, 8, 8, 4, 6, 6, 0, /* A6 ... H6 */ // 0, 4, 4, 0, 0, 0, 6, 6, 6}; /* A7 ... H7 */ // /* Auf 8-ter Reihe kann kein Bauer stehen */ signed char attack_w_min[h8+2]; /* mindste hvide brik der truer et felt */ signed char attack_b_min[h8+2]; /* mindste sorte brik der truer et felt */ signed char attack_w_nul[h8+2]; /* nulstiller attack_w_min */ signed char attack_b_nul[h8+2]; /* nulstiller attack_b_min */ signed char tablin[h8+1]; /* table of lines e7=5; b4=2 etc. */ signed char tabrow[h8+1]; /* table of rows e7=7; b4=4 etc. */ char xxx[162]; /* her l‘ses den stilling, der startes med */ char gem_xxx[162]; signed char ply, ply_1; /* ply, ply minus en, ply minus to */ signed char wh_bl; #define white 1 #define black -1 signed char sq[120+78]; // her er skakbr‘ttet som 10xi2 + pb_pos signed char *sq_idx, *sq_idx2; /* disse pointere bruges på skakbrættet */ /* brættes felter (sq) kan indeholde disse værdier: */ #define w_p 2 /* white pawn o.s.v. */ #define w_n 3 #define w_b 4 #define w_r 5 #define w_q 6 #define w_k 7 #define b_p -2 #define b_n -3 #define b_b -4 #define b_r -5 #define b_q -6 #define b_k -7 #define sq_empty -1 #define sq_illegal 1 /* udenfor 8x8 brættet */ /* >=w_p er en hvid brik; <=b_p er en sort brik */ #define prom_q_9 111 /* ved bondeforvandling indeholder til-feltet en */ #define prom_r_9 112 /* af disse v‘rdier. */ #define prom_b_9 113 /* Forvandling er til q,r,b,n, og det sker p† */ #define prom_n_9 114 /* feltet = fra-felt + 9/10/11. */ #define prom_q_10 116 /* (For sort tr‘kker man 9/10/11 fra) */ #define prom_r_10 117 #define prom_b_10 118 #define prom_n_10 119 #define prom_q_11 121 #define prom_r_11 122 #define prom_b_11 123 #define prom_n_11 124 #define ANTSELPLY 2 #define DRAWPLY 3 #define max_ply 32 #define m_ply max_ply+4 // normalt kun +1....... #define opening_limit 2 #define endgame_limit 7966 #define allowed 1 #define not_allowed 0 typedef struct {signed char fr; signed char to; } move; move wmove; typedef char *string_t; signed char quiet; // is a position quiet? true or false. #define GAME_MAXINDEX 102 unsigned long int game_id [GAME_MAXINDEX+1]; unsigned long int game_idx[GAME_MAXINDEX+1]; int game_pointer=-1; typedef struct {unsigned long int hash_id; unsigned long int hash_idx; signed char hash_fr; signed char hash_to; signed int hash_score; // 30222==none signed char hash_score_final; // true or false signed char hash_depth; signed char hash_ply; unsigned char hash_mpc; } hash_struct; //unsigned long int asdfadsf[4096]; //unsigned long int bsdfadsf[4096]; //unsigned long int csdfadsf[4096]; //unsigned long int dsdfadsf[4096]; #ifdef COMPACT hash_struct compa[256]; #endif hash_struct hash; int hashint[8]; #ifdef _WIN32 #define far #endif int far *farp; int far *wfarp; int swhash=1; int swnullmove=1; unsigned long int uli_id, uli_idx, uli_id_index, hz, uli_sletigen; unsigned long int hash_maxindex=2048, hash_totbytes, uli_sletigenx; unsigned long int randi_id [h8+1][12]; unsigned long int randi_idx[h8+1][12]; //unsigned long int randy_id[21]; // b/w, 4xcastle, 2x8 e_p //unsigned long int randy_idx[21]; signed char plydyb; //, gemplydyb; signed char happens[20]={' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\0'}; // check if some events happens... typedef struct {signed char w_o_o; signed char b_o_o; signed char w_o_o_o; signed char b_o_o_o; signed char e_p; /* indeholder not-allowed eller a6 hvis der fx lige er spillet a7a5 */ signed char pawnchange; // pawns/rooks moved/captured--> true signed char draw50; // antal spillede tr‘k uden slag eller bondetr‘k unsigned long int hash_idx; unsigned long int hash_id; signed char swnullhash; } pp; pp p[m_ply]; signed char ms_fr, matelvl_fr; signed char ms_to, matelvl_to; #define max_moves_in_table 90 //int tpo2idx [max_moves_in_table]; /* pegepinde */ signed char sel_delay [m_ply]; /*"t‘ller forcerede ting i x-dele"*/ signed char first_dynamic_sel_ply [m_ply]; /* i hvilket ply starter sel. search */ signed char sel_side [m_ply]; /* white/black. hvem k›rer sel. search?*/ signed char nullmove [m_ply]; // signed char nullmovesq=a1; signed char last_ply; /* hvor dybt i ply g†r vi maksimalt ned?*/ signed char king_in_check [m_ply]; /* er kongen i skak? true/false */ signed char best_move_fr [m_ply]; signed char best_move_to [m_ply]; //int gem_best_score_0; /* bruges ved afbrydelse af et tr‘k*/ int most_recent_best_score; // -------------------------------- int gem_sel_vurd [m_ply]; // gem selektiv vurdering int best_score [m_ply]; // bruges i mini-max int mms [m_ply]; // rigtig mini-max score.... int start_best_score [m_ply]; /* nulstiller best_score */ int mate_score [m_ply]; int w_materiel [m_ply]; /* hvids materiel udover kongen */ int b_materiel [m_ply]; /* sorts materiel udover kongen */ int centre [m_ply]; /* acc. centralisering */ signed char mobilitet [m_ply]; /* udfyldes n†r tr‘kkene er dannet */ char realmoves [m_ply]; /* mobilitet minus pseudomoves */ double mate_sch_pos [m_ply]; /* mate search positions left */ int random_move; /* random moves in the opening */ //int mate_sch_pos [m_ply]; /* mate search positions left */ signed char move_fr_before [m_ply]; /* indholdet af from- og to-feltet */ signed char move_to_before [m_ply]; /* inden tr‘kket blev udf›rt */ signed char prt_fr [m_ply]; /* traekket i forrige udsk. variant*/ signed char prt_to [m_ply]; /* traekket i forrige udsk. variant*/ signed char full_line; /* styrer fuld/blank linie */ signed char move_pointer [m_ply]; /* peger p† n‘ste tr‘k */ signed char move_point; /* arbejdsindeks når der arbejdes i træktabellen */ signed char move_fr [m_ply][max_moves_in_table]; signed char move_to [m_ply][max_moves_in_table]; int move_value [m_ply][max_moves_in_table]; int oldpre_value [m_ply][max_moves_in_table]; /************** counters ******************/ double tv_nodes, tv_pseudo_moves, tv_cutoff, tv_printline, tv_last_ply; double tv_error, filtrc_error, tv_pat, tv_repeat, tv_allnodes=0; double tv_sessionmoves=0, tv_sessionmovetime=0; double tv_hash_read, tv_hash_read_ok, tv_hash_read_ok_final, tv_hash_nofinal; double tv_hash_hit; double tv_hash_skriv, tv_hash_opdat, tv_hash_ejskriv, tv_hash_error; int tv_non_sel_move; double w_ever, b_ever; double vurd_node; int gem_vurd; double maxmovetime=0; // max time for a move in the session double wtid, btid; // time in 1/100 sec used by w and b double msmax; // max number of nodes in matesearch #ifdef SCHOOP int gameinxmin=0; // zero or = minutes for the game int moves_inxmin=60; // used for x moves int min_forxmoves=60; // in y minutes #else int gameinxmin=5; // zero or = minutes for the game int moves_inxmin=0; // used for x moves int min_forxmoves=0; // in y minutes #endif int secprmove=0; int mateinx=0; // used for the mate-level int drucker=false; // AUTO232 on/off int startmateriel; // sum of materiel - 2*K in startposition int draw_score=0; //****************** permanent brain *********************** signed char pb_move_ready=false; signed char pb_move_fr; signed char pb_move_to; #ifdef PBSILLY signed char pb_sillyi_fr, pb_silly2_fr, pb_silly2w_fr; signed char pb_sillyi_to, pb_silly2_to, pb_silly2w_to; #endif signed char pb_on=false; signed char pb_time_used=false; signed char pb_sw_move_received=false; signed char pb_sw_move_guessed=false; double pb_opponents_time, pb_oppo_nodes; unsigned long int pb_count_bioskey; unsigned long int pb_count_limit; signed char pb_tv_1_4=0; signed char pb_move_received[20]; #define MSPCT 20 // max 20% of the time should be used in the matesearch double check_time_at_nodes; // when to do extra timecontrol char mark_nodesstop; // # indicates a brutal stop // disse felter bruges til at danne legale tr‘k n†r man er i skak signed char sq_avoid_check[h8+1]; /* true/false - hvilke felter skal man flytte til for at parere skakken */ signed char sq_checking_man; // hvor st†r den skakgivende brik // signed char checking_direction1; /* skakgivende retning mod kongen / nul */ signed char checking_direction2; /* ved dobbeltskakker den anden retning */ signed char sq_checked_king; /* hvor er den truede konge */ int w_insufmat, b_insufmat; int trace=-30000; FILE *fp; FILE *gi; // used for gameinfo.trc FILE *pgn; // used for games.txt #define normal_move 0 signed char make2_move_status=normal_move; #define pseudo_move 1 signed char make_move_status=normal_move; #define make_cut_off 2 #define score_is_found 3 signed char simple_kill1_fr [m_ply]; /* pr. ply gemmes tr‘k, der */ signed char simple_kill1_to [m_ply]; /* bevirker cut-off. */ int tv_s_kill1 [m_ply]; int simple_kill1_vu [m_ply]; /* hvor gode var killerne? */ int s_kill1_oldpre [m_ply]; /* killerens oprindelige preval*/ signed char simple_kill2_fr [m_ply]; /* i prevalue s‘ttes de */ signed char simple_kill2_to [m_ply]; /* foran andre tr‘k. */ int tv_s_kill2 [m_ply]; int simple_kill2_vu [m_ply]; /* hvor gode var killerne? */ int s_kill2_oldpre [m_ply]; /* killerens oprindelige preval*/ // ‘ndret fra 2000,5..... //#define kill_items 90 //#define kill_depth 2 //signed char kill_fr [kill_items][ kill_depth]; //signed char kill_to [kill_items][ kill_depth]; /* Best-Move-And-Score-So-Far */ /* i den første iteration eller to puttes kun data i indeks [0], da det er uinteressant at det bedste træk skifter mange gange her... Vha disse data kan man kalde frem, hvad programmet kom frem til under sine beregninger... De kan også bruges til Kaufman's 1-time test, hvor han giver point hvis programmet har fundet det rigtige efter 30, 60, 90 og 120 sekunder. (0 til 4 point pr. testposition) */ #define bmassf_max 10 /* signed char bmassf_idx; int bmassf_seconds [bmassf_max]; int bmassf_score [bmassf_max]; signed char bmassf_move_fr [bmassf_max]; signed char bmassf_move_to [bmassf_max]; */ /* ved test af stillinger skal man finde (evt. undg†) dette tr‘k */ signed char solution_fr; signed char solution_to; /* forvandling kan ikke umiddelbart klares endnu */ signed char solution_mark; /* indeholder ! eller ? - find/undg† dette træk */ signed char run_test=false; /* indeholder true eller false. K›rer vi test? */ signed char solution_xxx[51]; signed char filnavn[20]; double tid, timemovestart; int disctrace=false; int exitsolfound=false; signed char piliwq[13], piliwr[13], piliwb[13], piliwn[13], piliwp[13], sqwk; signed char pilibq[13], pilibr[13], pilibb[13], pilibn[13], pilibp[13], sqbk; // int tvpili; int two_kings; // value of two kings // Es wird der Text in 'text' ausgedruckt (til seriel port). void drucke_text(string_t text) { int i; for(i=0;text[i]!=0;i=i+1) putchar(text[i]);//biosprint(0,text[i],port); return; } // Druckt die Carriage-Return Linefeed Sequenz am Ende einer Zeile. void drucke_crlf(void) { char text[3]; // text[0]='\f'; // formfeed // text[0]='\n'; // linieskift // text[0]='\r'; // return tast // text[0]='\t'; // horisontal tabulering text[0]=13; // CR; text[1]=10; // LINEFEED; text[2]=0; drucke_text(text); } void break_point() { #ifdef BREAKPOINT int dum; if (iteration equal 4 and ply equal 4 and move_fr[0][move_pointer[0]]==f6 and move_to[0][move_pointer[0]]==e4 and move_fr[1][move_pointer[1]]==d2 and move_to[1][move_pointer[1]]==d3 and move_fr[2][move_pointer[2]]==d8 and move_to[2][move_pointer[2]]==a5 and move_fr[3][move_pointer[3]]==c1 and move_to[3][move_pointer[3]]==d2 // and move_fr[4][move_pointer[4]]==e8 // and move_to[4][move_pointer[4]]==f8 ) ++dum; //printf("s‘t breakpoint i denne linie..."); #endif } void press_a_k_t_c() { int dum; if (filtrace equal false) { dum = getch(); ++dum;} } void press_any_key_to_continue() { int dum; printf("\n Press any key to continue..."); dum = getch(); ++dum; } int bw_index(signed char sqman) { if (sqman>w_k or sqman b_p and sqman =a6) return randi_id[1][ 5+e_p-a6]; // else return randi_id[2][13+e_p-a3]; //} void read_hash(unsigned long int key) { //if (swhash equal 1) #ifdef COMPACT hash=compa[key]; #endif #ifdef MET1 {for (hz=0; hz<=7; ++hz) *(hashint+hz)=*(farp+key*8+hz); memcpy(&hash, hashint, 16); } #endif #ifdef MET2 {//wfarp=farp+key*sizeof(hash); movedata(FP_SEG((farp+key)), FP_OFF((farp+key)), FP_SEG(&hash), FP_OFF(&hash), sizeof(hash)); // wfarp=farp+key*sizeof(hash); // movedata(FP_SEG(hashint), FP_OFF(hashint), // FP_SEG(wfarp), FP_OFF(wfarp), // sizeof(hash)); // memcpy(&hash.hash_id, hashint, sizeof(hash)); } #endif } void write_hash(unsigned long int key) { //if (swhash equal 1) #ifdef COMPACT compa[key]=hash; #endif #ifdef MET1 {memcpy(hashint, &hash, 16); for (hz=0; hz<=7; ++hz) *(farp+key*8+hz)=*(hashint+hz); // memcpy(hashint, &hash.hash_id, sizeof(hash)); // wfarp=farp+key*sizeof(hash); // movedata(FP_SEG(wfarp), FP_OFF(wfarp), // FP_SEG(hashint), FP_OFF(hashint), // sizeof(hash)); } #endif #ifdef MET2 {//wfarp=farp+key*sizeof(hash); movedata(FP_SEG(&hash), FP_OFF(&hash), FP_SEG((farp+key)), FP_OFF((farp+key)), sizeof(hash)); // wfarp=farp+key*sizeof(hash); // movedata(FP_SEG(hashint), FP_OFF(hashint), // FP_SEG(wfarp), FP_OFF(wfarp), // sizeof(hash)); // memcpy(&hash.hash_id, hashint, sizeof(hash)); } #endif } void calculate_hashkey() { int x; uli_id=uli_idx=0; for (x=a1; x<=h8; ++x) {if (sq[x]>=w_p or sq[x]<=b_p) {uli_idx=uli_idx exor randi_idx[x][bw_index(sq[x])]; uli_id =uli_id exor randi_id [x][bw_index(sq[x])];} } if (wh_bl equal black) {uli_idx=uli_idx exor randi_idx[0][0]; uli_id =uli_id exor randi_id [0][0];} //if (p[ply].w_o_o !=allowed and p[ply].w_o_o ==allowed) uli_id=uli_id exor randy_id[1]; //if (p[ply].w_o_o_o!=allowed and p[ply].w_o_o_o==allowed) uli_id=uli_id exor randy_id[2]; //if (p[ply].b_o_o !=allowed and p[ply].b_o_o ==allowed) uli_id=uli_id exor randy_id[3]; //if (p[ply].b_o_o_o!=allowed and p[ply].b_o_o_o==allowed) uli_id=uli_id exor randy_id[4]; //uli_id=uli_id exor make_e_p_hash(p[ply_1].e_p); //uli_id=uli_id exor make_e_p_hash(p[ply].e_p); if (p[ply].e_p!=not_allowed) {uli_idx=uli_idx exor randi_idx[0][1]; uli_id =uli_id exor randi_id [0][1];} } void sort_pili(signed char *pili) // makes search in testpositions and gameplay identical... {signed char x, y, z, *p, *q; for (x=0; x<=8; ++x) {for (y=0, p=pili; y<=8; ++y) {q=p+1; if (*p<*q) {z=*q; *q=*p; *p=z;}; ++p; } } } void zero_to_pili(signed char *pili, signed char man) {signed char x, *p; p=pili; for (x=0; x<=11; ++x) {*p=0; ++p;} *p=man; } void add_to_pili(signed char *pili, signed char *sq) {*(pili+*(pili+11))=*sq; ++*(pili+11);} // in one statement....!? void change_to_pili(signed char *pili, signed char *sqfr, signed char *sqto) {signed char *p; p=pili; loop: if (*p!=*sqfr) {++p; goto loop;} // ++p in the if-statement....!? *p=*sqto; } void delete_from_pili(signed char *pili, signed char *sq) {signed char *p; p=pili; loop: if (*p!=*sq) {++p; goto loop;} // ++p in the if-statement....!? if (*(p+1) equal 0) {*p=0; --*(pili+11);} else {--*(pili+11); *p=*(pili+*(pili+11)); *(pili+*(pili+11))=0;} } void add_error() { ++tv_error; ++filtrc_error; printf(" ******* error ******* "); } int everplay_and_black() { if (status != everplay or intern equal white) return false; else return true;} void add_pili(signed char *sq, signed char *man) { if (*man>=w_p) { if (*man equal w_p) add_to_pili(piliwp, sq); else if (*man equal w_n) add_to_pili(piliwn, sq); else if (*man equal w_b) add_to_pili(piliwb, sq); else if (*man equal w_r) add_to_pili(piliwr, sq); else add_to_pili(piliwq, sq); } else { if (*man equal b_p) add_to_pili(pilibp, sq); else if (*man equal b_n) add_to_pili(pilibn, sq); else if (*man equal b_b) add_to_pili(pilibb, sq); else if (*man equal b_r) add_to_pili(pilibr, sq); else add_to_pili(pilibq, sq); } } void change_pili(signed char *sqfr, signed char *sqto, signed char *man) { #ifdef CHECKALL if (*man>w_k or *manb_p) ) {//print_line(); show_board(); //press_a_k_t_c(); add_error(); /*printf(" wh_bl in is-move-a-check... ");*/} #endif if (*man>=w_p) { if (*man equal w_p) change_to_pili(piliwp, sqfr, sqto); else if (*man equal w_k) sqwk=*sqto; else if (*man equal w_n) change_to_pili(piliwn, sqfr, sqto); else if (*man equal w_b) change_to_pili(piliwb, sqfr, sqto); else if (*man equal w_r) change_to_pili(piliwr, sqfr, sqto); else change_to_pili(piliwq, sqfr, sqto); } else { if (*man equal b_p) change_to_pili(pilibp, sqfr, sqto); else if (*man equal b_k) sqbk=*sqto; else if (*man equal b_n) change_to_pili(pilibn, sqfr, sqto); else if (*man equal b_b) change_to_pili(pilibb, sqfr, sqto); else if (*man equal b_r) change_to_pili(pilibr, sqfr, sqto); else change_to_pili(pilibq, sqfr, sqto); } } void change_castle_pili(signed char sq1, signed char sq2, signed char man) {if (sq1==h1 or sq1==h8 or sq1==a1 or sq1==a8) // make-move; not undo-move {uli_sletigenx=uli_sletigenx exor randi_idx[sq1][bw_index(man)]; uli_sletigen =uli_sletigen exor randi_id [sq1][bw_index(man)]; uli_sletigenx=uli_sletigenx exor randi_idx[sq2][bw_index(man)]; uli_sletigen =uli_sletigen exor randi_id [sq2][bw_index(man)]; } change_pili(&sq1, &sq2, &man); } void delete_pili(signed char *sq, signed char *man) { if (*man>=w_p) { if (*man equal w_p) delete_from_pili(piliwp, sq); else if (*man equal w_n) delete_from_pili(piliwn, sq); else if (*man equal w_b) delete_from_pili(piliwb, sq); else if (*man equal w_r) delete_from_pili(piliwr, sq); else delete_from_pili(piliwq, sq); } else { if (*man equal b_p) delete_from_pili(pilibp, sq); else if (*man equal b_n) delete_from_pili(pilibn, sq); else if (*man equal b_b) delete_from_pili(pilibb, sq); else if (*man equal b_r) delete_from_pili(pilibr, sq); else delete_from_pili(pilibq, sq); } } void print_line(); void undo_move(); void make_move(signed char *fr, signed char *to, int hop_ud); void skipgarbage() { while ( getchar() !='\n' ) {} } void scanf_char(signed char *ch) {scanf("%c",ch); skipgarbage();} void scanf_int(int *integer) {scanf("%d",integer); skipgarbage();} void scanf_string() {scanf("%s",xxx); skipgarbage();} double henttid() // returnerer antal hundreddele sekunder siden programstart... {return (double)(100*(clock())/CLK_TCK);} int timepctmovesofar() //{return ((tv_nodes / 30) / ((double)secprmove+1));} // => samme spil hver gang {return ((henttid()-timemovestart+pb_opponents_time) / ((double)secprmove+1));} void p99_secsofar() {sprintf(p99,"\n %8.2f sec. ", (henttid()-timemovestart)/100);} //void writessf(pointer peger) hvordan overf›res file-pointer.....???? //{p99_secsofar(); fprintf(peger, p99);} void writesecsofar_gi() {p99_secsofar(); fprintf(gi,p99);} void writesecsofar() {p99_secsofar(); fprintf(fp,p99);} void make_delay(float delay) { float y; y=henttid(); for (; y+delay>henttid(); ) {} } int count_black_8_row() { int x=0; if (sq[a8] equal b_r) ++x; if (sq[h8] equal b_r) ++x; if (sq[b8] equal b_n) ++x; if (sq[g8] equal b_n) ++x; if (sq[c8] equal b_b) ++x; if (sq[f8] equal b_b) ++x; if (sq[d8] equal b_q) ++x; if (sq[e8] equal b_k) ++x; return x; } void is_castle_allowed() { #ifdef VARIANTS if (chess_variant==knightmate or chess_variant==stationary) {p[0].w_o_o=not_allowed; p[0].w_o_o_o=not_allowed; p[0].b_o_o=not_allowed; p[0].b_o_o_o=not_allowed; } #endif } void normal_chess() { chess_variant=normal; memcpy(men_value, nc_men_value, 16); memcpy(king, nc_king, 20); memcpy(queen, nc_queen, 20); memcpy(rook, nc_rook, 20); memcpy(bishop, nc_bishop, 20); memcpy(knight, nc_knight, 20); } int find_move_index(signed char *fr, signed char *to) {int x=0; loop: //#ifdef CHECKALL if (x>200) { #ifdef ONLYFORJENS printf("\nLooooooooooop! find-move-index\n\n"); press_any_key_to_continue(); #endif happens[10]='0'; return -1;} //#endif if (*fr equal move_fr [0][x] and *to equal move_to [0][x]) return x; ++x; goto loop; } void beep() {printf("\a");} void sq120_to_koordinat(signed char *ch1, signed char *ch2, signed char *ch3) /* 31 (a2) => 2(r‘kke) 1(linie) */ {*ch3=(*ch1 - 10) / 10; *ch2=*ch1 - 10 - (10 * *ch3);} void p99_a1_h8(signed char *ch1) // danner fx 'c8' hvis funktionen bliver kaldt med signed char = 93 {signed char ch2, ch3; sq120_to_koordinat(ch1, &ch2, &ch3); sprintf(p99,"%c%c",'a' - 1 + ch2, '0' + ch3); p99[2]=0; } void print_a1_h8(signed char *ch1) {p99_a1_h8(ch1); printf(p99);} void sprint_a1_h8(signed char *ch1) {p99_a1_h8(ch1); drucke_text(p99);} void pgn_a1_h8(signed char *ch1) {p99_a1_h8(ch1); fprintf(pgn,p99);} void skiftfarve() { #ifndef _WIN32 if (hvid==1) {hvid=0; setfillstyle(SOLID_FILL,BLACK);} else {hvid=1; setfillstyle(SOLID_FILL,WHITE);} #endif } void rammefirkant(int x, int y, int x2, int y2) // firkant med sort ramme { #ifndef _WIN32 if (hvid==1) {bar(x+1, y+1, x2-1, y2-1); setcolor(BLACK); rectangle(x, y, x2, y2); } else bar(x, y, x2, y2); if (magic equal 8) make_delay(10); #endif } void draw_box(int x, int y, int lx, int ly) // tegn firkant i feltet { rammefirkant(square_x+((x) *sqwidth/25), square_y-((y+ly)*sqwidth/25), square_x+((x+lx)*sqwidth/25), square_y-((y) *sqwidth/25)); if (magic equal 8) make_delay(10); } void draw_p() // brikkernes udseende { draw_box(7,7, 10,2); draw_box(9,9, 6,7); } void draw_b() { draw_box(5,3, 14,3); draw_box(10,6, 4,14); } void draw_n() { draw_box(5,3, 14,3); draw_box(11,6, 5,9); draw_box(7,15, 9,3); } void draw_r() { draw_box(6,5, 12,5); draw_box(9,10, 6,5); draw_box(7,15, 10,4); } void draw_q() { draw_box(6,3, 12,5); draw_box(4,10, 3,11); draw_box(10,10, 4,7); draw_box(17,10, 3,11); } void draw_k() { draw_box(6,3, 12,5); draw_box(4,10, 7,8); draw_box(13,10, 7,8); draw_box(11,20, 2,2); } int square_colour(signed char *sq) { if ((tablin[*sq] % 2) equal (tabrow[*sq] % 2)) return black; else return white; } void show_board() { signed char w1_char, w2_char, w3_char, man, pb_offset; //int wint; if (pb_on equal true) pb_offset=99; else pb_offset=0; setcolor(boardcolor); for (yi=1; yi<50; ++yi) // en ramme om br‘ttet tegnes { #ifndef _WIN32 if (yi equal 5) setcolor(BLACK); rectangle(board_x-yi, board_y-yi, board_x+yi+8*sqwidth-1, board_y+yi+8*sqwidth-1); #endif } for (w1_char=a1; w1_char<=h8; w1_char++) // br‘ttets felter l›bes igennem {if (sq[w1_char]!=sq_illegal) {//wint=w1_char+pb_offset; man=sq[wint]; man=sq[w1_char+pb_offset]; sq120_to_koordinat(&w1_char, &w2_char, &w3_char); xi=w2_char-1; yi=7-(w3_char-1); #ifndef _WIN32 if (square_colour(&w1_char) equal white) setfillstyle(SOLID_FILL,LIGHTGRAY); else setfillstyle(SOLID_FILL,DARKGRAY); #endif square_x=board_x+(xi*sqwidth); // feltet 'nordvest' square_y=board_y+(yi*sqwidth); bar(square_x, // feltet tegnes square_y, square_x+sqwidth-1, square_y+sqwidth-1); if (magic equal 8) make_delay(10); square_y+=sqwidth; // feltet 'sydvest' skiftfarve(); // tilbage til sort/hvid if (man!=sq_empty) {if ((man>=w_p and hvid==0) or (man<=b_p and hvid==1)) skiftfarve(); if (man equal w_q or man equal b_q) draw_q(); if (man equal w_k or man equal b_k) { #ifdef VARIANTS if (chess_variant==knightmate) draw_n(); else #endif draw_k();} if (man equal w_r or man equal b_r) draw_r(); if (man equal w_b or man equal b_b) draw_b(); if (man equal w_n or man equal b_n) { #ifdef VARIANTS if (chess_variant==knightmate) draw_k(); else #endif draw_n();} if (man equal w_p or man equal b_p) draw_p(); } } } #ifndef _WIN32 setcolor(RED); // br‘ttets koordinater s‘ttes p† #endif for (xi=0, nr[1]='\0', *nr='a'; xi<8; ++xi,++nr[0]) outtextxy(board_x+xi*sqwidth+(10*sqwidth/25), board_y+(208*sqwidth/25), nr); for (yi=0, nr[1]='\0', *nr='8'; yi<8; ++yi,--nr[0]) outtextxy(board_x-(15*sqwidth/25), board_y+yi*sqwidth+(10*sqwidth/25), nr); } void print_kqrbnp(signed char ch1) /* printer 'K' hvis input = 7(w_k), 'D' ved 6 o.s.v. */ {signed char poschar; poschar=ch1; if (poschar < 0) poschar= -1 * poschar; printf("%1c",men_letter[poschar]); } void change_black_white() {if (wh_bl equal white) wh_bl = black; else wh_bl = white; } void unpack_promotion(signed char *to, signed char *to_9_10_11, signed char *promote_piece) {switch (*to) {case prom_q_10 : *to_9_10_11=10; *promote_piece=w_q; break; case prom_q_9 : *to_9_10_11=9 ; *promote_piece=w_q; break; case prom_q_11 : *to_9_10_11=11; *promote_piece=w_q; break; case prom_n_10 : *to_9_10_11=10; *promote_piece=w_n; break; case prom_n_9 : *to_9_10_11=9 ; *promote_piece=w_n; break; case prom_n_11 : *to_9_10_11=11; *promote_piece=w_n; break; case prom_r_10 : *to_9_10_11=10; *promote_piece=w_r; break; case prom_r_9 : *to_9_10_11=9 ; *promote_piece=w_r; break; case prom_r_11 : *to_9_10_11=11; *promote_piece=w_r; break; case prom_b_10 : *to_9_10_11=10; *promote_piece=w_b; break; case prom_b_9 : *to_9_10_11=9 ; *promote_piece=w_b; break; case prom_b_11 : *to_9_10_11=11; *promote_piece=w_b; break; } } int pre_val(int x) { if (s_kill equal 2) {if (x equal +150 and simple_kill1_vu[ply]>(int_max-100)) return simple_kill1_vu[ply]; if (x equal -150 and simple_kill1_vu[ply]<(int_min+100)) return simple_kill1_vu[ply]; if (x equal +120 and simple_kill2_vu[ply]>(int_max-100)) return simple_kill2_vu[ply]; if (x equal -120 and simple_kill2_vu[ply]<(int_min+100)) return simple_kill2_vu[ply]; } if (ply<2) return (x/3); else return x; } void w_prevalue_moves() {int man, w_min, b_min, pre_value; signed char fr, to, to_9_10_11, promote_piece; signed char s_kill1_fr, s_kill1_to, s_kill2_fr, s_kill2_to; /* signed char top_kill_fr, top_kill_to; int x; if (ply equal 1 and iteration>0) {x=find_move_index(&move_fr[0] [move_pointer[0]], &move_to[0] [move_pointer[0]]); #ifdef CHECKALL if (x>4000) {//printf("\nLooooooooooop!-w-prevalue-moves!!\n\n"); //press_any_key_to_continue(); top_kill_fr=0;} else #endif {top_kill_fr=kill_fr[x][0]; top_kill_to=kill_to[x][0];} } else top_kill_fr=0; if (top_kill != 1) top_kill_fr=0; */ s_kill1_fr=simple_kill1_fr[ply]; s_kill1_to=simple_kill1_to[ply]; s_kill2_fr=simple_kill2_fr[ply]; s_kill2_to=simple_kill2_to[ply]; if (s_kill==0) {s_kill1_fr=0; s_kill2_fr=0;} for (move_point=0; move_fr[ply][move_point] != stop; ++move_point) {fr=move_fr[ply][move_point]; to=move_to[ply][move_point]; if (fr equal hash.hash_fr and to equal hash.hash_to) {pre_value=int_max+2; ++tv_hash_hit; if (info_out==1 and ply==1) printf("hash-kill="); goto w_pre_slut;} // if (fr equal top_kill_fr and to equal top_kill_to) // {pre_value=int_max+1; if (info_out==1) printf("top-kill="); // top_kill_fr=1; goto w_pre_slut;} /* skal fjernes igen */ // check denne goto......... if (attack_w_min[to]>=w_p) pre_value=+5; else pre_value=0; if (to>h8) {unpack_promotion(&to, &to_9_10_11, &promote_piece); to=fr + to_9_10_11; man=300; if (promote_piece equal w_q) pre_value += 100; if (promote_piece equal w_n) pre_value += 100; else pre_value += 50; } else man=men_value[sq[fr]]; /* værdi af brik, der flyttes */ if (iteration>0) { if (man != men_value[w_k] and attack_b_min[fr]>=b_k) {b_min= men_value[0-(attack_b_min[fr]) ]; if (attack_w_min[fr]>w_k) w_min=0; else w_min=men_value[attack_w_min[fr]]; if (w_min equal 0) pre_value += man; else if ((man + w_min) > b_min) {pre_value += ((man - 10)/4 ); if (w_min < b_min) pre_value += ((b_min - w_min) /4 ); } }; } if (attack_b_min[to]>=b_k) {b_min= men_value[0-(attack_b_min[to]) ]; if (attack_w_min[to]>w_k) w_min=0; else w_min=men_value[attack_w_min[to]]; if (w_min equal 0 or w_min equal man) pre_value -= man; else if ((man /*+ w_min*/) > b_min) pre_value += (b_min - man /*- w_min - 10*/); }; if (sq[to] != sq_empty) pre_value += men_value[0-(sq[to])]; w_pre_slut: oldpre_value[ply][move_point]=pre_value; if (fr equal s_kill1_fr and to equal s_kill1_to) // and (simple_kill1_vu[ply]>int_max-100 { if (pre_value+50>s_kill1_oldpre[ply] and s_kill>=3) // ) {if (simple_kill1_vu[ply]>(int_max-100)) pre_value=simple_kill1_vu[ply]; else pre_value=simple_kill1_vu[ply] /* hvad med pat m.m....?) */ -w_materiel[ply]+b_materiel[ply] +50+(s_kill1_oldpre[ply]/3) ; // goto w_pre_slut; } else pre_value+=pre_val(+150); } // {pre_value+=s_kill /*simple_kill1_vu[ply]*/;/* goto w_pre_slut;*/} if (fr equal s_kill2_fr and to equal s_kill2_to) // and (simple_kill2_vu[ply]>int_max-100 { if (pre_value+50>s_kill2_oldpre[ply] and s_kill>=3) // ) {if (simple_kill2_vu[ply]>(int_max-100)) pre_value=simple_kill2_vu[ply]; else pre_value=simple_kill2_vu[ply] /* hvad med pat m.m....?) */ -w_materiel[ply]+b_materiel[ply] +30+(s_kill2_oldpre[ply]/3) ; // goto w_pre_slut; } else pre_value+=pre_val(+120); } // {pre_value+=s_kill-1 /*simple_kill2_vu[ply]*/;/*goto w_pre_slut;*/} move_value[ply][move_point]=pre_value; } // if (ply==1 and top_kill_fr !=1 and // iteration>2) // {if (info_out==1) printf(" no-topkill ");} } void b_prevalue_moves() {int man, w_min, b_min, pre_value; signed char fr, to, to_9_10_11, promote_piece; signed char s_kill1_fr, s_kill1_to, s_kill2_fr, s_kill2_to; /* signed char top_kill_fr, top_kill_to; int x; if (ply equal 1 and iteration>0) {x=find_move_index(&move_fr[0] [move_pointer[0]], &move_to[0] [move_pointer[0]]); #ifdef CHECKALL if (x>4000) {//printf("\nLooooooooooop!-b-prevalue-moves!!\n\n"); for (x=0; x<20; ++x) {printf("\n"); print_a1_h8(&move_fr[0] [x]); print_a1_h8(&move_to[0] [x]); printf("\n"); press_any_key_to_continue(); } x=4001; // press_any_key_to_continue(); top_kill_fr=0;} else #endif {top_kill_fr=kill_fr[x][0]; top_kill_to=kill_to[x][0];} } else top_kill_fr=0; if (top_kill != 1) top_kill_fr=0; */ s_kill1_fr=simple_kill1_fr[ply]; s_kill1_to=simple_kill1_to[ply]; s_kill2_fr=simple_kill2_fr[ply]; s_kill2_to=simple_kill2_to[ply]; if (s_kill==0) {s_kill1_fr=0; s_kill2_fr=0;} #ifdef PREVAL if (ply equal PREVALPLYTRACE) { printf("\n kill-1="); print_a1_h8(&s_kill1_fr); print_a1_h8(&s_kill1_to); printf(" oldpre=%d",s_kill1_oldpre[ply]); printf(" vu=%d",simple_kill1_vu[ply]); printf(" tv=%d",tv_s_kill1[ply]); printf("\n kill-2="); print_a1_h8(&s_kill2_fr); print_a1_h8(&s_kill2_to); printf(" oldpre=%d",s_kill2_oldpre[ply]); printf(" vu=%d",simple_kill2_vu[ply]); printf(" tv=%d",tv_s_kill2[ply]); } #endif for (move_point=0; move_fr[ply][move_point] != stop; ++move_point) {fr=move_fr[ply][move_point]; to=move_to[ply][move_point]; if (fr equal hash.hash_fr and to equal hash.hash_to) {pre_value=int_min-2; ++tv_hash_hit; if (info_out==1 and ply==1) printf("hash-kill="); goto b_pre_slut;} // if (fr equal top_kill_fr and to equal top_kill_to) // {pre_value=int_min-1; if (info_out==1) printf("top-kill="); // top_kill_fr=1; goto b_pre_slut;} /* skal fjernes igen */ if (attack_b_min[to]<=b_p) pre_value=-5; else pre_value=0; if (to>h8) {unpack_promotion(&to, &to_9_10_11, &promote_piece); to=fr - to_9_10_11; man=300; if (promote_piece equal w_q) pre_value -= 100; if (promote_piece equal w_n) pre_value -= 100; else pre_value -= 50; } else man=men_value[0-(sq[fr])]; /* v‘rdi af brik, der flyttes */ if (iteration>0) { if (man != men_value[w_k] and attack_w_min[fr]<=w_k) {w_min= men_value[attack_w_min[fr] ]; if (attack_b_min[fr] w_min) {pre_value -= ((man - 10)/4 ); if (b_min < w_min) pre_value += ((w_min - b_min) /4 ); } }; } if (attack_w_min[to]<=w_k) {w_min= men_value[attack_w_min[to] ]; if (attack_b_min[to] w_min) pre_value -= (w_min - man /*- b_min - 10*/); }; if (sq[to] != sq_empty) pre_value -= men_value[sq[to]]; b_pre_slut: oldpre_value[ply][move_point]=pre_value; if (fr equal s_kill1_fr and to equal s_kill1_to) { if (pre_value-50=3) // and simple_kill1_vu[ply]=3) // or simple_kill2_vu[ply]2) // {if (info_out==1) printf(" no-topkill ");} } void get_next_good_move() /* Dette ser noget rodet ud, men der sker simpelthen det, at man sikrer sig, at det bedste af de resterende træk kommer op som det forreste af de resterende træk og altså bliver prøvet først. */ {signed char gem_i, best_i, anne, *lars, *torben; register signed char i, *x; int best_z, *jens, dina; register int *hanne; signed char *skaerm; /*skaerm=99999; */ if (wh_bl equal white) best_z=int_min; else best_z=int_max; i=move_pointer[ply]; gem_i=i; best_i=i; hanne=&move_value[ply][i]; x=&move_fr[ply][i]; for (lars=x; *x!=stop; ++x) {if ((wh_bl equal white and *hanne>best_z) or (wh_bl equal black and *hanne= konge (truet af konge eller ud‘kket) kan feltet ikke v‘re truet af D, T eller L og der laves straks en return false. */ /* her skal s† unders›ges, om det er true eller false............ */ return false; } int is_move_a_check(signed char *fr, signed char *to) /* denne funktion unders›ger, om et tr‘k giver skak */ /* input er et tr‘k (fra og til), skakbr‘ttet(sq), wh_bl, sq_b/w_k[ply] */ /* bem‘rk at ved ply==last_ply er tr‘kket udf›rt p† br‘ttet.... */ /* denne funktion returnerer false/true */ /* form†let er at udv‘lge de skakgivende tr‘k til den selektive search. */ /* rokade og forvandling tages der ikke hensyn til her, da disse tr‘k altid er med i den selektive search alligevel */ { signed char man, *gangart, *idx2, enemy_king, sq_enemy_king, sw=0; if (sq[*fr] equal sq_empty) man=sq[*to]; else man=sq[*fr]; if (man >= w_p) {sq_enemy_king=sqbk; enemy_king=b_k;} else {sq_enemy_king=sqwk; enemy_king=w_k;} #ifdef CHECKALL if (man>=w_p and wh_bl==black) {add_error(); printf(" wh_bl in is-move-a-check... ");} #endif if (man equal w_p * wh_bl) {if ((*to + wh_bl * 9 equal sq_enemy_king) or (*to + wh_bl * 11 equal sq_enemy_king) ) return true; else goto i_m_a_c_90; } else if (man equal w_r * wh_bl) gangart=rook; else if (man equal w_b * wh_bl) gangart=bishop; else if (man equal w_k * wh_bl) goto i_m_a_c_90; else if (man equal w_n * wh_bl) {gangart=knight; goto i_m_a_c_knight;} else { gangart=queen; sw=1; } i_m_a_c_10: /* ny retning */ if (*++gangart equal stop) goto i_m_a_c_90; /* ikke flere retninger */ if (*to > sq_enemy_king and *gangart > 0) goto i_m_a_c_10; /* forkert */ if (*to < sq_enemy_king and *gangart < 0) goto i_m_a_c_10; /* retning */ idx2=&sq[*to]; i_m_a_c_20: /* et skridt mere i den givne retning */ idx2 += *gangart; if (*idx2 equal sq_empty) goto i_m_a_c_20; if (*idx2 equal enemy_king) return true; goto i_m_a_c_10; i_m_a_c_knight: if (knight[0] equal more_steps) goto i_m_a_c_10; // nightrider i_m_a_c_knight_55: if (*++gangart equal stop) goto i_m_a_c_90; /* ikke flere retninger */ if (*to + *gangart equal sq_enemy_king) return true; goto i_m_a_c_knight_55; i_m_a_c_90: #ifdef VARIANTS if (chess_variant!=normal and sw==1) { if (chess_variant==q_is_rn or chess_variant==q_is_bn) {gangart=knight; sw=2; goto i_m_a_c_knight_55;} } #endif // if ((wh_bl==black and discovered_check(fr, to, &sqwk)==true) // or (wh_bl==white and discovered_check(fr, to, &sqbk)==true)) // return true; return false; } int is_move_a_sel_move(signed char *fr, signed char *to) { int man, enemy_man, gain; signed char depth; /* finder selektive tr‘k - denne funktion kaldes ikke med rokade eller forvandling. */ if (ply equal 0 and iteration equal 0) // kun skakker return is_move_a_check(fr, to); // i matesearch ply zero depth=ply - first_dynamic_sel_ply[ply]; /* depth er nu 0, 2, 4 osv..nej..*/ //#ifdef CHECKALL // if (depth % 2 != 0) {printf("depth not 0,2,4.... %d %d\n", // ply,first_dynamic_sel_ply[ply]); add_error();} //#endif #ifdef CHECKALL if (iteration equal 0 and ant_sel_ply>0) { printf("(iteration equal 0 and sel_ply>0).... "); add_error();} #endif // if (depth>=ant_sel_ply) return is_move_a_check(fr, to); /* check-search */ /* if (iteration equal 0) add_error(); */ /*press_any_key_to_continue()*/ if (wh_bl equal white) goto w_moves; else goto b_moves; w_moves: /* NB: w_attack_min er ufuldst‘ndig p† dette tidspunkt! */ if (only_recapture equal true) {if (sq[*to] != sq_empty and (men_value[sq[*to] * -1] + w_materiel[ply]-b_materiel[ply]) >= (w_materiel[0]-b_materiel[0]) ) return true; else return is_move_a_check(fr, to); // 1. jan 98 } if (depth>ant_sel_ply) goto w_m_1; if (depth equal 0 and sq[*to] != sq_empty) return true; /* alle slag i f›rste ply i den selektive search tages med */ // if (depth <= 2 and *to>=a6 and sq[*fr] equal w_p // and attack_b_min[*to] != b_p) return true; if (depth <= 4 and *to>=a7 and sq[*fr] equal w_p) return true; if (sq[*fr] equal w_p and (sq[*to+9] < b_p or sq[*to+11] < b_p) ) return true; w_m_1: // if ((w_materiel[ply]-b_materiel[ply]) <= // (w_materiel[0]-b_materiel[0])) { if (iteration>0 or ply>(4+last_sel_ply+gem_check_search-2)) // 4=last_iteration 11 okt. {if (sq[*to] != sq_empty) {man=men_value[sq[*fr]]; /* v‘rdi af brik */ enemy_man=men_value[sq[*to] * -1]; if (attack_b_min[*to]==b_k - 1) // mangler: udaekket hvis daekket af K og truet af en anden brik...... gain=enemy_man; /* en ud‘kket brik sl†s */ else gain=enemy_man - man; /* modstanderen kan sl† igen */ if ((w_materiel[ply]-b_materiel[ply]+gain) > (w_materiel[0]-b_materiel[0])) /* slag unders›ges herefter kun, hvis de kan give materielt overskud */ return true; } } } if (iteration>0 and depth>3) return false; else return is_move_a_check(fr, to); b_moves: /* NB: b_attack_min er ufuldst‘ndig p† dette tidspunkt! */ if (only_recapture equal true) {if (sq[*to] != sq_empty and (-men_value[sq[*to] ] + w_materiel[ply]-b_materiel[ply]) <= (w_materiel[0]-b_materiel[0]) ) return true; else return is_move_a_check(fr, to); // 1. jan 98 } if (depth>ant_sel_ply) goto b_m_1; if (depth equal 0 and sq[*to] != sq_empty) return true; /* alle slag i f›rste ply i den selektive search tages med */ // if (depth <= 2 and *to<=h3 and sq[*fr] equal b_p // and attack_w_min[*to] != w_p) return true; if (depth <= 4 and *to<=h2 and sq[*fr] equal b_p) return true; if (sq[*fr] equal b_p and (sq[*to-9] > w_p or sq[*to-11] > w_p) ) return true; b_m_1: // if ((w_materiel[ply]-b_materiel[ply]) >= // (w_materiel[0]-b_materiel[0])) { if (iteration>0 or ply>(4+last_sel_ply+gem_check_search-2)) // 4=last_iteration 11 okt. {if (sq[*to] != sq_empty) {man=men_value[sq[*fr] * -1]; /* v‘rdi af brik */ enemy_man=men_value[sq[*to]]; if (attack_w_min[*to]==w_k + 1) gain=enemy_man; /* en ud‘kket brik sl†s */ else gain=enemy_man - man; /* modstanderen kan sl† igen */ if ((w_materiel[ply]-b_materiel[ply]-gain) < (w_materiel[0]-b_materiel[0])) /* slag unders›ges herefter kun, hvis de kan give materielt overskud */ return true; } } } if (iteration>0 and depth>3) return false; else return is_move_a_check(fr, to); } int sel_move(signed char *ch1, signed char *ch2) { int dum; dum=is_move_a_sel_move(ch1, ch2); if (dum equal false) ++tv_non_sel_move; return dum; } #ifdef VARIANTS int pawncovered(signed char x) { if (sq[x]>=w_p) {if (sq[x-9]==w_p or sq[x-11]==w_p) return true; else return false;} else {if (sq[x+9]==b_p or sq[x+11]==b_p) return true; else return false;} } #endif void generate_moves_2(signed char *gangart, signed char ch1) { signed char sc1; signed char ch2; #ifdef VARIANTS if (chess_variant equal pawnfreeze and pawncovered(ch1) equal true) goto g_m2_exit; #endif sc1 = *gangart; /* husk at D,L & T g†r lange ture */ g_m2_10: /* ny retning */ if (*++gangart equal stop) goto g_m2_90; /* ikke flere retninger */ ch2=ch1; sq_idx2=sq_idx; g_m2_20: /* et skridt mere i den givne retning */ sq_idx2 += *gangart; ch2 += *gangart; if (*sq_idx2 equal sq_illegal) goto g_m2_10; /* udenfor brættet */ // asdf // if (sq[f2] equal sq_empty and // sq[a7] equal b_k and // sq[h8] equal w_r and // ply equal 1 and // ch1 equal c5 // ) // {//press_any_key_to_continue(); // // printf("asdf....\n"); // print_a1_h8(&ch2); // } if (wh_bl equal white) {if (*sq_idx < attack_w_min[ch2]) {attack_w_min[ch2]=*sq_idx; if (gen_moves_mode equal only_attack) {if (ch2 equal sqbk) {if (checking_direction1 equal 0) {sq_checking_man=ch1; checking_direction1=*gangart; sq_checked_king=ch2; } else checking_direction2=*gangart; /* dobbeltskak! */ } } else if (ch2 equal sqbk) {make2_move_status=pseudo_move; // if (ply equal 1) printf(" m-m-s=pseudo "); } } } else {if (*sq_idx > attack_b_min[ch2]) {attack_b_min[ch2]=*sq_idx; if (gen_moves_mode equal only_attack) {if (ch2 equal sqwk) {if (checking_direction1 equal 0) {sq_checking_man=ch1; checking_direction1=*gangart; sq_checked_king=ch2; } else checking_direction2=*gangart; /* dobbeltskak! */ } } else if (ch2 equal sqwk) {make2_move_status=pseudo_move; // if (ply equal 1) printf(" m-m-s=pseudo "); } } } if (wh_bl equal white and *sq_idx2 >= w_p) goto g_m2_10; if (wh_bl equal black and *sq_idx2 <= b_p) goto g_m2_10; /* en brik af samme farve */ if (gen_moves_mode equal only_attack) goto g_m2_80; if (*sq_idx equal w_k) {if (attack_b_min[ch2]>=b_k) goto g_m2_10; else {if ( ((ch2 - ch1) equal checking_direction1 and sq[sq_checking_man] != b_p ) or ((ch2 - ch1) equal checking_direction2 and sq[ch1 - checking_direction2] != b_p ) ) goto g_m2_10; else goto g_m2_70; } } if (*sq_idx equal b_k) {if (attack_w_min[ch2]<=w_k) goto g_m2_10; else {if ( ((ch2 - ch1) equal checking_direction1 and sq[sq_checking_man] != w_p ) or ((ch2 - ch1) equal checking_direction2 and sq[ch1 - checking_direction2] != w_p ) ) goto g_m2_10; else goto g_m2_70; } } if (checking_direction1 != 0 and sq_avoid_check[ch2] equal false #ifdef VARIANTS // and chess_variant < more_goals #endif ) goto g_m2_80; g_m2_70: /* if (ply>2 and king_in_check[ply] equal false hmmmmmmmmmmmmmmmmmmmmmmm and ch1 equal move_to[ply-2][move_pointer[ply-2]] and ch2 equal move_fr[ply-2][move_pointer[ply-2]] and move_to[ply-1][move_pointer[ply-1]]==move_fr[ply-3][move_pointer[ply-3]] and move_to[ply-3][move_pointer[ply-3]]==move_fr[ply-1][move_pointer[ply-1]] and move_to_before[ply-2] equal sq_empty and move_to_before[ply-3] equal sq_empty and swrepeat4 equal 1 ) {if ((wh_bl equal white and best_score[ply]draw_score) ) {best_score[ply]=draw_score; ++tv_repeat;} } else */ if (sel_ply_now equal false or sel_move(&ch1, &ch2) equal true) #ifdef VARIANTS if (chess_variant!=gridchess or grid[ch1]!=grid[ch2]) #endif { {move_fr[ply][move_point]=ch1; move_to[ply][move_point++]=ch2; #ifdef CHECKALL if (ch2h8 or sq[ch2]==sq_illegal) {add_error(); printf("error ch2.. "); press_a_k_t_c();} // if (sq[f6]==b_q and // sq[e5]==sq_empty and // sq[d4]==sq_empty and // sq[c3]==w_k and // ch1==d5 and // ch2==c4 // ) // {add_error(); printf("error sq_avoid_ch.. "); press_a_k_t_c();} #endif // print_kqrbnp(*sq_idx); // print_a1_h8(&ch2); // printf(" "); } } g_m2_80: if (*sq_idx2 != sq_empty) goto g_m2_10; if (sc1 equal more_steps) goto g_m2_20; goto g_m2_10; g_m2_90: // if (make2_move_status equal pseudo_move) // sq_idx=&sq[h8]+1; // ny her 31/8 g_m2_exit: ; } void pawnmove_into_array(signed char *ch1, signed char *ch2, signed char prom) {int selmove; if (checking_direction1 equal 0 or sq_avoid_check[*ch2] equal true or *ch2 equal p[ply].e_p #ifdef VARIANTS // or chess_variant >= more_goals #endif ) #ifdef VARIANTS if (chess_variant!=gridchess or grid[*ch1]!=grid[*ch2]) #endif { if ((wh_bl equal white and *ch1h2)) {if (sel_ply_now equal false or sel_move(ch1, ch2) equal true) {move_fr[ply][move_point]=*ch1; move_to[ply][move_point++]=*ch2; } } else {move_fr[ply][move_point]=*ch1; move_to[ply][move_point++]=prom; /* promotion to Q, R, B, N */ //if (magic equal 2) if (tv_pat>0 or ( (intern equal white and best_score[0]draw_score) ) ) {move_fr[ply][move_point]=*ch1; move_to[ply][move_point++]=prom+1; move_fr[ply][move_point]=*ch1; move_to[ply][move_point++]=prom+2; } move_fr[ply][move_point]=*ch1; move_to[ply][move_point++]=prom+3; } } } void generate_pawn_moves(signed char ch1) { signed char ch2; #ifdef VARIANTS if (chess_variant equal pawnfreeze and pawncovered(ch1) equal true) goto gpm_exit; #endif if (gen_moves_mode equal move_and_attack) {ch2 = ch1 + wh_bl * 10; if (sq[ch2] equal sq_empty) {pawnmove_into_array(&ch1, &ch2, prom_q_10); if ((wh_bl equal white and ch1<=h2) or (wh_bl equal black and ch1>=a7)) {ch2 = ch1 + wh_bl * 20; if (sq[ch2] equal sq_empty) pawnmove_into_array(&ch1, &ch2, 0); } } } if (wh_bl equal white) {ch2 = ch1 + 9; attack_w_min[ch2]=w_p; if (gen_moves_mode equal only_attack and ch2 equal sqbk) {sq_checking_man=ch1; checking_direction1=9; sq_checked_king=ch2; } } else {ch2 = ch1 - 9; attack_b_min[ch2]=b_p; if (gen_moves_mode equal only_attack and ch2 equal sqwk) {sq_checking_man=ch1; checking_direction1=-9; sq_checked_king=ch2; } } if (gen_moves_mode equal move_and_attack) {if ((wh_bl equal white and sq[ch2]<=b_p) or (wh_bl equal black and sq[ch2]>=w_p) or (ch2 equal p[ply].e_p )) pawnmove_into_array(&ch1, &ch2, prom_q_9); } if (wh_bl equal white) {ch2 = ch1 + 11; attack_w_min[ch2]=w_p; if (gen_moves_mode equal only_attack and ch2 equal sqbk) {sq_checking_man=ch1; checking_direction1=11; sq_checked_king=ch2; } } else {ch2 = ch1 - 11; attack_b_min[ch2]=b_p; if (gen_moves_mode equal only_attack and ch2 equal sqwk) {sq_checking_man=ch1; checking_direction1=-11; sq_checked_king=ch2; } } if (gen_moves_mode equal move_and_attack) {if ((wh_bl equal white and sq[ch2]<=b_p) or (wh_bl equal black and sq[ch2]>=w_p) or (ch2 equal p[ply].e_p )) pawnmove_into_array(&ch1, &ch2, prom_q_11); } gpm_exit: ; } void generate_moves() {signed char sovs, x; if (wh_bl equal white) memcpy(attack_w_min+a1, attack_w_nul+a1, h8-a1+2); else memcpy(attack_b_min+a1, attack_b_nul+a1, h8-a1+2); move_point=0; //#ifdef VARIANTS // if (chess_variant >= more_goals) checking_direction1=0; //#endif if (checking_direction2 != 0 and gen_moves_mode equal move_and_attack #ifdef VARIANTS and chess_variant != stationary #endif ) {if (wh_bl equal white) {sq_idx=&sq[sqwk]; generate_moves_2(king, sqwk);} // only kingmoves when in doublecheck else {sq_idx=&sq[sqbk]; generate_moves_2(king, sqbk);} goto g_m_exit; } if (wh_bl equal white) {for (x=0; piliwp[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[piliwp[x]]; generate_pawn_moves(piliwp[x]);} for (x=0; piliwr[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[piliwr[x]]; generate_moves_2(rook , piliwr[x]);} for (x=0; piliwb[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[piliwb[x]]; generate_moves_2(bishop, piliwb[x]);} for (x=0; piliwn[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[piliwn[x]]; generate_moves_2(knight, piliwn[x]);} if ( #ifdef VARIANTS chess_variant!=stationary and #endif make2_move_status!=pseudo_move) {sq_idx=&sq[sqwk]; generate_moves_2(king , sqwk);} // for (x=0; piliwk[x]!=0; ++x) // {sq_idx=&sq[piliwk[x]]; generate_moves_2(king , piliwk[x]);} for (x=0; piliwq[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[piliwq[x]]; generate_moves_2(queen, piliwq[x]); #ifdef VARIANTS if (chess_variant==q_is_rn or chess_variant==q_is_bn) {sq_idx=&sq[piliwq[x]]; generate_moves_2(knight, piliwq[x]);} #endif } } else {for (x=0; pilibp[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[pilibp[x]]; generate_pawn_moves(pilibp[x]);} for (x=0; pilibr[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[pilibr[x]]; generate_moves_2(rook , pilibr[x]);} for (x=0; pilibb[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[pilibb[x]]; generate_moves_2(bishop, pilibb[x]);} for (x=0; pilibn[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[pilibn[x]]; generate_moves_2(knight, pilibn[x]);} if ( #ifdef VARIANTS chess_variant!=stationary and #endif make2_move_status!=pseudo_move) {sq_idx=&sq[sqbk]; generate_moves_2(king , sqbk);} // for (x=0; piliwk[x]!=0; ++x) // {sq_idx=&sq[piliwk[x]]; generate_moves_2(king , piliwk[x]);} for (x=0; pilibq[x]!=0 and make2_move_status!=pseudo_move; ++x) {sq_idx=&sq[pilibq[x]]; generate_moves_2(queen, pilibq[x]); #ifdef VARIANTS if (chess_variant==q_is_rn or chess_variant==q_is_bn) {sq_idx=&sq[pilibq[x]]; generate_moves_2(knight, pilibq[x]);} #endif } } if (wh_bl equal white) {if ( p[ply].w_o_o equal allowed and sq[f1] equal sq_empty and sq[g1] equal sq_empty and attack_b_min[e1] equal b_k - 1 and attack_b_min[f1] equal b_k - 1 and attack_b_min[g1] equal b_k - 1) {move_fr[ply][move_point] =e1; move_to[ply][move_point++]=g1; } if ( p[ply].w_o_o_o equal allowed and sq[d1] equal sq_empty and sq[c1] equal sq_empty and sq[b1] equal sq_empty and attack_b_min[e1] equal b_k - 1 and attack_b_min[d1] equal b_k - 1 and attack_b_min[c1] equal b_k - 1) {move_fr[ply][move_point] =e1; move_to[ply][move_point++]=c1; } } else {if ( p[ply].b_o_o equal allowed and sq[f8] equal sq_empty and sq[g8] equal sq_empty and attack_w_min[e8] equal w_k + 1 and attack_w_min[f8] equal w_k + 1 and attack_w_min[g8] equal w_k + 1) {move_fr[ply][move_point] =e8; move_to[ply][move_point++]=g8; } if ( p[ply].b_o_o_o equal allowed and sq[d8] equal sq_empty and sq[c8] equal sq_empty and sq[b8] equal sq_empty and attack_w_min[e8] equal w_k + 1 and attack_w_min[d8] equal w_k + 1 and attack_w_min[c8] equal w_k + 1) {move_fr[ply][move_point] =e8; move_to[ply][move_point++]=c8; } } g_m_exit: ; } void clear_board() {signed char w1_char, w2_char, w3_char; for (w1_char=0; w1_char<120; w1_char++) { sq[w1_char]=sq_illegal; sq120_to_koordinat(&w1_char, &w2_char, &w3_char); if (w2_char>=1 and w2_char<=8 and w3_char>=1 and w3_char<=8) sq[w1_char]=sq_empty; } } void turn_sqavoid_false() {int x; if (checking_direction1 != 0) {for (x=sq_checking_man; x != sq_checked_king; x+=checking_direction1) sq_avoid_check[x]=false; } #ifdef CHECKSQAVOID for (x=a1; x<=h8; x++) {if (sq_avoid_check[x]!=false) {add_error(); printf(" ups... ");} } #endif // for (x=a1; x<=h8; sq_avoid_check[x++]=false); // ret fejl og fjern } void make_move_array() { int x; gen_moves_mode=move_and_attack; generate_moves(); #ifdef CHECKALL if (checking_direction1 == 0 and king_in_check[ply]==true) {add_error(); printf(" king in check... "); print_line(); show_board(); press_a_k_t_c();} #endif turn_sqavoid_false(); /* fatal error hvis der er overflow i move array..... */ mobilitet[ply]=move_point; realmoves[ply]=move_point; { if (move_point>32); else if (move_point>16) sel_delay[ply] += 1; else if (move_point> 8) sel_delay[ply] += 2; else if (move_point> 4) sel_delay[ply] += 6; else if (move_point> 2) sel_delay[ply] += 12; else sel_delay[ply] += 18; } move_fr[ply][ move_point]=stop; move_pointer[ply]=0; if (move_point>0) {if ( wh_bl equal black) b_prevalue_moves(); else w_prevalue_moves();} } void make_only_attack() {/* tr‘kgeneratoren k›res igennem, men kun attack-arrayet dannes */ signed char x; checking_direction1=0; checking_direction2=0; gen_moves_mode=only_attack; generate_moves(); if (checking_direction1 != 0) {for (x=sq_checking_man; x != sq_checked_king; x+=checking_direction1) sq_avoid_check[x]=true; } } void get_solution(signed char w3_char) /* er det en teststilling læses løsningen (som f.eks. er Qe8xNh5+!). Felterne fra og til (e8 og h5) findes ved at finde cifrene (8 og 5). Trækket omformes til internt format (solution_fr=95 og to=68). Forvandling kan ikke håndteres endnu og er sikkert ikke nødvendig. */ {signed char file_x, row_x; solution_fr=false; solution_to=false; for (solution_mark='!'; w3_char<81; ++w3_char) {if (xxx[w3_char] equal '?') solution_mark='?'; else {if (xxx[w3_char] != ' ') {if (xxx[w3_char] >='1' and xxx[w3_char] <='8') {file_x = file_x - 'a' + 1; row_x = xxx[w3_char] - '1' + 1; if (solution_fr equal false) solution_fr = (10 + (10 * row_x)) + file_x; else solution_to = (10 + (10 * row_x)) + file_x; } else file_x = xxx[w3_char]; } } if ((xxx[w3_char] equal '\n') or (xxx[w3_char] equal '\0') or (xxx[w3_char] equal ' ' and solution_to != false)) w3_char=99; } } void remove_move(int x) { //printf("\n remove:"); //print_a1_h8(&move_fr[0] [x]); //print_a1_h8(&move_to[0] [x]); //printf("\n"); //press_any_key_to_continue(); r: #ifdef CHECKALL if (x equal 120 or x<0) {add_error(); printf(" x equal 120 or < 0... ");} #endif move_to [0][x]=move_to [0][x+1]; move_fr [0][x]=move_fr [0][x+1]; move_value[0][x]=move_value[0][x+1]; if (move_fr[0][x] != stop) {++x; goto r;} } //void remove_pseudomoves_ply_zero() //{ int x=0, p=0, gem_iteration=iteration, gg=last_ply, asp=ant_sel_ply; // iteration=0; last_ply=2 /*1*/; ant_sel_ply=0; //loop_x: // if (move_fr[0][x] equal stop) // {/*if (p>0) printf("\nPseudomoves removed: %d iteration=%d\n",p,gem_iteration); // press_any_key_to_continue(); */ // iteration=gem_iteration; last_ply=gg; ant_sel_ply=asp;} // else // {/*last_ply=77; */ // make_move(&move_fr[0][x], &move_to[0][x], false); // if (make2_move_status equal pseudo_move) // {++p; // printf("\npseudo:"); // print_a1_h8(&move_fr[0][x]); // print_a1_h8(&move_to[0][x]); // printf("\n"); // move_pointer[0]=x; undo_move(); // remove_move(x); // --realmoves[0]; // --mobilitet[0]; // --x; // } // else {move_pointer[0]=x; undo_move();} // ++x; goto loop_x; // } //} void set_pb_guessmove_last() { int x, y; signed char wchar; x=find_move_index(&pb_move_fr, &pb_move_to); y=mobilitet[0]-1; wchar=move_fr[0][y]; move_fr[0][y]=move_fr[0][x]; move_fr[0][x]=wchar; wchar=move_to[0][y]; move_to[0][y]=move_to[0][x]; move_to[0][x]=wchar; } void gen_moves_ply_zero() { signed char gemply=ply; // slettes? ingen effekt - stadig slag ply=0; #ifdef CHECKALL if (ply_1 != -1) add_error(); #endif move_pointer[0]=0; change_black_white(); make_only_attack(); change_black_white(); make_move_array(); if ( (wh_bl equal black and attack_b_min[sqwk]>=b_k) or (wh_bl equal white and attack_w_min[sqbk]<=w_k) ) king_in_check[0]=true; else king_in_check[0]=false; // remove_pseudomoves_ply_zero(); sel_delay[0]=0; ply=gemply; // slettes? ved ply 0 i mate-search..... if (pb_on equal true/* and iteration>0*/) set_pb_guessmove_last(); } void initialize_best_score() {int x; // gem_best_score_0=best_score[0]; most_recent_best_score=best_score[0]; for (x=0;x<=max_ply; x++) // {if (x>0 or start_best_score[0] != w_materiel[0]-b_materiel[0]+wh_bl*30) // nb - +wh_bl*30 ikke vandt‘t!!! //{if (x>0 or matesearch_score equal no_good_found) {if ((wh_bl equal white and x % 2 equal 0) or (wh_bl equal black and x % 2 equal 1)) {start_best_score[x]=(int_min + x); mate_score[x]=(int_min + x);} else {start_best_score[x]=(int_max - x); mate_score[x]=(int_max - x);} if (iteration equal 0 and x % 2 equal 0) start_best_score[x] = w_materiel[0]-b_materiel[0]+wh_bl*30; if (matesearch_score equal no_good_found) best_score[0]=start_best_score[0]; else {best_score[0]=matesearch_score;} } mms[0]=start_best_score[0]; } void nulstil() { signed char x; p[0].pawnchange=false; for (x=a1; x<=h8; sq_avoid_check[x++]=false); for (x=a1; x<=h8; ++x) {attack_w_nul[x]=w_k+1; attack_b_nul[x]=b_k-1;} ply=0; ply_1=-1; mate_ply=-1; calculate_hashkey(); p[0].hash_idx=uli_idx; p[0].hash_id=uli_id; } void roll_entries() { int x=0; for (; x=a1; w1_char=w1_char - 10) {w2_char=w1_char; if (xxx[w3_char] equal '/') w3_char++; do { if (xxx[w3_char] equal 'k') {sq[w2_char]=b_k; ++w3_char; sqbk=w2_char; ++w2_char;} else if (xxx[w3_char] equal 'K') {sq[w2_char]=w_k; ++w3_char; sqwk=w2_char; ++w2_char;} else if (xxx[w3_char] equal 'q') {sq[w2_char]=b_q; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'Q') {sq[w2_char]=w_q; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'r') {sq[w2_char]=b_r; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'R') {sq[w2_char]=w_r; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 's') {sq[w2_char]=b_r; ++w3_char; beep(); if (w2_char equal a8) p[0].b_o_o_o=not_allowed; else if (w2_char equal h8) p[0].b_o_o=not_allowed; /* else {strcpy(fatal_tekst,"s-rook not on a8/h8"); goto fatal_error;} */ ++w2_char; } else if (xxx[w3_char] equal 'S') {sq[w2_char]=w_r; ++w3_char; beep(); if (w2_char equal a1) p[0].w_o_o_o=not_allowed; else if (w2_char equal h1) p[0].w_o_o =not_allowed; /* else {strcpy(fatal_tekst,"S-rook not on a1/h1"); goto fatal_error;} */ ++w2_char; } else if (xxx[w3_char] equal 'n') {sq[w2_char]=b_n; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'N') {sq[w2_char]=w_n; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'b') {sq[w2_char]=b_b; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'B') {sq[w2_char]=w_b; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'p') {sq[w2_char]=b_p; ++w3_char; ++w2_char;} else if (xxx[w3_char] equal 'P') {sq[w2_char]=w_p; ++w3_char; ++w2_char;} else if (xxx[w3_char]>='1' and xxx[w3_char]<='8') { --xxx[w3_char]; ++w2_char;} else if (xxx[w3_char] equal '0' or xxx[w3_char] equal '/' or xxx[w3_char] equal ' ') { ++w3_char;} /* else {strcpy(fatal_tekst,"ukendt tegn i input xxx[]"); goto fatal_error;}; */ } while (xxx[w3_char] != '/' and xxx[w3_char] != ' ' and w3_char<81); } /* mangler: check at der er en hvid og sort konge */ if (xxx[++w3_char] equal 'b') wh_bl = black; else wh_bl = white; intern=wh_bl; if (sq[a8] != b_r or sq[e8] != b_k) p[0].b_o_o_o = not_allowed; if (sq[h8] != b_r or sq[e8] != b_k) p[0].b_o_o = not_allowed; if (sq[a1] != w_r or sq[e1] != w_k) p[0].w_o_o_o = not_allowed; if (sq[h1] != w_r or sq[e1] != w_k) p[0].w_o_o = not_allowed; w_materiel[0]=0; b_materiel[0]=0; for (w1_char=a1; w1_char<=h8; ++w1_char) {sq120_to_koordinat(&w1_char, &tablin[w1_char], &tabrow[w1_char]); if (sq[w1_char]<=b_p) b_materiel[0] += men_value[sq[w1_char] * -1]; if (sq[w1_char]>=w_p) w_materiel[0] += men_value[sq[w1_char] ]; { if (sq[w1_char] equal w_k) sqwk=w1_char; else if (sq[w1_char] equal b_k) sqbk=w1_char; else if (sq[w1_char]>=w_p or sq[w1_char]<=b_p) add_pili(&w1_char, &sq[w1_char]); } } get_solution(w3_char); nulstil(); game_pointer=-1; store_hash_for_3xrepeat(); pb_move_ready=false; startmovetime=henttid(); } void print_pc_speed() { printf("\n PC-timetest (50.00 = 50 mhz 486): %5.2f ", pctid); printf("\n PC-speedfactor (10 = 50 mhz 486): %d ", speedfactor); if (pctid <= 0) // happens sometimes, but no pc is that fast... {printf("\n\n\n\nPC-timetest failed - leave Dabbaba and restart.\n"); press_any_key_to_continue();} } void pc_speed() { long int x; if (speedfactor>0) return; printf("running PC-speedtest..."); pctid=henttid(); for(x=0;x<545;++x) {make_array_ply_zero();}; pctid=henttid()-pctid; if (pctid equal 0) pctid=1; #ifdef CHECKJENSPCTIME if (pctid<5 or pctid>6) {printf(" CHECKJENSPCTIME er forkert..."); beep(); press_a_k_t_c();} #endif speedfactor=((5000/pctid)+5)/10; // 50 is time used on a 50mhz 486 print_pc_speed(); } void p99_seconds_used() { #ifdef BLANKHAPPENS strcpy(happens,""); #endif sprintf(p99,"\nTime: white=%6.2f seconds black=%6.2f seconds %s", wtid, btid, happens); } void show_seconds_used() { p99_seconds_used(); printf(p99);} void init_hash() { long unsigned int qqq; hash.hash_id=0; hash.hash_idx=0; hash.hash_fr=0; hash.hash_to=0; hash.hash_depth=-99; hash.hash_score_final=false; hash.hash_mpc=0; hash.hash_ply=99; // hash.hash_score=30222; ///* for (qqq=0; qqq<=hash_maxindex; ++qqq) { //hash.hash_fr=(char)qqq; write_hash(qqq); } } void store_pb_pos() { memcpy(sq+h8+22, sq+a1, 78); } void new_game() { printf("\n\nReady for a new game now...\n\n"); init_hash(); strcpy(xxx,"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR/w"); make_array_ply_zero(); pc_speed(); startmateriel=w_materiel[0]+b_materiel[0]-two_kings; if (save_games equal true) {fprintf(pgn,"\n"); if (evermoves_160 equal 160) {p99_seconds_used(); fprintf(pgn,p99);} // fprintf(pgn,"\n\n\n[Event \"x\"]\n"); fprintf(pgn,"\n\n[Event \"x\"]\n"); } wtid=0; btid=0; pb_move_fr=d2; pb_move_to=d4; pb_move_ready=true; store_pb_pos(); sq[d2+99]=sq_empty; sq[d4+99]=w_p; } void print_vurdering(int vu_rd) { if (vu_rd<(int_min+100)) vu_rd=vu_rd * -1; if (vu_rd < (int_max - 100)) printf(" score: %d",vu_rd); // nix else printf("mate in %d",(1 + (ply / 2))); else printf(" mate in %d",(1 + ((int_max - vu_rd) / 2))); // else printf("mate in %d %d %d %d",(1 + ((int_max - vu_rd) / 2)), // vu, best_score[ply], best_score[ply+2]); } void line_with_numbers() { printf("\n12345678901234567890123456789012345678901234567890");} void print_line() /* udskriver en variant */ {signed char fedtmule, fr, to, *nora, to_9_10_11, promote_piece, prom; printf("\n"); if (filtrace equal false and info_out equal 1) printf("\n"); if (filtrace equal true) printf("%6.0f ",tv_nodes); // if (mms[2]>=30000 or mms[2]<=-30000) printf("3 "); // else printf(" "); for (fedtmule=0; fedtmuleh8) {unpack_promotion(&to, &to_9_10_11, &promote_piece); if (*nora>=w_p) to=fr + to_9_10_11; if (*nora<=b_p) to=fr - to_9_10_11; prom=men_letter[promote_piece]; } else {//if (first_dynamic_sel_ply[fedtmule] equal 99 and // first_dynamic_sel_ply[fedtmule+1] != 99) // prom='*'; if (king_in_check[fedtmule+1] equal true) {if (prom equal ' ') prom='+'; else prom='$'; } } print_a1_h8(&to); printf("%c ",prom); prt_fr[fedtmule]=fr; prt_to[fedtmule]=to; } else printf(" "); } if (filtrace equal true) ++full_line; if (full_line equal 10) full_line=1; print_vurdering(best_score[ply]); if (run_test==true and magic!=13) {line_with_numbers();printf("\n%s",solution_xxx);} } int sbauerbewertung(int feld,int reihe, int linie) { /*--------------------------------------------------------------------*/ /*- Bewertung eines schwarzen Bauern. Neben den Parameter muessen -*/ /*- auch die Bauernkontrollen, Bauernlinien und Turmlinien richtig -*/ /*- belegt sein. -*/ /*- Gibt die Bewertung aus der Sicht von Schwarz zurueck. -*/ /*--------------------------------------------------------------------*/ int wert=0,j; reihe = 9-reihe; /* Reihe umdrehen. Hoehere Reihe ist */ /* damit wie bei WEISS besser. */ // if(MatSumme[Tiefe]>ENDSPIELMATERIAL) { /* Eroeffnung oder Mittelspiel */ // wert=sBFeldWert[feld]; // /* Entwicklung nicht abgeschlossen. Stosse Randbauern nicht vor */ // if((entwickelt<4) and ((linie>=F_LINIE)||(linie<=B_LINIE)) and // (reihe>REIHE_3)) { /* reihe wurde umgedreht. */ // wert = wert - 15; // } // } // else { /* Im Endspiel sind alle Linien gleich gut. Bringe Bauern nach */ // /* vorne. */ // wert = reihe*4; // } /** *** Ist Bauer ein Isolani ? *** Randbauern brauchen nicht extra behandelt werden. Bauern[A_LINIE-1] ist *** linker Rand, Bauern[H_LINE+1] rechter Rand. Auf beiden Raendern steht *** kein Bauer. **/ //if (linie>4) wert -= (+37 - ((linie - 4) * 15)); //else wert -= (-37 + ((linie) * 15)); if((sbauern[linie-1]==0) and (sbauern[linie+1]==0)) { wert += 12; /* Isolani */ if(sbauern[linie]>1) { /* Isolierter Doppelbauer. */ wert += 4; // before 12 } } if(sbauern[linie]>1) { /* Doppelbauer */ wert += 5; // 15---->5 29 sep. } /* Duo oder unterstuetzter Bauer bekommt Bonus */ /* Z.B. e5,d5 ist Duo, d6 unterstuetzt e5 */ // attack_w_min[to]>=w_p if((attack_b_min[feld]==b_p) or (attack_b_min[feld-10]==b_p)) { wert -= reihe ; } /* Rueckstaendiger Bauer wird nicht von eigenen gestuetzt und */ /* kann nicht nach vorne, weil gegnerische Bauern Feld vor ihm */ /* kontrollieren. */ if (attack_b_min[feld] != b_p and attack_b_min[feld-10] != b_p and attack_b_min[feld+10] != b_p) { wert += 15; if ((attack_w_min[feld-10] equal w_p) or (attack_w_min[feld-20] equal w_p and attack_b_min[feld-20] != b_p) ) {wert += 25; if (wbauern[linie]==0) {wert += 15; // *** rook part 1.sa *** if (piliwr[1]>0 and tablin[piliwr[1]] equal linie) wert+=15; if (piliwr[0]>0 and tablin[piliwr[0]] equal linie) wert+=15; } } //else {if (attack_b_min[feld-20] != b_p and // attack_w_min[feld-20] equal w_p) wert += 10; // } //gl. if (sq[a1 - 1 + linie] equal w_r) wert += 10; if(wbauern[linie]==0) { /* Halboffene Linie */ if (piliwr[1]>0 and tablin[piliwr[1]] equal linie) wert+=12; // *** rook part 1.sb *** if (piliwr[0]>0 and tablin[piliwr[0]] equal linie) wert+=12; // if((Tuerme[linie].weiss>0)) { // wert=wert -8; /* Turm kniet sich auf rueckstaendigen Bauer */ } } else {if(wbauern[linie]==0) { /* Halboffene Linie */ /* ** Bauer ist Freibauer, wenn auf halboffenen Linie und die ** weiteren Felder auf seiner Linie nicht von gegnerischen ** Bauern kontrolliert werden. */ for(j=feld;j>h2;j-=10) { if(attack_w_min[j] equal w_p) { goto fertig; } } /* Freibauer gefunden. Im Endspiel ist Freibauer wichtiger als */ /* im Mittelspiel. */ if (b_materiel[ply]0) { /* Turm unterstuetzt Freibauer */ // wert = wert + reihe*2; /* auf selben Linie */ // } // if(Tuerme[linie].weiss>0) { /* gegnerischer Turm auf selben */ // wert = wert - reihe*2; /* Linie. */ // } // if(MatSumme[Tiefe]==0) { /* Reines Bauernendspiel. Freibauer */ // wert = wert + reihe*8; /* Besonders wertvoll. */ // } if((attack_b_min[feld]==b_p) or (attack_b_min[feld-10]==b_p)) { /* Unterstuetzter Freibauer */ wert -= reihe*14; } /* Freibauer von weisser Figur blockiert. Figur wird auch */ /* nicht von eigenen Bauern bedroht. */ if((sq[feld-10]>=w_p) and (attack_b_min[feld-10]!=b_p)) { wert+= reihe*14; } } else { /* Freibauer im Mittelspiel */ wert -= reihe * 27; if((attack_b_min[feld]==b_p) or (attack_b_min[feld-10]==b_p)) { /* Unterstuetzter Freibauer */ wert -= reihe*8; } } } } fertig: return wert; } int wbauerbewertung(int feld,int reihe, int linie) { int wert=0,j; //reihe = 9-reihe; /* Reihe umdrehen. Hoehere Reihe ist */ /* damit wie bei WEISS besser. */ // if(MatSumme[Tiefe]>ENDSPIELMATERIAL) { /* Eroeffnung oder Mittelspiel */ // wert=sBFeldWert[feld]; // /* Entwicklung nicht abgeschlossen. Stosse Randbauern nicht vor */ // if((entwickelt<4) and ((linie>=F_LINIE)||(linie<=B_LINIE)) and // (reihe>REIHE_3)) { /* reihe wurde umgedreht. */ // wert = wert - 15; // } // } // else { /* Im Endspiel sind alle Linien gleich gut. Bringe Bauern nach */ // /* vorne. */ // wert = reihe*4; // } /** *** Ist Bauer ein Isolani ? *** Randbauern brauchen nicht extra behandelt werden. Bauern[A_LINIE-1] ist *** linker Rand, Bauern[H_LINE+1] rechter Rand. Auf beiden Raendern steht *** kein Bauer. **/ //if (linie>4) wert += (+37 - ((linie - 4) * 15)); //else wert += (-37 + ((linie) * 15)); if((wbauern[linie-1]==0) and (wbauern[linie+1]==0)) { wert -= 12; /* Isolani */ if(wbauern[linie]>1) { /* Isolierter Doppelbauer. */ wert -= 4; // before 12 } } if(wbauern[linie]>1) { /* Doppelbauer */ wert -= 5; // 15---->5 29 sep. } /* Duo oder unterstuetzter Bauer bekommt Bonus */ /* Z.B. e5,d5 ist Duo, d6 unterstuetzt e5 */ // attack_w_min[to]>=w_p if((attack_w_min[feld]==w_p) or (attack_w_min[feld+10]==w_p)) { wert += reihe ; } /* Rueckstaendier Bauer */ /* Rueckstaendiger Bauer wird nicht von eigenen gestuetzt und */ /* kann nicht nach vorne, weil gegnerische Bauern Feld vor ihm */ /* kontrollieren. */ if (attack_w_min[feld] != w_p and attack_w_min[feld+10] != w_p and attack_w_min[feld-10] != w_p) { wert -= 15; if ((attack_b_min[feld+10] equal b_p) or (attack_b_min[feld+20] equal b_p and attack_w_min[feld+20] != w_p) ) {wert -= 25; if (sbauern[linie]==0) {wert -= 15; // *** rook part 1.wa *** if (pilibr[0]>0 and tablin[pilibr[0]] equal linie) wert-=15; if (pilibr[1]>0 and tablin[pilibr[1]] equal linie) wert-=15; } } //else {if (attack_w_min[feld+20] != w_p and // attack_b_min[feld+20] equal b_p) wert -= 10; // } // gl.if (sq[a8 - 1 + linie] equal b_r) wert -= 10; if (sbauern[linie]==0) { /* Halboffene Linie */ if (pilibr[0]>0 and tablin[pilibr[0]] equal linie) wert-=12; // *** rook part 1.wb *** if (pilibr[1]>0 and tablin[pilibr[1]] equal linie) wert-=12; // if((Tuerme[linie].weiss>0)) { // wert=wert -8; /* Turm kniet sich auf rueckstaendigen Bauer */ } } else {if(sbauern[linie]==0) { /* Halboffene Linie */ /* ** Bauer ist Freibauer, wenn auf halboffenen Linie und die ** weiteren Felder auf seiner Linie nicht von gegnerischen ** Bauern kontrolliert werden. */ for(j=feld;j0) { /* Turm unterstuetzt Freibauer */ // wert = wert + reihe*2; /* auf selben Linie */ // } // if(Tuerme[linie].weiss>0) { /* gegnerischer Turm auf selben */ // wert = wert - reihe*2; /* Linie. */ // } // if(MatSumme[Tiefe]==0) { /* Reines Bauernendspiel. Freibauer */ // wert = wert + reihe*8; /* Besonders wertvoll. */ // } if((attack_w_min[feld]==w_p) or (attack_w_min[feld+10]==w_p)) { /* Unterstuetzter Freibauer */ wert += reihe*14; } /* Freibauer von schwarzer Figur blockiert. Figur wird auch */ /* nicht von eigenen Bauern bedroht. */ if((sq[feld+10]<=b_p) and (attack_w_min[feld+10]!=w_p)) { wert-= reihe*14; } } else { /* Freibauer im Mittelspiel */ wert += reihe * 27; if((attack_w_min[feld]==w_p) or (attack_w_min[feld+10]==w_p)) { /* Unterstuetzter Freibauer */ wert += reihe*8; } } } } fertig: return wert; } void init_bewertung(void) { int i, x; // Raender mit initialisieren. Damit braucht man bei Randlinien nicht // extra abfragen. for(i=0;i<=9;++i) { // kan optimeres - kun 1 til 8 wbauern[i]=0; sbauern[i]=0; /// Tuerme[i].weiss=0; Tuerme[i].schwarz=0; } for (x=0; piliwp[x]>0; ++x) ++wbauern[tablin[piliwp[x]]]; for (x=0; pilibp[x]>0; ++x) ++sbauern[tablin[pilibp[x]]]; return; } int how_open(signed char *rooksq) { int x=0, wsq; wsq=*rooksq+10; a: if (sq[wsq] equal sq_empty) {++x; wsq+=10; goto a;} wsq=*rooksq-10; b: if (sq[wsq] equal sq_empty) {++x; wsq-=10; goto b;} return x*8; } int bewerte_stellung(/*int alpha,int beta,int seite*/) { int wert,/*huskposwert,*/poswert,i,j,k,feld, q, p /*,wlaeufer,slaeufer*/; int buhhh; signed char x /*,f*/; // int bauernanzahl; // int matsum,wtauf7,stauf2; // int wentwickelt,sentwickelt; /* Positionelle Bewertungsfaktoren wiegen starkes Materialungleichgewicht */ /* nicht auf. Daher wird in diesem Fall auf Positionsbewertung verzichtet */ /* Ausnahme: Spaetes Endspiel. Freibauern haben hohe Bewertung. */ /* Leichtfigur ohne Bauern ist wirkungslos. */ // wert=0; /* ** Initialisiere die Turm und Bauernlinien und die Bauernkontrollen. ** Das koennte man wesentlich schneller auch bei der Ausfuehrung (und ** der Zuruecknahme) von Zuegen inkrementell berechnen. Allerdings ist ** diese inkrementelle Berechnung auch wegen der Spezialfaelle Rochade, ** Enpassant und Umwandlung laestig und fehleranfaellig. ** Koennte auch in init_bewertung Figurenliste aufbauen und dann in ** der zweiten Runde diese Figurenliste durchgehen (und nicht mehr ** das gesamte Brett). ** Die schnellste Loesung besteht darin, auch diese Figurenliste ** inkrementell zu berechnen. Allerdings werden dann die Funktionen ** 'zugausfuehren' und zugzuruecknehmen' noch komplizierter. ** Nach dem KISS (Keep It Simple und Stupid) Prinzip wurde in MiniMAX ** diese Loesung gewaehlt. */ init_bewertung(); poswert=0; buhhh=0; // if (tv_nodes==34677) pawninfo=true; for (x=0; piliwp[x]>0; ++x) {p=poswert; ++buhhh; poswert+=wbauerbewertung(piliwp[x], tabrow[piliwp[x]], tablin[piliwp[x]]); if (pawninfo equal true) {print_a1_h8(&piliwp[x]); printf(":%d ",poswert-p);} } for (x=0; pilibp[x]>0; ++x) {p=poswert; ++buhhh; poswert+=sbauerbewertung(pilibp[x], tabrow[pilibp[x]], tablin[pilibp[x]]); if (pawninfo equal true) {print_a1_h8(&pilibp[x]); printf(":%d ",poswert-p);} } // huskposwert=poswert; // *** rook part 2 *** if (pilibr[0]>0 and sbauern[tablin[pilibr[0]]]==0) {if (wbauern[tablin[pilibr[0]]]==0) poswert-=(10+how_open(&pilibr[0])); else poswert-=5;} if (pilibr[1]>0 and sbauern[tablin[pilibr[1]]]==0) {if (wbauern[tablin[pilibr[1]]]==0) poswert-=(10+how_open(&pilibr[1])); else poswert-=5;} if (piliwr[0]>0 and wbauern[tablin[piliwr[0]]]==0) {if (sbauern[tablin[piliwr[0]]]==0) poswert+=(10+how_open(&piliwr[0])); else poswert+=5;} if (piliwr[1]>0 and wbauern[tablin[piliwr[1]]]==0) {if (sbauern[tablin[piliwr[1]]]==0) poswert+=(10+how_open(&piliwr[1])); else poswert+=5;} poswert=(poswert*wpawn)/8; q=abs(poswert); if (q>maxpawn) maxpawn=q; // if (maxpawn>200) // {print_line(); show_board(); // press_a_k_t_c();} if (q>limitpawnscore) {limitpawnscore=q; ++pawnexceed;} ++totalexcd; return poswert; } int opening() { int z; if (piliwp[11]+pilibp[11]>12 and drucker equal false) // seek open play; but not against computers (=auto232)... z=(piliwp[11]+pilibp[11]-12)*-4*intern; else z=0; /* BLACK */ if (pilibq[0]!=0 and (pilibq[0]>h5 or pilibq[0]==a5)) z-=(4*black_8); if (sq[a6] equal b_n or sq[h6] equal b_n or sq[a5] equal b_n or sq[h5] equal b_n) z+=25; if (sq[e6] equal b_p and sq[c8] equal b_b and sq[b7] equal b_p) z+=20; if (sq[d6] equal b_p and sq[f8] equal b_b and sq[g7] equal b_p) z+=20; if (sq[e7] != b_p) z-=10; if (sq[d7] != b_p) z-=10; if (sq[c7] != b_p) z-=5; if (sq[a7] equal b_p) z-=10; if (sq[h7] equal b_p) z-=10; if (sq[g7] equal b_b and sq[g6] equal b_p) z-=8; if (sq[b7] equal b_b and sq[b6] equal b_p) z-=5; if (sq[g8] != b_n) z-=33; if (sq[b8] != b_n) z-=23; if (sq[f8] != b_b) z-=17; if (sq[c8] != b_b) z-=14; if (sq[f8] equal b_b and sq[g7] == b_p and sq[e7] != sq_empty) z+=30; if (sq[c8] equal b_b and sq[b7] == b_p and sq[d7] != sq_empty) z+=20; if (sq[e7] equal b_p and sq[e6] != sq_empty) z+=25; if (sq[d7] equal b_p and sq[d6] != sq_empty) z+=25; if (sq[c7] equal b_p and sq[c6] != sq_empty and sq[d5] equal b_p and sq[d4] equal w_p) z+=11; if (pilibr[0]!=0 and pilibr[0]h2) z-=20; if (piliwr[1]!=0 and piliwr[1]>h2) z-=20; // black + white // if (everplay_and_black() equal false) { if (sq[e7] != b_p and sq[e6] != b_p) z-=(4+2*black_8); if (sq[d7] != b_p and sq[d6] != b_p) z-=(4+2*black_8); if (sq[e2] != w_p and sq[e3] != w_p) z+=(4+2*black_8); if (sq[d2] != w_p and sq[d3] != w_p) z+=(4+2*black_8); if (piliwn[1]>0 and tabrow[piliwn[1]]<4) z+=(black_8-2); if (piliwn[2]>0 and tabrow[piliwn[2]]<4) z+=(black_8-2); if (pilibn[1]>0 and tabrow[pilibn[1]]>5) z-=(black_8-2); if (pilibn[2]>0 and tabrow[pilibn[2]]>5) z-=(black_8-2); if (sq[e4]==w_p and sq[d4]==w_p) z+=(10+black_8); if (sq[c4]==w_p and sq[d4]==w_p) z+=(4+black_8); if (sq[e5]==b_p and sq[d5]==b_p) z-=(10+black_8); if (sq[c5]==b_p and sq[d5]==b_p) z-=(4+black_8); if (sq[d2]==w_b) z-=(black_8-2); if (sq[e2]==w_b) z-=(black_8-2); if (sq[d7]==b_b) z+=(black_8-2); if (sq[e7]==b_b) z+=(black_8-2); if (sq[d2]==w_n) z-=(black_8+2); if (sq[e2]==w_n) z-=(black_8+2); if (sq[d7]==b_n) z+=(black_8+2); if (sq[e7]==b_n) z+=(black_8+2); if (sq[e6]==b_p and (sq[d7]==b_b or sq[c8]==b_b)) z+=black_8; if (sq[e3]==w_p and (sq[d2]==w_b or sq[c1]==w_b)) z-=black_8; if ((sq[d5]==w_p or sq[d5]==b_p) and (sq[c4]==w_b or sq[b3]==w_b)) z-=(black_8-2); if ((sq[e5]==w_p or sq[e5]==b_p) and (sq[f4]==w_b or sq[g3]==w_b)) z-=(black_8-2); if ((sq[d4]==b_p or sq[d4]==w_p) and (sq[c5]==b_b or sq[b6]==b_b)) z+=(black_8-2); if ((sq[e4]==b_p or sq[e4]==w_p) and (sq[f5]==b_b or sq[g6]==b_b)) z+=(black_8-2); if (sq[b7]==b_b and (sq[c6]==b_p or sq[d5]==b_p or sq[d5]==w_p)) z+=black_8; if (sq[g7]==b_b and (sq[f6]==b_p or sq[e5]==b_p or sq[e5]==w_p)) z+=black_8; if (sq[b2]==w_b and (sq[c3]==w_p or sq[d4]==w_p or sq[d4]==b_p)) z-=black_8; if (sq[g2]==w_b and (sq[f3]==w_p or sq[e4]==w_p or sq[e4]==b_p)) z-=black_8; if (sq[e3]==w_p and (sq[d2]==w_b or sq[c1]==w_b)) z-=black_8; if (sq[b5]==w_b and sq[b7]==b_p and sq[c7]==b_p and sq[d7]==b_p) if (sq[c6]==b_n) z-=black_8/2; else z-=black_8; if (sq[b4]==b_b and sq[b2]==w_p and sq[c2]==w_p and sq[d2]==w_p) if (sq[c3]==w_n) z+=black_8/2; else z+=black_8; if ((sq[c4]==w_b or sq[b3]==w_b or sq[a2]==w_b) and sq[e6]!=b_p and tablin[sqbk]>4 and sq[d5]!=w_p and sq[d5]!=b_p and sq[c4]!=w_p and sq[c4]!=b_p) // n›jagtigere... z+=(black_8*2+4); if ((sq[c5]==b_b or sq[b6]==b_b or sq[a7]==b_b) and sq[e3]!=w_p and tablin[sqwk]>4 and sq[d4]!=w_p and sq[d4]!=b_p and sq[c5]!=w_p and sq[c5]!=b_p) z-=(black_8*2+4); if ((sq[g5]==w_b or sq[h4]==w_b) and sq[f6]==b_n and (sq[e7]<=b_r or (sq[e7]==sq_empty and sq[d8]<=b_r))) z+=black_8*3; if ((sq[g4]==b_b or sq[h5]==b_b) and sq[f3]==w_n and (sq[e2]>=w_r or (sq[e2]==sq_empty and sq[d1]>=w_r))) z-=black_8*3; if ((sq[b5]==w_b or sq[a4]==w_b) and sq[c6]==b_n and (sq[d7]<=b_r or (sq[d7]==sq_empty and sq[e8]<=b_r))) z+=black_8*3; if ((sq[b4]==b_b or sq[a5]==b_b) and sq[c3]==w_n and (sq[d2]>=w_r or (sq[d2]==sq_empty and sq[e1]>=w_r))) z-=black_8*3; // if (sq[d2]==w_n and sq[c1]==w_b and sq[b2]==w_p) z-=8; // if (sq[e2]==w_n and sq[f1]==w_b and sq[g2]==w_p) z-=8; // if (sq[d7]==b_n and sq[c8]==b_b and sq[b7]==b_p) z+=8; // if (sq[e7]==b_n and sq[f8]==b_b and sq[g7]==b_p) z+=8; if (p[ply].w_o_o==allowed and sq[f2]!=w_p) {if (sq[h2]==w_p) {if ((sq[f3]==w_p and sq[e4]==w_p) or (sq[f4]==w_p and sq[e3]==w_p) or (sq[f4]==w_p and sq[e5]==w_p)) z-=6; else z-=16; } else z-=16; } if (p[ply].b_o_o==allowed and sq[f7]!=b_p) {if (sq[h7]==b_p) {if ((sq[f6]==b_p and sq[e5]==b_p) or (sq[f5]==b_p and sq[e6]==b_p) or (sq[f5]==b_p and sq[e4]==b_p)) z+=6; else z+=16; } else z+=16; } if (p[ply].w_o_o==allowed and sq[g2]!=w_p and sq[g3]!=w_p) {z-=12; if (p[ply].w_o_o_o==not_allowed or (sq[b2]!=w_p and sq[b3]!=w_p) or (sq[c2]!=w_p and sq[c3]!=w_p)) z-=12; } if (p[ply].b_o_o==allowed and sq[g7]!=b_p and sq[g6]!=b_p) {z+=12; if (p[ply].b_o_o_o==not_allowed or (sq[b7]!=b_p and sq[b6]!=b_p) or (sq[c7]!=b_p and sq[c6]!=b_p)) z+=12; } } return z*wopen/8; } int king_safety() { int k=0, x, sq_king, kinglin; //if (b_materiel[ply]>endgame_limit) {sq_king=sqwk; kinglin=tablin[sq_king]; if (sq[sq_king+11]>=w_p) k+=8; if (sq[sq_king+10]>=w_p or sq[sq_king+10]==b_p) k+=18; if (sq[sq_king+9] >=w_p) k+=8; if (sq[sq_king+1] ==w_p) k+=8; if (sq[sq_king-1] ==w_p) k+=8; if (kinglin equal 1 or kinglin equal 8) k+=12; if (sq_king!=e1 and sq[sq_king+1]!=sq_empty and sq[sq_king-1]!=sq_empty) k-=12; if (kinglin>=4) x=-1; else x=+1; // >=4 ?? if (sq[sq_king+x] >=w_p) k+=8; if (sq[sq_king+x+10] >=w_p) k+=8; if (kinglin>=5 and sq[g2]!=w_p and sq[g3]!=w_p) k-=25; if (sq_king equal g1 or sq_king equal b1) k+=16; else if (sq_king equal e1 and (p[ply].w_o_o==allowed or p[ply].w_o_o_o==allowed)) k+=8; else if (sq_king equal c1) k+=12; } //if (w_materiel[ply]>endgame_limit) {sq_king=sqbk; kinglin=tablin[sq_king]; if (sq[sq_king-11]<=b_p) k-=8; if (sq[sq_king-10]<=b_p or sq[sq_king-10]==w_p) k-=18; if (sq[sq_king-9] <=b_p) k-=8; if (sq[sq_king+1] ==b_p) k-=8; if (sq[sq_king-1] ==b_p) k-=8; if (kinglin equal 1 or kinglin equal 8) k-=12; if (sq_king!=e8 and sq[sq_king+1]!=sq_empty and sq[sq_king-1]!=sq_empty) k+=12; if (kinglin>=4) x=-1; else x=+1; // >=4 ?? if (sq[sq_king+x] <=b_p) k-=8; if (sq[sq_king+x-10] <=b_p) k-=8; if (kinglin>=5 and sq[g7]!=b_p and sq[g6]!=b_p) k+=25; if (sq_king equal g8 or sq_king equal b8) k-=16; else if (sq_king equal e8 and (p[ply].b_o_o==allowed or p[ply].b_o_o_o==allowed)) k-=8; else if (sq_king equal c8) k-=12; } return k; } int repeat3x_draw() { signed int x=game_pointer-4, y=1; r3x: if (x<0) return false; if ( game_id [game_pointer] equal game_id [x] and game_idx[game_pointer] equal game_idx[x]) {++y; if (y equal 3) return true;} x-=2; goto r3x; } #ifdef VARIANTS #else int all_pawns_on_kingfile(signed char *pilipawn, signed char kinglin) { int x=0; p: if (tablin[*(pilipawn+x)] != kinglin) return false; if (*(pilipawn+(++x)) equal 0) return true; else goto p; } int bishops_on_diff_sq_colour(signed char *pilibishop) { int x0=0, x1=1; b: if (square_colour(pilibishop+x0) != square_colour(pilibishop+x1)) return true; ++x0; ++x1; // if (xi>7) beep(); // just a check... if (*(pilibishop+x1) equal 0) return false; else goto b; } int dead_draw() { if (b_materiel[ply] <= men_value[w_k] and piliwp[11] equal 0) {if (piliwq[11] equal 0 and piliwr[11] equal 0) if ((piliwb[11]<=1 and piliwn[11]==0) or (piliwb[11]>1 and piliwn[11]==0 and bishops_on_diff_sq_colour(piliwb) equal false) or (piliwn[11]<=1 and piliwb[11]==0) // go deeper with 2 knights; not the other cases.... ) return true; } else if (w_materiel[ply] <= men_value[w_k] and pilibp[11] equal 0) {if (pilibq[11] equal 0 and pilibr[11] equal 0) if ((pilibb[11]<=1 and pilibn[11]==0) or (pilibb[11]>1 and pilibn[11]==0 and bishops_on_diff_sq_colour(pilibb) equal false) or (pilibn[11]<=1 and pilibb[11]==0) ) return true; } return false; } int b_king_near_corner(signed char sqk, signed char *k_corner) { if (sqk==h8 or sqk==h7 or sqk==g7 or sqk==g8) {*k_corner=h8; return true;} if (sqk==a8 or sqk==a7 or sqk==b7 or sqk==b8) {*k_corner=a8; return true;} return false; } int w_king_near_corner(signed char sqk, signed char *k_corner) { if (sqk==h1 or sqk==h2 or sqk==g2 or sqk==g1) {*k_corner=h1; return true;} if (sqk==a1 or sqk==a2 or sqk==b2 or sqk==b1) {*k_corner=a1; return true;} return false; } int probably_draw() { signed char k_corner; if (b_materiel[ply] <= men_value[w_k] and piliwq[11]==0 and piliwr[11]==0) {if (piliwp[11] equal 0) {if (piliwn[11]==2 and piliwb[11]==0) return true; } else if ((b_king_near_corner(sqbk, &k_corner) equal true) and (piliwb[11]==1 or (piliwb[11]>1 and bishops_on_diff_sq_colour(piliwb)==false) ) and square_colour(&k_corner) != square_colour(piliwb) and all_pawns_on_kingfile(piliwp, tablin[k_corner])==true) return true; } if (w_materiel[ply] <= men_value[w_k] and pilibq[11]==0 and pilibr[11]==0) {if (pilibp[11] equal 0) {if (pilibn[11]==2 and pilibb[11]==0) return true; } else if ((w_king_near_corner(sqwk, &k_corner) equal true) and (pilibb[11]==1 or (pilibb[11]>1 and bishops_on_diff_sq_colour(pilibb)==false) ) and square_colour(&k_corner) != square_colour(pilibb) and all_pawns_on_kingfile(pilibp, tablin[k_corner])==true) return true; } return false; } void check_insufmat() { if (piliwq[11]==0 and piliwr[11]==0 and piliwp[11]==0) {if ((piliwb[11]==0 and (piliwn[11]<=1 or (ply>DRAWPLY and piliwn[11]==2)) ) or (piliwn[11]==0 and (piliwb[11]<=1 or bishops_on_diff_sq_colour(piliwb)==false) ) ) w_insufmat=true; } if (pilibq[11]==0 and pilibr[11]==0 and pilibp[11]==0) {if ((pilibb[11]==0 and (pilibn[11]<=1 or (ply>DRAWPLY and pilibn[11]==2)) ) or (pilibn[11]==0 and (pilibb[11]<=1 or bishops_on_diff_sq_colour(pilibb)==false) ) ) b_insufmat=true; } } #endif int vurdering() { int v, exch_pct, vurd_j, materiel_10_0; int vurd_a, vurd_a2, vurd_b, vurd_c, vurd_d, vurd_e; int vurd_f, vurd_g, vurd_h, vurd_i; int wmatply, bmatply; if (vurd_node equal tv_nodes) return gem_vurd; //printf(":"); vurd_node = tv_nodes; w_insufmat=false; b_insufmat=false; #ifdef VARIANTS #else check_insufmat(); #endif wmatply=w_materiel[ply]; bmatply=b_materiel[ply]; materiel_10_0 = (wmatply+bmatply-two_kings) / (startmateriel / 10); // if (materiel_10_0<0 or materiel_10_0>15) // {add_error(); printf(" materiel_10_0 forkert.... ");} if (materiel_10_0>10) materiel_10_0=10; //if (iteration equal 4 and ply equal 4 // and move_fr[0][move_pointer[0]]==f6 // and move_to[0][move_pointer[0]]==e4 // and move_fr[1][move_pointer[1]]==d2 // and move_to[1][move_pointer[1]]==d3 // and move_fr[2][move_pointer[2]]==b8 // and move_to[2][move_pointer[2]]==c6 // and move_fr[3][move_pointer[3]]==d3 // and move_to[3][move_pointer[3]]==e4 // and move_fr[4][move_pointer[4]]==e8 // and move_to[4][move_pointer[4]]==f8 // ) // exch_pct=55; //printf("s‘t breakpoint i denne linie..."); // {print_line(); // printf("\n score v = %d", v); // press_a_k_t_c();} v=(wmatply-bmatply); vurd_a=v; if (full_evalu equal 0 /*or iteration<3*/) goto retur; if (black_8>=opening_limit) {v+=opening(); vurd_a2=v; v+=random_move; } vurd_b=v; v+=king_safety()*wkingsaf/8*materiel_10_0/10; vurd_c=v; if (ply>=iteration) v+=((mobilitet[iteration]-mobilitet[iteration-1]) * sgn_wh_bl * wmobil / 8 * materiel_10_0 / 10 / 4); vurd_d=v; v+=centre[ply]*wcentr/8*materiel_10_0/10; vurd_e=v; if (*(piliwb+11)>1) v+=bishoppair * (10 - abs(10-pilibp[11]-piliwp[11])) / 10; if (*(pilibb+11)>1) v-=bishoppair * (10 - abs(10-pilibp[11]-piliwp[11])) / 10; vurd_f=v; if (Q_near_enemy_K != 0) {if (piliwq[0]!=0) {v+= 8 - abs(tablin[piliwq[0]] - tablin[sqbk]) - - abs(tabrow[piliwq[0]] - tabrow[sqbk]); } if (pilibq[0]!=0) {v+=-8 + abs(tablin[pilibq[0]] - tablin[sqwk]) - + abs(tabrow[pilibq[0]] - tabrow[sqwk]); } } if (rook_placement != 0) // *** rook part 3 *** {//{if (piliwr[0]!=0) {v+=tabrow[piliwr[0]]; // if (tabrow[piliwr[0]]>6) v+=5; // if (tabrow[piliwr[0]] equal tabrow[sqbk]) v+=8; // } if (piliwr[1]!=0) {//v+=tabrow[piliwr[1]]; //if (tabrow[piliwr[1]]>6) v+=5; //if (tabrow[piliwr[1]] equal tabrow[sqbk]) v+=8; if (attack_w_min[piliwr[0]] equal w_r or // unsure attack_w_min[piliwr[1]] equal w_r) // test... {v+=15; if (tablin[piliwr[0]] equal tablin[piliwr[1]]) v+=30; } } //if (pilibr[0]!=0) {v-=(9-tabrow[pilibr[0]]); // if (tabrow[pilibr[0]]<3) v-=5; // if (tabrow[pilibr[0]] equal tabrow[sqwk]) v-=8; // } if (pilibr[1]!=0) {//v-=(9-tabrow[pilibr[1]]); //if (tabrow[pilibr[1]]<3) v-=5; //if (tabrow[pilibr[1]] equal tabrow[sqwk]) v-=8; if (attack_b_min[pilibr[0]] equal b_r or // unsure attack_b_min[pilibr[1]] equal b_r) // test... {v-=15; if (tablin[pilibr[0]] equal tablin[pilibr[1]]) v-=30; } } } // be carefull to give a piece for 3 pawns; your pawns may be hunted... if (piliwq[11]==pilibq[11] and piliwr[11]==pilibr[11]) {if (piliwb[11]+piliwn[11] > pilibb[11]+pilibn[11]) v+=25*pilibp[11]; else if (pilibb[11]+pilibn[11] > piliwb[11]+piliwn[11]) v-=25*piliwp[11]; } vurd_g=v; if (wmatply != bmatply) // drop this if-line (faster?) // this can be calculated iterative (faster) {exch_pct = ( ((wmatply - bmatply ) * 10 ) // better / (((wmatply + bmatply // formula... - two_kings ) / exchf ) + 1 ) ); if (exch_pct> 70) exch_pct= 70; else if (exch_pct<-70) exch_pct=-70; } else exch_pct=0; v+=exch_pct; vurd_h=v; if (p[ply].pawnchange equal true) /* and intern equal black*/ {if ((magic != 4 and ((wh_bl equal black and v+limitpawnscorebest_score[ply_1]) ) ) or (wpawn equal 0) ) goto keine_bewerte; v+=bewerte_stellung(); } keine_bewerte: vurd_i=v; if (king_centre != 0) { // keep kings away from the centre until the early endgame v+=(4 - (abs(materiel_10_0 - 3))) * (4,5-tablin[sqbk]) * (4,5-tablin[sqbk]); v+=(4 - (abs(materiel_10_0 - 3))) * (4,5-tabrow[sqbk]) * (4,5-tabrow[sqbk]); v-=(4 - (abs(materiel_10_0 - 3))) * (4,5-tablin[sqwk]) * (4,5-tablin[sqwk]); v-=(4 - (abs(materiel_10_0 - 3))) * (4,5-tabrow[sqwk]) * (4,5-tabrow[sqwk]); } if (king_corner != 0) {if (wmatply-bmatply >= men_value[w_r]) v+=( (3 * (4,5-tablin[sqbk]) * (4,5-tablin[sqbk]) ) // get king into + (3 * (4,5-tabrow[sqbk]) * (4,5-tabrow[sqbk]) ) // the corner //if (wmatply <= men_value[w_k] and pilibp[11] equal 0) // get king into // v-=100 * (abs((4,5-tablin[sqwk]) * (4,5-tabrow[sqwk])));// the corner - (4 * abs(tablin[sqwk]-tablin[sqbk]) ) // attack with - (4 * abs(tabrow[sqwk]-tabrow[sqbk]) ) // the king ); ////////////////////////// else if (bmatply-wmatply >= men_value[w_r]) v-=( (3 * (4,5-tablin[sqwk]) * (4,5-tablin[sqwk]) ) // get king into + (3 * (4,5-tabrow[sqwk]) * (4,5-tabrow[sqwk]) ) // the corner - (4 * abs(tablin[sqwk]-tablin[sqbk]) ) // attack with - (4 * abs(tabrow[sqwk]-tabrow[sqbk]) ) // the king ); } //if (bmatply equal men_value[w_k] and // KPK // wmatply equal (men_value[w_k] + men_value[w_p]) // ) // {}; // how do we do that.....................? // if (dead_draw() equal true) // v=draw_score; // KBK or KNK or KK or evt. KBB...K // else if (ply>DRAWPLY and probably_draw() equal true) // v=draw_score; // KNNK.... if (sq[a8] equal w_n or sq[h8] equal w_n) v-=20*materiel_10_0; if (sq[a1] equal b_n or sq[h1] equal b_n) v+=20*materiel_10_0; vurd_j=v; /* printf("\n %d %d %d %d %d",v, ((mobilitet[iteration]) * sgn_wh_bl * wmobil / 8 / 4), ((-mobilitet[iteration-1]) * sgn_wh_bl * wmobil / 8 / 4), iteration, centre[ply]*wcentr/8 ); */ retur: /* if (iteration equal 1 //and ply ==4 and move_fr[0][move_pointer[0]]==h1 and move_to[0][move_pointer[0]]==f1 // and move_fr[1][move_pointer[1]]==d2 // and move_to[1][move_pointer[1]]==d3 // and move_fr[2][move_pointer[2]]==b8 // and move_to[2][move_pointer[2]]==c6 // and move_fr[3][move_pointer[3]]==d3 // and move_to[3][move_pointer[3]]==e4 // and move_fr[4][move_pointer[4]]==e8 // and move_to[4][move_pointer[4]]==f8 and v equal 62 ) { print_line(); printf("\n score v = %d", v); printf("\n vurd_a-j: ma:%d op:%d rnd:%d ksaf:%d mob:%d cen:%d pair:%d div:%d exch:%d pawn:%d div2:%d", vurd_a, vurd_a2, vurd_b, vurd_c, vurd_d, vurd_e, vurd_f, vurd_g, vurd_h, vurd_i, vurd_j); press_a_k_t_c(); } */ /* if (v equal 487) {print_line(); show_board(); press_a_k_t_c();} */ if (b_insufmat equal true and vdraw_score) v=draw_score; vu=v; gem_vurd=v; //if (gem_sel_vurd[ply] != 30111) // {if (gem_sel_vurd[ply] equal v) printf(":");} giver ingen hits... return v; } signed char msmoves() { if (ply equal 0) return 125; if (mate_sch_pos[ply]< 2) return 0; if (mate_sch_pos[ply]=b_k) {if (attack_w_min[piecesquare]>w_k or ((men_value[-1 * attack_b_min[piecesquare]] - men_value[ sq[piecesquare]])<-120) ) quiet=false; } } void is_b_piece_quiet(signed char piecesquare) { if (attack_w_min[piecesquare]<=w_k) {if (attack_b_min[piecesquare]