//////////////////////////// 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 x1, y1, 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 10x12 + 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]; 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_silly1_fr, pb_silly2_fr, pb_silly2w_fr; signed char pb_silly1_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) 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() { if (hvid==1) {hvid=0; setfillstyle(SOLID_FILL,BLACK);} else {hvid=1; setfillstyle(SOLID_FILL,WHITE);} } void rammefirkant(int x, int y, int x2, int y2) // firkant med sort ramme { 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); } 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 (y1=1; y1<50; ++y1) // en ramme om br‘ttet tegnes {if (y1 equal 5) setcolor(BLACK); rectangle(board_x-y1, board_y-y1, board_x+y1+8*sqwidth-1, board_y+y1+8*sqwidth-1); } 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); x1=w2_char-1; y1=7-(w3_char-1); if (square_colour(&w1_char) equal white) setfillstyle(SOLID_FILL,LIGHTGRAY); else setfillstyle(SOLID_FILL,DARKGRAY); square_x=board_x+(x1*sqwidth); // feltet 'nordvest' square_y=board_y+(y1*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(); } } } setcolor(RED); // br‘ttets koordinater s‘ttes p† for (x1=0, nr[1]='\0', *nr='a'; x1<8; ++x1,++nr[0]) outtextxy(board_x+x1*sqwidth+(10*sqwidth/25), board_y+(208*sqwidth/25), nr); for (y1=0, nr[1]='\0', *nr='8'; y1<8; ++y1,--nr[0]) outtextxy(board_x-(15*sqwidth/25), board_y+y1*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 (x1>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]=0) return p[x].hash_id; x2=game_pointer+x; if (x2>=0) return game_id[x2]; else return 0; } long unsigned int find_hash_idx(signed int x) { signed int x2; if (x>=0) return p[x].hash_idx; x2=game_pointer+x; if (x2>=0) return game_idx[x2]; else return 0; } #ifdef VARIANTS int rooksquare_mate() { if (sq[a8]>=w_p or sq[h8]>=w_p or sq[a1]<=b_p or sq[h1]<=b_p) return true; else return false; } #ifdef EXTINCT int extinct_mate() { if (piliwn[11]==0 or pilibn[11]==0 or piliwb[11]==0 or pilibb[11]==0 or piliwq[11]==0 or pilibq[11]==0 or piliwr[11]==0 or pilibr[11]==0 or piliwp[11]==0 or pilibp[11]==0) return true; else return false; } #endif #endif int repeat_position() { signed int x=ply-4; r_p: if (x 5000) trace=2; //if (bioskey(1)!=0) beep(); // slettes igen - giver 10% ekstra tid fr=*zfr; to=*zto; ++ply; ++ply_1; if (wh_bl equal white) mms[ply]=int_max+ply; // flyttes l‘ngere ned... else mms[ply]=int_min-ply; gem_sel_vurd[ply]=30111; #ifdef CHECKALL if (p[0].pawnchange != false) { //#ifdef ONLYFORJENS happens[1]='1'; //#endif } // {printf(" p[0].pawnchange "); add_error();} #endif p[0].pawnchange=false; // skal slettes igen // if (solution_xxx[43]=='+' and tv_nodes equal 4698) // if (tv_nodes equal 3358) // {print_line(); // show_board(); // press_a_k_t_c();} // if (solution_xxx[5]=='7' or solution_xxx[1]=='7') // if (p[0].w_o_o_o != 0) // {print_line(); // show_board(); // press_a_k_t_c();} #ifdef CHECKALL if (sq[a1]==w_r and sq[h1]==w_r) {if (sq[c1]==w_r or sq[f1]==w_r) {add_error(); } } // if (sq[fr] equal sq_empty) giver hit // add_error; hver gang?????? #endif mobilitet[ply]=0; // hjaelper det? nej......... sel_side[ply]=sel_side[ply_1]; #ifdef CHECKALL if (sq[h8+1] != sq_illegal) {add_error(); print_line(); printf("error i8.. "); press_a_k_t_c();} if (iteration==0 and sel_side[ply]!=white and sel_side[ply]!=black and ply>=first_dynamic_sel_ply[ply] and ply>2) {add_error(); printf("sel-side... "); if (status==self_play or status==everplay) {print_line(); press_a_k_t_c();} } if (intern!=white and intern!=black) {printf("intern... "); print_line(); press_a_k_t_c(); } #endif if (ply>1) { if (best_score[ply-2] equal start_best_score[ply-2]) best_score[ply]=start_best_score[ply]; else best_score[ply]=best_score[ply-2]; } else {best_score[1]=start_best_score[1]; // ud 8/10 if (iteration equal last_iteration) // not the optimal way... if (black_8 equal 8) r=4; else r=8; random_move=( (black_8 * ((rand() % 13) - 6) ) / r) * wrand / 8; if (black_8 < 6) random_move=0; #ifdef RANDOMOFF random_move=0; #endif //if (black_8 equal 8 and fr equal e2 and to equal e4) // random_move+=6; // play more 1.e4.... if (black_8 equal 8 and fr equal e7 and to equal e5 and sq[e4] equal w_p) random_move-=15; // play more 1.e4,e5.... if (black_8 equal 8 and fr equal g8 and to equal f6 and sq[e4] equal w_p and sq[e5] equal sq_empty) random_move+=222; // play less/never 1.e4,Nf6 // if (everplay_and_black() equal false) { if (sq[fr] equal w_p and piliwp[11]>4) {random_move+=(piliwp[11]-4); if (to-fr equal +20) random_move+=4;} if (sq[fr] equal b_p and pilibp[11]>4) {random_move-=(pilibp[11]-4); if (to-fr equal -20) random_move-=4;} if (fr==f1 and to==g2 and sq[f1]==w_b) random_move+=8; if (fr==c1 and to==b2 and sq[c1]==w_b) random_move+=8; if (fr==f8 and to==g7 and sq[f8]==b_b) random_move-=8; if (fr==c8 and to==b7 and sq[c8]==b_b) random_move-=8; if (fr==e1 and to==g1 and sqwk==e1) random_move+=10; if (fr==e1 and to==c1 and sqwk==e1) random_move+=6; if (fr==e8 and to==g8 and sqbk==e8) random_move-=10; if (fr==e8 and to==c8 and sqbk==e8) random_move-=6; if (to<=h8) // and everplay_and_black() equal false) {if (sq[to]<=b_p) random_move+=15; else if (sq[to]>=w_p) random_move-=15;} //else happens[12]='2'; yes, it happens if (sq[fr] equal w_p) random_move+=10; // can be coded better.... if (sq[fr] equal b_p) random_move-=10; } } p[ply]=p[ply_1]; nullmove[ply]=99; uli_sletigen=p[ply].hash_id; uli_sletigenx=p[ply].hash_idx; uli_sletigen =uli_sletigen exor randi_id [0][0]; uli_sletigenx=uli_sletigenx exor randi_idx[0][0]; sel_delay[ply]=sel_delay[ply_1]; first_dynamic_sel_ply[ply]=first_dynamic_sel_ply[ply_1]; w_materiel[ply]=w_materiel[ply_1]; b_materiel[ply]=b_materiel[ply_1]; #ifdef CHECKALL if (frh8 or sq[fr]==sq_illegal) {add_error(); print_line(); printf("error fr.. "); press_a_k_t_c();} if (ply<1) add_error(); #endif promotion=false; p[ply].e_p=not_allowed; if (fr equal to) /*random_move=0;*/ {centre[ply]=centre[ply_1]+30*wh_bl; goto nm;} // nullmove fr_before=sq[fr]; move_fr_before[ply_1]=fr_before; uli_sletigenx=uli_sletigenx exor randi_idx[fr][bw_index(fr_before)]; uli_sletigen =uli_sletigen exor randi_id [fr][bw_index(fr_before)]; if (fr_before equal w_p * wh_bl) /* et bondetraek? */ {p[ply].pawnchange=true; p[ply].draw50=0; if (to<=h8) /* forvandling? nej */ {if (abs(to - fr) equal 20) // bondes dobbeltskridt //{p[ply].e_p= fr + 10 * wh_bl; gl. version - hurtigere?! p[ply].e_p=((fr+to)/2); // } else {if (abs(to - fr) != 10 and sq[to] equal sq_empty) /* e.p. */ // tablin is probably slower... {work_ep=to - 10 * wh_bl; delete_pili(&work_ep, &sq[work_ep]); uli_sletigenx=uli_sletigenx exor randi_idx[work_ep][bw_index(sq[work_ep])]; uli_sletigen =uli_sletigen exor randi_id [work_ep][bw_index(sq[work_ep])]; sq[work_ep] = sq_empty; /* bonden skal fjernes */ if (wh_bl equal white) b_materiel[ply] -= men_value[w_p]; else w_materiel[ply] -= men_value[w_p]; } } } else /* forvandling? ja */ {promotion=true; sel_delay[ply] += 4; unpack_promotion(&to, &to_9_10_11, &promote_piece); to=fr + wh_bl * to_9_10_11; if (wh_bl equal white) w_materiel[ply] += men_value[promote_piece] - men_value[w_p]; else b_materiel[ply] += men_value[promote_piece] - men_value[w_p]; } } else {if (fr_before equal w_r * wh_bl) p[ply].pawnchange=true; if (sq[to] equal sq_empty) ++p[ply].draw50; else p[ply].draw50=0; } #ifdef CHECKALL if (toh8 or sq[to]==sq_illegal) {add_error(); print_line(); printf("error to.. "); press_a_k_t_c();} #endif if ((p[ply].e_p==not_allowed and p[ply_1].e_p!=not_allowed) or // billig l›sning - kan skrives hurtigere bin‘rt med exor............... (p[ply].e_p!=not_allowed and p[ply_1].e_p==not_allowed)) {uli_sletigenx=uli_sletigenx exor randi_idx[0][1]; uli_sletigen =uli_sletigen exor randi_id [0][1]; } if (ply equal 1 and info_out==1) { printf("\n "); print_kqrbnp(sq[fr]); print_a1_h8(&fr); print_a1_h8(&to); printf(" : ");} if (ply equal 2 and info_out==1) {if (move_pointer[1] < 3) {print_kqrbnp(sq[fr]); print_a1_h8(&fr); print_a1_h8(&to); printf(" ");} else printf("*"); } to_before=sq[to]; move_to_before[ply_1]=to_before; if (fr equal e1 or fr equal h1 or to equal h1) p[ply].w_o_o=not_allowed; if (fr equal e8 or fr equal h8 or to equal h8) p[ply].b_o_o=not_allowed; if (fr equal e1 or fr equal a1 or to equal a1) p[ply].w_o_o_o=not_allowed; if (fr equal e8 or fr equal a8 or to equal a8) p[ply].b_o_o_o=not_allowed; if (to_before != sq_empty) {uli_sletigenx=uli_sletigenx exor randi_idx[to][bw_index(to_before)]; uli_sletigen =uli_sletigen exor randi_id [to][bw_index(to_before)]; delete_pili(&to, &to_before); if (wh_bl equal white) {man=men_value[to_before * -1]; b_materiel[ply] -= man;} else {man=men_value[to_before ]; w_materiel[ply] -= man;} if (man equal men_value[w_q]) sel_delay[ply] += 4; else if (man equal men_value[w_r]) {sel_delay[ply] += 3; p[ply].pawnchange=true; } else if (man equal men_value[w_b]) sel_delay[ply] += 2; else if (man equal men_value[w_n]) sel_delay[ply] += 2; else {sel_delay[ply] += 1; p[ply].pawnchange=true; } } if (promotion equal true) {sq[to]=promote_piece * wh_bl; delete_pili(&fr, &fr_before); // hmmmmmmm add_pili(&to, &sq[to]); // hmmmmmmm } else {sq[to]=fr_before; change_pili(&fr, &to, &fr_before); } uli_sletigenx=uli_sletigenx exor randi_idx[to][bw_index(sq[to])]; uli_sletigen =uli_sletigen exor randi_id [to][bw_index(sq[to])]; sq[fr]=sq_empty; /* selve traekket udfoeres */ // if (fr_before equal w_p) // centre[ply]=centre[ply_1]-wBFeldWert[fr]+wBFeldWert[to]; // else {if (fr_before equal b_p) // centre[ply]=centre[ply_1]+sBFeldWert[fr]-sBFeldWert[to]; // else centre[ply]=centre[ply_1]+wh_bl*((centrum[to]-centrum[fr])/4); // } if (fr_before>w_p or fr_before4) fr_li=9-fr_li; to_li=tablin[to]; if (to_li>4) to_li=9-to_li; if (fr_li != to_li) // both may be 4.... {if ((to_li>fr_li and fr_before equal w_p) or (to_li1)*/ {happens[0]='0'; #ifdef ONLYFORJENS show_board(); print_line(); press_a_k_t_c(); #endif ++tv_hash_error; } } #endif // uli_id_index=uli_idx & hash_maxindex; // if (ply > USEHASHABOVEPLY) {uli_id_index=uli_sletigenx & hash_maxindex; read_hash(uli_id_index); ++tv_hash_read; if (uli_sletigen!=hash.hash_id or uli_sletigenx!=hash.hash_idx) hash.hash_fr=0; else {++tv_hash_read_ok; ///* //if (hash.hash_score>30000) press_any_key_to_continue; //// if (ply>=2 and hash.hash_score_final equal false and hash.hash_depth>=iteration-ply) { if (wh_bl equal white) {if (hash.hash_score<=best_score[ply_1]) // and make2_move.. {make_move_status=make_cut_off; ++tv_hash_nofinal; //change_black_white(); turn_sqavoid_false(); best_score[ply]=hash.hash_score; goto make_move_slut; } } else {if (hash.hash_score>=best_score[ply_1]) // and make2_move.. {make_move_status=make_cut_off; ++tv_hash_nofinal; //change_black_white(); turn_sqavoid_false(); best_score[ply]=hash.hash_score; goto make_move_slut; } } } //*/ } } //else hash.hash_fr=0; } else hash.hash_fr=0; if (hop_ud equal true) goto make_move_slut; #ifdef VARIANTS if (chess_variant equal rooksquare) {if (sq[a8]>=w_p or sq[h8]>=w_p) {make_move_status=score_is_found; best_score[ply]=int_max-ply; goto make_move_slut; } if (sq[a1]<=b_p or sq[h1]<=b_p) {make_move_status=score_is_found; best_score[ply]=int_min+ply; goto make_move_slut; } } #ifdef EXTINCT if (chess_variant equal extinct) {if (fr_before!=sq_empty and extinct_mate() equal true) // fr..... {make_move_status=score_is_found; if (wh_bl equal white) //(fr_before>=w_p) best_score[ply]=int_max-ply+2; // hmmmmmm else best_score[ply]=int_min+ply-2; goto make_move_slut; } } #endif #endif #ifdef VARIANTS #else if (to_before!=sq_empty or ply equal 1) // opr. fr... {if (dead_draw() equal true) {make_move_status=score_is_found; best_score[ply]=draw_score; goto make_move_slut; } } if (ply>DRAWPLY and probably_draw() equal true) {make_move_status=score_is_found; best_score[ply]=draw_score; goto make_move_slut; } #endif if ( (p[ply].draw50>=100) or (/*everplay_and_black() equal false and*/repeat_position() equal true) /* and fr equal move_to[ply-3][move_pointer[ply-3]] and to equal move_fr[ply-3][move_pointer[ply-3]] and move_to[ply-2][move_pointer[ply-2]]==move_fr[ply-4][move_pointer[ply-4]] and move_to[ply-4][move_pointer[ply-4]]==move_fr[ply-2][move_pointer[ply-2]] and move_to_before[ply-3] equal sq_empty and move_to_before[ply-4] equal sq_empty and swrepeat4 equal 1 */ // (ply>3 and p[ply-4].hash_id equal uli_sletigen // and p[ply-4].hash_idx equal uli_sletigenx // and swrepeat4 equal 1 // ) ) {make_move_status=score_is_found; if (p[ply].draw50<100) ++tv_repeat; // dum if best_score[ply]=draw_score; goto make_move_slut; } //#ifdef DAB4KORR //#else if (hash.hash_fr!=0) {if (hash.hash_score_final equal true and hash.hash_depth>=iteration-ply) {make_move_status=score_is_found; ++tv_hash_read_ok_final; best_score[ply]=hash.hash_score; goto make_move_slut; } // else....... } //#endif if (ply equal last_ply) {++tv_last_ply; /* if (ply<=trace) printf("lp:"); */ // if ((wh_bl==black and discovered_check(&fr, &to, &sqbk)==true) // or (wh_bl==white and discovered_check(&fr, &to, &sqwk)==true)) // {make2_move_status=pseudo_move; // ++tv_pseudo_moves; // goto make_move_slut; // } if (is_move_a_check(&fr, &to) equal false) {realmoves[ply]=1; king_in_check[ply]=false; goto make_move_slut; } } /* if (tv_nodes == 10420) { show_board(); print_line(); press_a_k_t_c();} */ nm: // jump to here for a nullmove make_only_attack(); 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[ply]=true; sel_delay[ply] += 2; } else king_in_check[ply]=false; change_black_white(); if (ply<=first_sel_ply-2 and king_in_check[ply] equal false and nullmove[ply_1] equal 99 and iteration>0 // ordinary search; not the matesearch //and move_pointer[ply_1]>0 // a little slower (330->340) with this. and w_materiel[ply]>men_value[w_k]+800 and b_materiel[ply]>men_value[w_k]+800 and swnullmove equal 1 and everplay_and_black() equal false) {if (ply equal first_sel_ply-2) rr=-1; else rr=-2; p[ply].swnullhash=1; nullmove[ply]=rr; first_sel_ply+=rr; last_ply+=rr; } if (ply>=first_sel_ply and first_dynamic_sel_ply[ply] equal 99 and ply < last_ply ) // dynamic change from brute force to selective search {first_dynamic_sel_ply[ply]=ply; #ifdef CHECKALL if (ply==0) {add_error(); printf("ply nul... ");} #endif sel_side[ply]=wh_bl; } husk=false; quiet=true; break_point(); // "Positionelle Selektivit„t" if (ply equal iteration-1 and iteration>=3 and king_in_check[ply] equal false and quiet_position() equal true and mateinx equal 0 ) {jub=vurdering(); if (wh_bl equal black) {jub-=10; if (jub<=best_score[ply_1] and make2_move_status!=pseudo_move) goto jubii; // {make_move_status=make_cut_off; // change_black_white(); turn_sqavoid_false(); // goto make_move_slut; // } } else {jub+=10; if (jub>=best_score[ply_1] and make2_move_status!=pseudo_move) { jubii: make_move_status=make_cut_off; best_score[ply]=jub; change_black_white(); turn_sqavoid_false(); //printf(" jub "); goto make_move_slut; } } } // else if (ply==4) {print_line(); press_a_k_t_c(); } gem_sel_side=sel_side[ply]; if (ply >= first_dynamic_sel_ply[ply] and wh_bl equal gem_sel_side // sel_side[ply] and ( (iteration equal 0 and king_in_check[ply] equal false // 01 jan. 98 ) or (king_in_check[ply] equal false and (ply > quiet_depth + first_dynamic_sel_ply[ply] or quiet_position() equal true) ) ) ) {sel_ply_now=true; husk=true; if (iteration equal 0 and ply<7) // don't trust score... goto l1; // (Nero / Benjamin Good) // passer dybde med dybde i is-move-a-sel-move (2x)? {vurd=vurdering(); // selektivt move // if (ply equal 1) move_value[0] [move_pointer[0]]=vurd; // n›dv.?? gem_sel_vurd[ply]=vurd; mms[ply]=vurd; if ((wh_bl equal white and vurd>best_score[ply]) or (wh_bl equal black and vurd=best_score[ply_1] and make2_move_status!=pseudo_move) { jubiii: make_move_status=make_cut_off; change_black_white(); turn_sqavoid_false(); goto make_move_slut; } } } if (ply equal first_dynamic_sel_ply[ply] // if (ply <= first_dynamic_sel_ply[ply]+ant_sel_ply // nyt pr. 20 juni // ikke helt korrekt...... and sel_delay[ply]>=qdynamic) {sel_ply_now=false; //sel_delay[ply] -= qdynamic; // disse 2 linier /* if (magic != 3) */ sel_delay[ply]=-122; // kan fjernes... } } else {sel_ply_now=false; if (ply >= first_dynamic_sel_ply[ply]) { if (gem_sel_side equal wh_bl // f›r sel_side[ply] and (king_in_check[ply] equal true // or quiet equal false no good idea... ) and skift equal 1) /* skift....... */ {++first_dynamic_sel_ply[ply]; /* initiativet skifter! */ sel_side[ply]*= -1; } } } l1: only_recapture=false; // bruges til at udv‘lge selektive tr‘k if ((sel_ply_now equal false or iteration > 0) and // sel_side[ply] != wh_bl and king_in_check[ply] equal false and (iteration equal 0 or ply > first_dynamic_sel_ply[ply]+3 ) and ((wh_bl == white and (w_materiel[ply]-b_materiel[ply]) < (w_materiel[0]-b_materiel[0]) ) or (wh_bl == black and (w_materiel[ply]-b_materiel[ply]) > (w_materiel[0]-b_materiel[0]) ) ) ) {sel_ply_now=true; only_recapture=true; husk=true; best_score[ply]=vurdering(); // only capture - n›dvendig? mms[ply]=best_score[ply]; if (ply<=trace) {print_line(); printf(" (sel-recap) "); press_a_k_t_c();} } tv_non_sel_move=0; make_move_array(); change_black_white(); if (iteration equal 0) {if (mobilitet[ply]>0) {if (wh_bl equal intern) {mobili=msmoves(); if (mobili equal 0) mobili=1; else if (mobili>mobilitet[ply]) mobili=mobilitet[ply]; mate_sch_pos[ply] = mate_sch_pos[ply_1] / (double)mobili; } else mate_sch_pos[ply] = mate_sch_pos[ply_1]/(double)mobilitet[ply]; } else mate_sch_pos[ply] = mate_sch_pos[ply_1]; } if (husk==true and tv_non_sel_move>0) realmoves[ply]=123; if (make2_move_status equal pseudo_move) ++tv_pseudo_moves; make_move_slut: // sq_avoid_check[to]=false; #ifdef CHECKALL if (sq[a1] != w_r and p[ply].w_o_o_o equal allowed) add_error(); #endif ++tv_nodes; change_black_white(); } void undo_move() {signed char fr, to, to_9_10_11, promote_piece, work_ep; vurd_node=-1; // if (sq[a1]==w_r and sq[h1]==w_r) // {if (sq[c1]==w_r or sq[f1]==w_r) // if (tv_nodes equal 3937) // {print_line(); // show_board(); // press_a_k_t_c();} // } --ply; --ply_1; change_black_white(); make_move_status=normal_move; make2_move_status=normal_move; if (magic equal 7) show_board(); /* tr‘kket f›res tilbage p† br‘ttet */ fr=move_fr[ply][ move_pointer[ply]]; to=move_to[ply][ move_pointer[ply]]; if (nullmove[ply]<99) {first_sel_ply-=nullmove[ply]; last_ply-=nullmove[ply]; nullmove[ply]=99; goto nm; } sq[fr]=move_fr_before[ply]; if (to>h8) /* ved forvandling skal to-feltet beregnes */ {unpack_promotion(&to, &to_9_10_11, &promote_piece); to=fr + wh_bl * to_9_10_11; add_pili(&fr, &sq[fr]); //hmmmmmm delete_pili(&to, &sq[to]/*&move_to_before[ply] &promote_piece*/);//hmmmmmm } else change_pili(&to, &fr, &sq[fr]); sq[to]=move_to_before[ply]; // sq_avoid_check[to]=false; // hj‘lper lidt: errors 7---->2 if (sq[to] != sq_empty) add_pili(&to, &sq[to]); if (fr equal e1 and to equal g1 and sq[e1] equal w_k) {sq[f1]=sq_empty; sq[h1]=w_r; change_castle_pili(f1, h1, w_r);}; if (fr equal e1 and to equal c1 and sq[e1] equal w_k) {sq[d1]=sq_empty; sq[a1]=w_r; change_castle_pili(d1, a1, w_r); }; if (fr equal e8 and to equal g8 and sq[e8] equal b_k) {sq[f8]=sq_empty; sq[h8]=b_r; change_castle_pili(f8, h8, b_r); }; if (fr equal e8 and to equal c8 and sq[e8] equal b_k) {sq[d8]=sq_empty; sq[a8]=b_r; change_castle_pili(d8, a8, b_r);}; if ((sq[fr] equal w_p * wh_bl) and (abs(to - fr) != 20)) {if (//tablin[to] != tablin[fr] a little slower than... abs(to - fr) != 10 and sq[to] equal sq_empty) // e.p. {work_ep=to - 10 * wh_bl; sq[work_ep] = b_p * wh_bl; // set in the pawn add_pili(&work_ep, &sq[work_ep]); } } if (best_score[ply] equal start_best_score[ply+1]) move_pointer[ply]=125; else ++move_pointer[ply]; // point at the next move nm: // jump to here for a nullmove } void make_evt_drucker_delay(double wtid) { if (henttid()-wtid<200) // move faster than 2 seconds...? make_delay(200-(henttid()-wtid)); // don't play too fast... } void print_best_move_ply_zero(int I_play) { signed char wto, wto_9_10_11, wpromote_piece, prom; char t[16], tegn[6]; prom=' '; wto=best_move_to[0]; if (wto>h8) {unpack_promotion(&wto, &wto_9_10_11, &wpromote_piece); wto=best_move_fr[0] + wto_9_10_11 * wh_bl; prom=men_letter[wpromote_piece]; } if (I_play equal true and status!=self_play) {if (sq[best_move_fr[0]]>=w_p) strcpy(tegn,". "); else strcpy(tegn,". -,"); printf("%d%s",(1+((mpc/*-1*/)/2)),tegn);} if (sq[best_move_fr[0]] equal sq_empty) print_kqrbnp(sq[wto]); else print_kqrbnp(sq[best_move_fr[0]]); print_a1_h8(&best_move_fr[0]); if (save_games equal true and I_play equal true) pgn_a1_h8(&best_move_fr[0]); if (drucker equal true and I_play equal true) {make_evt_drucker_delay(timemovestart); sprint_a1_h8(&best_move_fr[0]); if (sq[wto] equal sq_empty) t[0]='-'; else t[0]='x'; t[1]=0; drucke_text(t); } // dette med - og x g†r vist kun til sidst(I-play)..... if (sq[best_move_fr[0]] != sq_empty) {if (sq[wto] equal sq_empty) printf("-"); else printf("x"); } print_a1_h8(&wto); if (save_games equal true and I_play equal true) {pgn_a1_h8(&wto); fprintf(pgn,"%c ",prom); if ((mpc+1) % 10 equal 0 and evermoves_160!=16) fprintf(pgn,"\n"); } if (drucker equal true and I_play equal true) {sprint_a1_h8(&wto); sprintf(t,"%c",prom); t[2]=0; drucke_text(t); drucke_crlf(); } printf("%c",prom); } int mate_found() { if ((intern==white and best_score[0]>(int_max-100)) or (intern==black and best_score[0]<(int_min+100))) return true; else return false; } void opdat_hash(signed char fr, signed char to, signed int score) { signed char final, surprise, zz; if (ply_1<=plydyb and swhash==1 and p[ply].swnullhash==0 //and ply_1 > USEHASHABOVEPLY ) { if (move_fr [ply_1][move_pointer[ply_1]+1] equal stop) final=true; else final=false; uli_id_index=p[ply_1].hash_idx & hash_maxindex; read_hash(uli_id_index); if (ply_1==plydyb and hash.hash_mpc>mpc-2) goto ej; if (hash.hash_ply<3 and hash.hash_plyhash.hash_mpc /*or iteration-1>hash.hash_iteration*/) goto opdat; surprise=move_pointer[ply_1] / 8; if (hash.hash_score_final equal false and final equal true) zz=2; else zz=0; if ((iteration-ply_1+surprise+zz)>=hash.hash_depth) goto opdat; ej: ++tv_hash_ejskriv; goto efter_skriv; opdat: hash.hash_depth=iteration-ply_1; ++tv_hash_opdat; hash.hash_score=score; hash.hash_score_final=final; hash.hash_fr=fr; hash.hash_to=to; skriv: hash.hash_mpc=mpc; hash.hash_ply=ply_1; hash.hash_id=p[ply_1].hash_id; hash.hash_idx=p[ply_1].hash_idx; uli_id_index=hash.hash_idx & hash_maxindex; write_hash(uli_id_index); ++tv_hash_skriv; efter_skriv: } } void new_best_move() {signed char ch2, ch3; //, final, surprise, zz; gem_sel_vurd[ply_1]=30111; // hmmmmmm best_score [ply_1]=best_score[ply]; best_move_fr[ply_1]=move_fr [ply_1][move_pointer[ply_1]]; best_move_to[ply_1]=move_to [ply_1][move_pointer[ply_1]]; #ifdef PBSILLY //if (pb_on equal true) {//if (ply<=2) print_line(); if (ply_1==2) {pb_silly2w_fr=best_move_fr[2]; pb_silly2w_to=best_move_to[2];} else if (ply_1==1) {pb_silly1_fr=best_move_fr[1]; pb_silly1_to=best_move_to[1]; pb_silly2_fr=pb_silly2w_fr; pb_silly2_to=pb_silly2w_to;} }; #endif opdat_hash(best_move_fr[ply_1], best_move_to[ply_1], best_score[ply]); if (ply equal 1) {most_recent_best_score=best_score[0]; if (iteration>0 and mate_ply equal -1 and mate_found() equal true and mateinx equal 0) mate_ply=iteration+1; if (iteration>0 and magic==23) matesearch_score=no_good_found; // for at undg† Bc4xf7+ (se badmoves) fundet i matesearch med score -200.... if (gameplay equal true and dummy_search equal false and status!=everplay) {writesecsofar_gi(); fprintf(gi,"best move so far: "); sq120_to_koordinat(&best_move_fr[0], &ch2, &ch3); fprintf(gi,"%1c%1c",'a' - 1 + ch2, '0' + ch3); sq120_to_koordinat(&best_move_to[0], &ch2, &ch3); fprintf(gi,"%1c%1c",'a' - 1 + ch2, '0' + ch3); fprintf(gi," score: %d",best_score[0]); } if (disctrace equal true) {writesecsofar(); fprintf(fp,"best move so far: "); sq120_to_koordinat(&best_move_fr[0], &ch2, &ch3); fprintf(fp,"%1c%1c",'a' - 1 + ch2, '0' + ch3); sq120_to_koordinat(&best_move_to[0], &ch2, &ch3); fprintf(fp,"%1c%1c",'a' - 1 + ch2, '0' + ch3); fprintf(fp," score: %d",best_score[0]); } if ((info_out equal 1) or (filtrace equal true) or (run_test==true) or (gameplay==true and gameplay_info==true and dummy_search==false and pb_on equal false)) {printf("\nbest move so far: "); print_best_move_ply_zero(false); print_vurdering(best_score[0]); } if (mateinx>0 and mate_found() equal true) {//print_best_move_ply_zero(false); //print_vurdering(best_score[0]); if (matelvl_stop==true) press_any_key_to_continue(); matelvl_score=best_score[0]; if (best_score[0]>0) best_score[0]-=1; else best_score[0]+=1; matelvl_fr=best_move_fr[0]; matelvl_to=best_move_to[0]; } } } void minimax() { if (ply<=trace) {print_line(); press_a_k_t_c();} if (ply equal 1) {move_value[0] [move_pointer[0]]=best_score[1]; if (info_out==1) print_vurdering(best_score[1]); } if (wh_bl equal white) {if (best_score[ply] < mms[ply_1]) mms[ply_1]=best_score[ply]; if (best_score[ply] < best_score[ply_1]) new_best_move();} else {if (best_score[ply] > mms[ply_1]) mms[ply_1]=best_score[ply]; if (best_score[ply] > best_score[ply_1]) new_best_move();} //if (mateinx>0 and ply equal 1 and best_score[1]==best_score[0]) // new_best_move(); } /* void gem_top_killer(signed char *fr, signed char *to) { int x; x=find_move_index(&move_fr[0] [move_pointer[0]], &move_to[0] [move_pointer[0]]); #ifdef CHECKALL if (x>4000) {printf("\nLooooooooooop!-gem-top-killer!!\n\n"); print_line(); show_board(); press_any_key_to_continue();} else #endif kill_fr[x][0]=*fr; kill_to[x][0]=*to; // print_a1_h8(&move_fr[0] [move_pointer[0]]); // print_a1_h8(&move_to[0] [move_pointer[0]]); // print_a1_h8(&kill_fr[x][0]); // print_a1_h8(&kill_to[x][0]); // press_any_key_to_continue(); } */ void gem_simple_kill(signed char *m_fr, signed char *m_to) { int y, w_score; signed char c; if (move_to[ply-2] [move_pointer[ply-2]] equal *m_to) return; if (gem_sel_vurd[ply] equal 30111) w_score=best_score[ply]; else w_score=gem_sel_vurd[ply]; //if (a6 == *m_fr and b5 == *m_to and iteration>1 //and ply==1 // and best_score[ply+g]==-116) // {print_line(); show_board(); // press_a_k_t_c(); /*g+=0;*/ }; if (simple_kill1_fr[ply_1] == *m_fr and simple_kill1_to[ply_1] == *m_to) {++tv_s_kill1[ply_1]; --tv_s_kill2[ply_1]; simple_kill1_vu[ply_1]=w_score; //best_score[ply+g]; // +1]; return;} if (simple_kill2_fr[ply_1] == *m_fr and simple_kill2_to[ply_1] == *m_to) {++tv_s_kill2[ply_1]; --tv_s_kill1[ply_1]; simple_kill2_vu[ply_1]=w_score; //best_score[ply+g]; // +1]; return;} if (tv_s_kill1[ply_1]>tv_s_kill2[ply_1]) {simple_kill2_fr[ply_1]=*m_fr; simple_kill2_to[ply_1]=*m_to; simple_kill2_vu[ply_1]=w_score; //best_score[ply+g]; // +1]; //vu s_kill2_oldpre[ply_1]=oldpre_value[ply_1][move_pointer[ply_1]]; tv_s_kill2[ply_1]=1001; } else {simple_kill1_fr[ply_1]=*m_fr; simple_kill1_to[ply_1]=*m_to; simple_kill1_vu[ply_1]=w_score; //best_score[ply+g]; // +1]; //vu s_kill1_oldpre[ply_1]=oldpre_value[ply_1][move_pointer[ply_1]]; tv_s_kill1[ply_1]=1001; }; if (s_kill<=2 and tv_s_kill1[ply_1]1 or best_score[2]>int_max-100 or best_score[2]0 and do_gem_top() equal true) // gem_top_killer(&m_fr, &m_to); // if (ply <= 4 and best_score[ply] equal -30000 or // best_score[ply] equal +30000) // {++tv_cutoff; --tv_cutoff;} if (ply<=trace) {if (gem_sel_vurd[ply] != 30111) // nogen best_score[ply]=gem_sel_vurd[ply]; // effekt? // k o n f l i k t . . . . . . . printf(" Cut %d %d",best_score[ply], best_score[ply-2]); } ++tv_cutoff; if (wh_bl equal white) if (best_score[ply]mms[ply-2]) mms[ply-2]=best_score[ply]; gem_simple_kill(&m_fr, &m_to); ///* if (ply equal 2 and iteration != last_iteration and ((iteration equal 1 and magic equal 3) or (always !=1 and iteration equal 2) ) // or (iteration > 2 or iteration < 1)) // ny og gl. pr. 9 j u l i 97 ) {if (info_out==1) printf(" no-cut ");} else {if (make2_move_status!=pseudo_move) {undo_move(); //minimax(); } } //*/ /* // gammel if ( (iteration!=1) and // ny pr. 9 ju li 97 (ply != 2 or always equal 1 or iteration equal last_iteration or iteration != 2) // or (iteration > 2 or iteration < 1)) // ny og gl. pr. 9 ju li 97 ) {if (make2_move_status!=pseudo_move) undo_move();} else if (info_out==1) printf(" no-cut "); */ } void evt_cut_off() { if (wh_bl equal white) {if (best_score[ply]<=best_score[ply-2] ) {//if (best_score[ply]=best_score[ply-2] ) {//if (best_score[ply]>mms[ply-2]) mms[ply-2]=best_score[ply]; cut_off(); } } } void everplay_setup() { //-if (status equal everplay) //- {if (intern equal white) {wmobil=16; wcentr=16;} //- else {wmobil=10; wcentr=10;} } /// if (everplay_and_black() equal false) {w_antselply=0; quiet_depth=3;} //plydyb=gemplydyb;} /// else {w_antselply=4; quiet_depth=1;} //plydyb=1;} #ifdef QUIETEXPERIMENT #else w_antselply=4; quiet_depth=1; //plydyb=1; #endif //- {if (intern equal white) last_sel_ply=8; wmobil=16; wcentr=16; //- else last_sel_ply=6;} } signed char pb_move_guessed() { signed char wmove[5]; //if (pb_tv_1_4 != 4) return false; pb_move_received[4]=0; p99_a1_h8(&pb_move_fr); strcpy(wmove,p99); p99_a1_h8(&pb_move_to); strcpy(wmove+2,p99); wmove[4]=0; if (strcmp(".",pb_move_received) equal 0) strcpy(pb_move_received,wmove); if (strcmp(wmove,pb_move_received) equal 0) return true; else return false; } void add_movetime(double movetime, signed char no_nodes, double oppotid, double opponodes) { double estimated_time; //if ((intern equal white and pb_on equal false) or // (intern equal black and pb_on equal true)) //if (no_nodes equal true) {if (movetime<-1 or movetime>360000) // is sometimes -0.00000038575746 {if (save_games equal true) fprintf(pgn," {midnight-30!?} "); happens[3]='3'; movetime=3000; // midnightproblem... silly human movetime is set to 30 seconds } } /* else {estimated_time=(double)tv_nodes*100 / (200*(double)speedfactor); if (movetime+oppotid>(estimated_time*10) or movetime+oppotid<(estimated_time/10)) {if (save_games equal true) fprintf(pgn," {midnight!?} "); beep(); if (tv_nodes>opponodes) fghghgh else movetime=estimated_time; // midnightproblem... silly movetime is estimated... } } */ if (intern equal white) wtid+=movetime/100; else btid+=movetime/100; //for (;wtid<-999;) {wtid+=8640000; beep();} // skal slettes igen //for (;btid<-999;) {btid+=8640000; beep();} // skal slettes igen } void pb_undo_move_until_root() { for (; ply>0; ) {undo_move();} } void computer() { int finished=false, tpctmsf, tita; signed char gem_mobil_zero=0, bioschar, x; double tv_nodes_it_zero; gem_check_search=check_search; full_line=1; if (iteration equal 1) {tpct_it_zero=timepctmovesofar(); tv_nodes_it_zero=tv_nodes;} #ifdef QUIETEXPERIMENT if (secprmove>0 and everplay_and_black() equal false and ( (iteration==2 and tv_nodes - tv_nodes_it_zero< 500) or (iteration==3 and tv_nodes - tv_nodes_it_zero< 2500) or (iteration==4 and tv_nodes - tv_nodes_it_zero< 12500) or (iteration==5 and tv_nodes - tv_nodes_it_zero< 60000) ) ) w_antselply+=2; #endif if (iteration % 2 equal 0) sgn_wh_bl=wh_bl; else sgn_wh_bl=wh_bl * -1; is_castle_allowed(); qdynamic=it4_qdyn*iteration/4; if (qdynamic equal 0) qdynamic=100; first_sel_ply=iteration; if (//iteration>1 // evt. ogs† g›res i senere iterationer........ iteration>0 // ‘ndret 17 mar 97 and secprmove>0) {last_sel_ply=ANTSELPLY+w_antselply; // lagt ind 17 mar 97 /*everplay_setup();*/ // if (iteration equal 1) last_sel_ply=2; // lagt ind 17 mar 97 ant_sel_ply=last_sel_ply; last_sel_ply-=1; goto hertil;} // ant_sel_ply=2*iteration; // if (ant_sel_ply==last_sel_ply and iteration2) // ant_sel_ply=ant_sel_ply-2; // if (ant_sel_ply>last_sel_ply or iteration==last_iteration) ant_sel_ply=last_sel_ply; // check_search=2*iteration; // if (check_search==gem_check_search and iteration2) // check_search=check_search-2; // if (check_search>gem_check_search or iteration==last_iteration) check_search=gem_check_search; hertil: // if ( ((iteration+ant_sel_ply) % 2) equal 1) --ant_sel_ply; // 17 mar 97: ++ ---------> -- // dette b›r kunne fjernes engang....... fjernet 24 aug. '97 last_ply=iteration+ant_sel_ply+check_search; if (iteration equal 0) {ant_sel_ply=0; last_ply=(char)mslim[0]; check_search=last_ply; #ifdef CHECKALL if (sel_side[ply] != intern) add_error(); #endif } else if (limitpawnscore>5) limitpawnscore-=5; // slettes igen.... //if (pb_on equal true and move_fr[0][mobilitet[0]]!=stop) // beep(); if (pb_on equal true) move_pointer[0]=mobilitet[0]-1; else move_pointer[0]=0; // if (pb_on equal true) // { printf(" last-"); print_kqrbnp(sq[move_fr[0][move_pointer[0]]]); // print_a1_h8(&move_fr[0][move_pointer[0]]); // print_a1_h8(&move_to[0][move_pointer[0]]); // printf("-last"); // } if (disctrace equal true) {writesecsofar(); fprintf(fp,"Search to depth %d",(int)iteration); } if (gameplay equal true and dummy_search equal false and status!=everplay) {writesecsofar_gi(); fprintf(gi,"Search to depth %d",(int)iteration); } if ((gameplay==true and gameplay_info equal true and dummy_search!=true and pb_on equal false) or (run_test equal true)) printf("\n\n Search to depth %d",(int)iteration); if (info_out equal 0 and trace equal 0 and dummy_search!=true and run_test equal false and (pb_on equal false or pb_sw_move_received equal true) and status!=self_play and (gameplay==false or gameplay_info==false)) printf("%d ",(int)iteration); if (info_out equal 1 or trace > 0) {printf("\n\n Search to depth %d",(int)iteration); printf("\n plus a %d ply extended selektive search", (int)ant_sel_ply); if (it4_qdyn<80) printf(" (plus dynamic quiet move extension)"); printf("\n plus a %d ply check search\n", check_search); } // if (ply!=0) beep(); tita=0; titanic: if (filtrace equal true and iteration>0 and move_fr[0][tita] != stop) {printf("\n"); print_a1_h8(&move_fr[0][tita]); print_a1_h8(&move_to[0][tita]); printf(" vurd=%d", move_value[0][tita]); ++tita; goto titanic; } // if (matesearch_score != no_good_found) // flyttet fra initialize- // {best_move_fr[0]=ms_fr; // best-score.... // best_move_to[0]=ms_to; // tilsyneladende ikke n›dvendig... // } // kan stadig g† galt ved afbrydelse p† tid.... se 15 linier nede.... if (trace equal -29001) {show_board(); press_any_key_to_continue();} do { if (iteration equal 0 and wh_bl equal intern) {if (ply>last_ply or tv_nodes>msmax or move_pointer[ply]+mobilitet[ply]-realmoves[ply]>=msmoves() ) {move_pointer[ply]=mobilitet[ply]; goto her;} // nu } g: if (ply equal 1 and secprmove>0) {if (tv_nodes>check_time_at_nodes) {check_time_at_nodes=tv_nodes+(1000*speedfactor); // 21 okt if (iteration>2 and timepctmovesofar()>90) // 21 okt 97 {//if (move_pointer[1] equal 0) // dette ikke pr‘cist nok!!! // test p† move_pointer skal evt. v‘re 1................ // best_score[0]=gem_best_score_0; best_score[0]=most_recent_best_score; undo_move(); mark_nodesstop='#'; } } } get_next_good_move(); pb_move_typed_in: if (pb_on equal true) {++pb_count_bioskey; if (pb_count_bioskey>pb_count_limit) {pb_count_bioskey=0; if (bioskey(1)!=0) {bioschar=(char)bioskey(0); if (bioschar!='\b') printf("%c",bioschar); //pb_count_limit=speedfactor*10; // every 1/20 second if (pb_tv_1_4<19) {if (bioschar equal '\b') {if (pb_tv_1_4>0) {--pb_tv_1_4; printf("\b \b");}} else pb_move_received[pb_tv_1_4++]=bioschar; if ((int)bioschar equal 13) {pb_move_received[pb_tv_1_4 - 1] = 0; pb_opponents_time=(henttid() - startmovetime); pb_oppo_nodes=tv_nodes; add_movetime(pb_opponents_time, false, 0, 0); startmovetime=henttid(); pb_sw_move_received=true; pb_sw_move_guessed=pb_move_guessed(); if (pb_sw_move_guessed!=true) init_hash(); // hmmmmmmm #ifdef GUESSED else {if (save_games==true) fprintf(pgn," {guessed:}");} #endif printf("\n"); //printf("%s \n",pb_move_received); if (pb_sw_move_guessed==true and pb_time_used==false) {if (secprmove>0 and iteration>2) {tpctmsf=timepctmovesofar(); if (tpctmsf>90 or (move_pointer[1] equal 0 and (tpctmsf-tpct_it_zero)>30) ) goto leave_now; } show_board(); printf(" continue thinking... time left: %d seconds ", (secprmove-(int)(pb_opponents_time/100)+1)); } if (pb_sw_move_guessed==false or pb_time_used==true or iteration equal last_iteration) leave_now: {keyboard_stop=true; // virker dette stop.... pb_undo_move_until_root(); move_pointer[x]=mobilitet[x]; goto he; } } } } } if (iteration equal last_iteration) {pb_count_limit=0; goto pb_move_typed_in;} } if (ply equal 0) { if (move_fr[0][ move_pointer[0]] equal stop) {gem_mobil_zero=mobilitet[0]; mobilitet[0]=-44; goto her;} //dirty #ifdef FILTRACEMOVES if ( ( (move_fr[0][ move_pointer[0]] equal b8 and move_to[0][ move_pointer[0]] equal c6) or (move_fr[0][ move_pointer[0]] equal b8 and move_to[0][ move_pointer[0]] equal c6) ) and iteration equal last_iteration //and tv_nodes > 11600 testes ikke for hvert tr‘k.... ) trace=30; else trace=2; #endif it_out=iteration; move_out=move_pointer[0]; if (pb_on equal false) {if (iteration>2 and bioskey(1)!=0) {bioschar=(char)bioskey(0); if (bioschar equal 's') {keyboard_stop=true; goto he;} } } if (secprmove>0 and iteration>2) {tpctmsf=timepctmovesofar(); //check_time_at_nodes= // tv_nodes*100/(tpctmsf+1); //spar tid!? NEJ if (tpctmsf>90 or (((move_pointer[0] equal 0 and pb_on equal false) or (move_pointer[1] equal 0 and pb_on equal true) ) and (tpctmsf-tpct_it_zero)>30 ) ) if (pb_on equal true) {pb_time_used=true; if (pb_sw_move_received==true) {keyboard_stop=true; goto he; } } else {time_stop=true; goto he;} } } if (nullmove[ply]<99) make_move(&nullmovesq, &nullmovesq, false); else make_move(&move_fr[ply][ move_pointer[ply]], &move_to[ply][ move_pointer[ply]], false); undo: if (make_move_status equal score_is_found) {minimax(); if (ply>=2) evt_cut_off(); undo_move(); goto her; } if (make2_move_status equal pseudo_move) {undo_move(); realmoves[ply]--; if (ply equal 0) {move_pointer[0]-=1; remove_move(move_pointer[0]); // 7/4-97 if (--mobilitet[0] equal 0) move_pointer[0]=125; } //28/3 } else {if (make_move_status equal make_cut_off) { if (ply equal 1 and gem_sel_vurd[1] != 30111) // hmmm move_value[0] [move_pointer[0]]=gem_sel_vurd[1]; if (ply<=trace) // and filtrace equal false) // printf("Sel-CutOff! best-score; ply og ply-1: %d %d\n", // best_score[ply], best_score[ply_1]); { if (gem_sel_vurd[ply] != 30111) // hmmm best_score[ply]=gem_sel_vurd[ply]; printf("S/tpo-cut %d %d",best_score[ply], best_score[ply_1]); /* best_score[ply]=start_best_score[ply];*/ /* virker det? */ } minimax(); // hmmmmmm aht mms undo_move(); goto her; } } if (( ply equal last_ply ) ) { if (realmoves[ply] equal 0) {if (king_in_check[ply] equal false) {vu=draw_score; best_score[ply]=draw_score; ++tv_pat;} } else best_score[ply]=vurdering(); // ply eq last ply vu=best_score[ply]; mms[ply]=best_score[ply]; if (trace <= -10000 and tv_printline < tv_nodes) {tv_printline -= trace; print_line();} minimax(); if (ply>=2) evt_cut_off(); undo_move(); } goto her; he: best_score[0]=most_recent_best_score; // 28/4/98 move_pointer[0]=mobilitet[0]; her: while ( move_pointer[ply]>=mobilitet[ply] ) { if (ply_1<=plydyb and swhash==1 and p[ply].swnullhash==0 //and ply > USEHASHABOVEPLY ) {uli_id_index=p[ply].hash_idx & hash_maxindex; read_hash(uli_id_index); if (hash.hash_score_final equal false and p[ply].hash_id equal hash.hash_id and p[ply].hash_idx equal hash.hash_idx) {hash.hash_score_final=true; write_hash(uli_id_index);} } if (ply equal 0) { finished=true; break; } if (realmoves[ply] equal 0) {if (king_in_check[ply] equal false) {vu=draw_score; best_score[ply]=draw_score; mms[ply]=best_score[ply]; ++tv_pat;} } minimax(); // if (ply equal 2 and iteration>0 and do_gem_top() equal true) // gem_top_killer(&best_move_fr[1], &best_move_to[1]); //gem_simple_kill(&best_move_fr[ply_1], &best_move_to[ply_1]); // does this work well???? any effect??? if (ply>=2) evt_cut_off(); undo_move(); // minimax(); // korrekt her.......??? // if (mate_found() equal true) // {ant_sel_ply=0; check_search=0;} /* duer heller ikke..... */ // { finished=true; break; } /* duer ikke - den korteste mat skal // findes... */ } // end of WHILE if (finished==true) break; } while ( true ); // end of DO check_search=gem_check_search; if (mobilitet[0] equal -44) mobilitet[0]=gem_mobil_zero; //dirty } void menu_diverse() { #ifdef MENUDIV signed char valg='0', dum; int dumint; // int i; FILE *fp; for (; valg!='X'; ) {printf("\n 1 Danish=German / English letters "); printf("%s",men_letter); printf("\n 2 Board size : %d",sqwidth); // printf("\n 3 DIR *.* does not work... "); printf("\n 4 Value of queen : %d",men_value[6]); printf("\n 5 Value of knight: %d",men_value[3]); printf("\n 6 Moves without capture/pawnmove: %d",(int)p[0].draw50); printf("\n 7 Give draw a score of: %d",draw_score); printf("\n total nodes in this session: %8.0f", tv_allnodes); printf("\n max seconds for a move in this session: %6.2f", maxmovetime/100); printf("\n avg seconds for the %8.0f moves in this session: ", tv_sessionmoves); if (tv_sessionmoves equal 0) printf("0"); else printf("%4.2f",(tv_sessionmovetime / (100*tv_sessionmoves)) ); printf("\n max value reached for pawnstructure: %d ", maxpawn); printf("\n pawn limit exceeded %6.0f times", pawnexceed); printf(" out of %8.0f", totalexcd); print_pc_speed(); printf("\n X Back to the main menu"); printf("\n\n? "); scanf_char(&valg); valg=toupper(valg); if (valg equal '1') {if (men_letter[0] equal 'B') strcpy(men_letter,"P NBRQK"); else strcpy(men_letter,"B SLTDK"); } if (valg equal '2') {printf("Board size ? "); scanf_int(&sqwidth); show_board(); press_any_key_to_continue(); } if (valg equal '3') {system("DIR *.*");} if (valg equal '4') {printf("queen value ? "); scanf_int(&men_value[6]); } if (valg equal '5') {printf("knight value ? "); scanf_int(&men_value[3]); } if (valg equal '6') {printf("number of halfmoves ? "); scanf_int(&dumint); p[0].draw50=(char)dumint; } if (valg equal '7') {printf("draw value ? "); scanf_int(&draw_score); } // if (valg equal '4') // {system("EDIT COLDITZ");} } #endif } void menu_positions() { #ifdef MENUPOSITIONS signed char valg='0', dum; for (; valg!='X'; ) {printf("\n\n"); printf("\n 1 Show current position"); /* printf("\n 2 The startposition"); */ printf("\n 2 The matesearch finds g4+!! in a few seconds. (1,0,0)"); printf("\n 3 Mate in 3 - 1.Nh6++ (4,4,0)"); /* printf("\n 3 Mate in 2 - 1.Qg8+ (4,4,0)"); */ printf("\n 4 1.b7. quiet deep move: 4.Kb6! (4,6,0). Mate in 5 moves."); printf("\n 5 Mate in 12!! - in one second by the matesearch."); //printf("\n 5 CSS 86/2 p.21; BASIC-Chess 1.-,Rxc3! (4,4,0) - not solved..."); printf("\n 6 Mate in 2 moves by 1.Bb1! (4,4,0)"); printf("\n 7 Mate in 4 moves by 1.Rb6! (6,2,0)"); printf("\n 8 Colditz-test 30: 1.Bxe5! (2,6,0)"); printf("\n 9 P. Heine <> Larsen. 1.Bh4! (6,4,0) - yet too hard..."); printf("\n A Mate in 6 by 1.Kc2+ (discovered check...) (2,10,0)"); printf("\n B Kf6! (6,4,0) threat to a piece should extend the search"); printf("\n C Rg7+! - draw by repetition"); printf("\n D 1. Qf1+# (6!,8!,0) - when is the mate in 7 seen?"); printf("\n E Type in a position"); printf("\n F Rd6 stalemate"); printf("\n G -,Rd6 stalemate"); printf("\n H -,Qc6 with mate"); printf("\n I Qc6 with mate"); printf("\n J Rh8+! mate in 6"); printf("\n K Re8+! (2,2,0) checksearch/matesearch finds this"); printf("\n L Rxf4! (2,2,0) checksearch/matesearch test..."); printf("\n M Position: 1.d7 mate in 2"); printf("\n N Position: 1.d6 mate in 3"); printf("\n X Back to the main menu"); printf("\n\n? "); scanf_char(&valg); valg=toupper(valg); if (valg equal '1') {show_board(); press_any_key_to_continue();} if (valg equal '2') // {strcpy(xxx,"r6r/4kppp/pp6/2pn2P1/P2p1B2/1b1n3P/1P2N3/2R3KR/w"); {strcpy(xxx,"q7/1p2pppb/7p/1P5k/4PP1b/2P3PP/1N1N3K/6B1/w g3-g4+!"); make_array_ply_zero(); show_board(); } /* if (valg equal '2') {strcpy(xxx,"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR/w"); make_array_ply_zero(); show_board(); } */ if (valg equal '3') {strcpy(xxx,"3B1rk1/1B2bNpp/1pP2p2/pp5n/5n1r/RQP3Pq/R4P1P/6K1/w Nf7-h6+!"); /* {strcpy(xxx,"3B1r1k/1B2b1pp/1pP2p1N/pp5n/5n1r/RQP3Pq/R4P1P/6K1/w Qb3-g8+!"); */ make_array_ply_zero(); show_board(); } if (valg equal '4') {strcpy(xxx,"k1b5/P1P5/PPpP4/2K5/8/8/2p5/8/w b6-b7+!"); make_array_ply_zero(); show_board(); } if (valg equal '5') {strcpy(xxx,"3nn3/2p2p1k/1p1pp1p1/p2B3p/r2B2N1/4P2N/3PKPP1/6q1/w Nh3-g5+!"); /* {strcpy(xxx,"2rq1rk1/1p2bppp/3pbn2/p3p3/Pn2P3/1NN1B3/1PPQBPPP/2RR2K1/b Rc8xc3!"); */ make_array_ply_zero(); show_board(); } if (valg equal '6') {strcpy(xxx,"Q7/8/8/8/4B3/2K5/b7/k7/w Be4-b1!"); make_array_ply_zero(); show_board(); } if (valg equal '7') {strcpy(xxx,"1R6/2p5/p1K5/k7/8/1P6/2P5/8/w Rb8-b6!"); make_array_ply_zero(); show_board(); } if (valg equal '8') {strcpy(xxx,"Q7/p4rkp/3q4/2p1p1N1/P1P5/8/7B/7K/w Bh2xe5!"); make_array_ply_zero(); show_board(); } if (valg equal '9') {strcpy(xxx,"1r3kr1/1bR1bp2/p3p3/3pP3/Rn4p1/6B1/1P2BPP1/3N2K1/w Bg3-h4!"); make_array_ply_zero(); show_board(); } if (valg equal 'A') {strcpy(xxx,"3r2bk/5p1p/4p3/8/1PP5/1PK4r/1Q6/B3b3/w"); make_array_ply_zero(); show_board(); } if (valg equal 'B') {strcpy(xxx,"8/6n1/2p4p/R1P1K3/2P5/4P3/P6P/r5k1/w Ke5-f6!"); make_array_ply_zero(); show_board(); } if (valg equal 'C') {strcpy(xxx,"8/4bK1k/npp4p/3p4/4p3/5nR1/8/8/w Rg3-g7+!"); make_array_ply_zero(); show_board(); } if (valg equal 'D') {strcpy(xxx,"8/8/p5q1/1p6/1P6/5K2/5Q1p/7k/w Qf2-f1+!"); make_array_ply_zero(); show_board(); } if (valg equal 'E') {printf("\n Type in a position - be carefull!"); printf("\n An example: the startposition should be typed like this"); printf("\n rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR/w\n? "); scanf_string(); make_array_ply_zero(); show_board(); } if (valg equal 'F') {strcpy(xxx,"K2R4/8/k6q/8/8/8/8/8/w Rd8-d6! "); make_array_ply_zero(); show_board(); } if (valg equal 'G') {strcpy(xxx,"k2r4/8/K6Q/8/8/8/8/8/b Rd8-d6! "); make_array_ply_zero(); show_board(); } if (valg equal 'H') {strcpy(xxx,"K2R4/8/k6q/8/8/8/8/8/b Qh6-c6! "); make_array_ply_zero(); show_board(); } if (valg equal 'I') {strcpy(xxx,"k2r4/8/K6Q/8/8/8/8/8/w Qh6-c6! "); make_array_ply_zero(); show_board(); } if (valg equal 'J') {strcpy(xxx,"r3rbk1/ppq2pp1/2p3P1/8/2n3P1/2N5/PPP2P2/1KQR3R/w Rh1-h8!"); make_array_ply_zero(); show_board(); } if (valg equal 'K') {strcpy(xxx,"7k/n7/8/8/4Rp2/8/8/7K/w Re4-e8+!"); make_array_ply_zero(); show_board(); } if (valg equal 'L') {strcpy(xxx,"7k/n6r/8/8/4Rp2/8/8/6KN/w Re4xf4+!"); make_array_ply_zero(); show_board(); } if (valg equal 'M') {strcpy(xxx,"k7/8/1K1P4/8/8/8/8/8/w d6-d7!"); make_array_ply_zero(); show_board(); } if (valg equal 'N') {strcpy(xxx,"k7/8/1K6/3P4/8/8/8/8/w d5-d6!"); make_array_ply_zero(); show_board(); } } #endif } int game_evt_draw() { #ifdef VARIANTS #else if (dead_draw() equal true) {printf(" draw by insuff. mat. "); return true;} else #endif if (repeat3x_draw() equal true) {printf(" draw by 3 x repeat "); return true;} else if (p[0].draw50>=100) {printf(" draw by 50 move rule "); return true;} else return false; } void mainline_move(signed char fr, signed char to, signed char maliout) { if (ply==1) {pb_move_fr=fr; pb_move_to=to; pb_move_ready=true;} #ifdef HIDEINFO #else if (ply<2 and maliout equal true) print_kqrbnp(sq[fr]); if (maliout equal true) {print_a1_h8(&fr); print_a1_h8(&to); printf(" ");} #endif if (ply>0) {move_pointer[ply]=0; move_fr[ply][0]=fr; move_to[ply][0]=to;} make_move(&fr, &to, true); } void mainline(signed char maliout) { signed char /*tv=0,*/ wchar; int x; // if (ply!=0) beep(); if (status equal self_play) maliout=false; if (maliout equal true) printf("\nLine: "); move_pointer[0]=0; pb_move_ready=false; if (best_move_fr[0]==stop) {happens[4]='4'; goto leave;} x=find_move_index(&best_move_fr[0], &best_move_to[0]); if (x==-1) {happens[5]='5'; goto leave;} // skal slettes igen // if (x!=0) {wchar=move_fr[0][0]; move_fr[0][0]=move_fr[0][x]; move_fr[0][x]=wchar; wchar=move_to[0][0]; move_to[0][0]=move_to[0][x]; move_to[0][x]=wchar; // error1='+'; } // du'r ikke get_next_good_move(); // } // if (best_move_fr[0]!=move_fr[0][0] or // best_move_to[0]!=move_to[0][0]) // {error2=':'; dette sker mod forventning....... // beep(); // } mainline_move(move_fr[0][0], move_to[0][0], maliout); r: uli_id_index=p[ply].hash_idx & hash_maxindex; read_hash(uli_id_index); if ( p[ply].hash_id equal hash.hash_id and p[ply].hash_idx equal hash.hash_idx) {if (hash.hash_fr==stop) {happens[6]='6'; goto leave;} mainline_move(hash.hash_fr, hash.hash_to, maliout); if (ply==2 and maliout equal true) store_pb_pos(); if (ply<14) goto r; } leave: pb_undo_move_until_root(); } /* void mainline2(signed char maliout) { signed char tv=0, wchar; int x; if (maliout equal true) printf("\nLine: "); move_pointer[0]=0; pb_move_ready=false; // x=find_move_index(&best_move_fr[0], &best_move_to[0]); // if (x!=0) // {wchar=move_fr[0][0]; move_fr[0][0]=move_fr[0][x]; move_fr[0][x]=wchar; // wchar=move_to[0][0]; move_to[0][0]=move_to[0][x]; move_to[0][x]=wchar; // } mainline_move(move_fr[0][0], move_to[0][0], maliout); r: uli_id_index=p[ply].hash_idx & hash_maxindex; read_hash(uli_id_index); if ( p[ply].hash_id equal hash.hash_id and p[ply].hash_idx equal hash.hash_idx) {mainline_move(hash.hash_fr, hash.hash_to, maliout); if (ply<14) goto r; } pb_undo_move_until_root(); } */ void print_move() { signed char to, /*to2,*/ to_9_10_11,prom,promote_piece;//,promotion=false; //int dumm; if (status equal self_play) printf(" "); // 3------->2 4/7 else printf("\n I play... "); if (sound_on equal true) beep(); print_best_move_ply_zero(true); if (status != self_play) printf("\n"); #ifdef QUIETEXPERIMENT if (status != self_play ) printf("\n sel.depth=%d", (int)(ANTSELPLY+w_antselply)); #endif //dumm=game_evt_draw(); game_evt_draw(); if (disctrace equal true) {writesecsofar(); fprintf(fp,"calculation of move ended\n\n\n");} if (gameplay equal true and dummy_search equal false and status!=everplay) {writesecsofar_gi(); fprintf(gi,"calculation of move ended\n\n");} if (status != self_play ) { #ifdef HIDEINFO #else printf(" "); print_vurdering(best_score[0]); #endif printf("\ndepth: %d, next move=%d%c", it_out,move_out+1,mark_nodesstop);} // it_out,realmoves[0]+1,mark_nodesstop);} // it_out,move_out+1-tv_pseudo_moves,mark_nodesstop);} if (swhash equal 1) mainline(true); else pb_move_ready=false; if (gameplay==true and gameplay_info==true) press_any_key_to_continue(); } void computer_x() {signed char x; initialize_best_score(); mslim[1]=1000; mslim[2]=1000000; mslim[3]=100000000; mslim[4]=900000000; a: computer(); if (iteration equal 0) {if (best_score[0] != w_materiel[0]-b_materiel[0]+wh_bl*30 and // silly..................... best_score[0] != w_materiel[0]-b_materiel[0]-wh_bl*30) {matesearch_score=best_score[0]; ms_fr=best_move_fr[0]; ms_to=best_move_to[0]; } else matesearch_score=no_good_found; } #ifdef MSGOOD if (iteration equal 0 and save_games equal true and matesearch_score!=no_good_found and mate_found()==false) fprintf(pgn," {ms:good} "); #endif if (iteration equal 0 and status != self_play and status != everplay) if (!(gameplay==true and gameplay_info != true)) {for (x=0; x<=max_ply and p[x].e_p != 107; ++x) {}; // dirty... printf(" max depth reached = %d halfmoves.",x-1); printf("\nnodes: %8.0f; max: %8.0f ", tv_nodes, msmax); if (matesearch_score!=no_good_found and mate_found()==false) {printf("\n Something good was found...: "); print_best_move_ply_zero(false); print_vurdering(best_score[0]); } printf("\n End of mate-search..."); } if (iteration equal 0 and last_ply<24 and // (secprmove > 0 or (msmax/(tv_nodes+1))>3) ((secprmove equal 0 and (msmax/(tv_nodes+1))>3) or // don't continue matesearch if more than 1/3 is used (secprmove > 0 and // secprmove*100* MSPCT/100 / (henttid()-timemovestart+1) >3) ((double)secprmove* MSPCT) / (henttid()-timemovestart+1) >3) ) and mate_found() equal false) {if ((mslim[0] equal 8 or mslim[0] equal 16) and secprmove>0) {if ((henttid()-timemovestart) > 20) { {//msmax=((double)secprmove*100*MSPCT/100); // ok test.... msmax=(((double)secprmove*100 *MSPCT/100) / // 20% of time for matesearch (double)(henttid()-timemovestart +1) // time used so far ) * tv_nodes; if (msmax<500*(double)speedfactor) msmax=500*(double)speedfactor; } } else {{//mate_sch_pos[0]=9000+(100*(d/f)speedfactor); // denne kode ligger msmax=(double)secprmove*(double)speedfactor*50; // dobbelt... } }; } mslim[0]+=8; goto a; } full_evalu=gem_full_evalu; if (run_test equal true and iteration > 1 and exitsolfound equal true and solution_mark equal '!' and solution_to != false and best_move_fr[0]==solution_fr and best_move_to[0]==solution_to) q_test=true; } #ifdef PLAYEARLYGAMEFAST int play_early_game_fast() { double q, step; if (secprmove<1) secprmove=1; q=(double)secprmove / sqrt((double)secprmove/2); step=((double)secprmove - q) / 4; return ( (double)secprmove - ( ((double)black_8-4 -1 ) * step) ); } #endif void calculate_secprmove() { double used_time, time_left; int moves_left, w_int; if ((intern equal white and pb_on equal false) or (intern equal black and pb_on equal true)) used_time=wtid; else used_time=btid; if (moves_inxmin>0) {w_int=1+(mpc/(2*moves_inxmin)); time_left=( ((double)w_int*(double)min_forxmoves*60) - used_time); moves_left=2+(w_int*moves_inxmin-(mpc/2)); } else {time_left=( ((double)gameinxmin*60) - used_time); moves_left= // assume 10-30 moves left... ((w_materiel[0]+b_materiel[0]-two_kings+startmateriel) / (startmateriel / 20)) - 10; } secprmove=(int)time_left / moves_left; #ifdef PLAYEARLYGAMEFAST if (black_8 > 5) secprmove=play_early_game_fast(); // > 4 #endif //if (moves_inxmin>0) secprmove *= 2.0; else secprmove *= 2.0; //3 / 2; secprmove *= 1.8; if (status==everplay or status==self_play) secprmove *= 0.8; // no p.brain if (secprmove<1) secprmove=1; if ((info_out equal 1) or (gameplay equal true and status!=self_play and pb_on equal false)) printf("\nmaximum timelimit for my move is %d seconds...",secprmove); if (gameplay equal true and dummy_search equal false and status!=everplay) fprintf(gi,"\nmaximum timelimit for my move is %d seconds.",secprmove); } void make_display() { double kommatal; tid=henttid(); kommatal=(tid-timemovestart-pb_opponents_time); if (kommatal<=0) kommatal=1; if (kommatal>maxmovetime) maxmovetime=kommatal; tv_sessionmovetime+=kommatal; ++tv_sessionmoves; if (matelvl_score!=30888) {best_score[0]=matelvl_score; best_move_fr[0]=matelvl_fr; best_move_to[0]=matelvl_to; } if (noprint equal true or pb_on equal true) goto zzz; if (status equal self_play) {print_move(); goto zzz;} printf("\n %8.2f sec.", kommatal/100); printf("\n %8.0f nodes/sec.", (tv_nodes/((kommatal+pb_opponents_time)/100.0))); if (gameplay equal true) goto y; printf("\nnodes: %8.0f; ", tv_nodes); printf(" of these pseudomoves: %8.0f", tv_pseudo_moves); printf("\nnodes at last ply: %8.0f", tv_last_ply); printf(" cut-off's: %8.0f; ", tv_cutoff); if (tv_cutoff equal 0) tv_cutoff=1; printf("\n %8.1f nodes/cut-off.", (tv_nodes/tv_cutoff)); printf(" repeat:%5.0f", tv_repeat); if (tv_error > 0) {if (run_test==false) beep(); printf("\n %8.0f errors...", tv_error);} // if (tv_pat>0) printf("\n %8.0f stalematepositions seen...", tv_pat); #ifdef TVHASH printf("\nhash: read,ok,final,nofinal,hit: %8.0f %8.0f %8.0f %8.0f %8.0f ", tv_hash_read, tv_hash_read_ok, tv_hash_read_ok_final, tv_hash_nofinal, tv_hash_hit); printf("\n write, update, nowrite : %8.0f %8.0f %8.0f", tv_hash_skriv, tv_hash_opdat, tv_hash_ejskriv); if (tv_hash_error>0) printf("\n fejl iterativ beregning af hashkey : %8.0f", tv_hash_error); #endif y: print_move(); if (solution_mark equal '!' and solution_to != false) {if (best_move_fr[0]==solution_fr and best_move_to[0]==solution_to) printf("\nRight move, DABBABA!"); else {printf("\nWrong, DABBABA... The right move is "); print_kqrbnp(sq[solution_fr]); print_a1_h8(&solution_fr); print_a1_h8(&solution_to); } } if (gameplay equal false) show_board(); if (run_test==false and filtrace==false and gameplay==false) press_any_key_to_continue(); zzz: } void computer_and_display() { int gem_skift=skift, gem_swhash=swhash; signed char x, gem_pb_on; // if (status equal everplay) // {if (intern equal white) s_kill=1; // else s_kill=2;} pb_opponents_time=0; pb_oppo_nodes=0; w_antselply=0; #ifdef PBSILLY pb_silly1_fr=stop; pb_silly2_fr=stop; pb_silly2w_fr=stop; #endif everplay_setup(); nulstil(); matelvl_score=30888; pb_count_bioskey=0; pb_count_limit=speedfactor*10; // every 1/20 second #ifdef TVHASH tv_hash_error=0; tv_hash_nofinal=0; tv_hash_read=0; tv_hash_read_ok=0; tv_hash_read_ok_final=0; tv_hash_skriv=0; tv_hash_opdat=0; tv_hash_ejskriv=0; tv_hash_hit=0; #endif sort_pili(piliwq); sort_pili(piliwr); sort_pili(piliwb); sort_pili(piliwn); sort_pili(piliwp); sort_pili(pilibq); sort_pili(pilibr); sort_pili(pilibb); sort_pili(pilibn); sort_pili(pilibp); limitpawnscore=20 + abs(bewerte_stellung() ); check_time_at_nodes=10000; mark_nodesstop=' '; tpct_it_zero=0; black_8=count_black_8_row(); if (gameinxmin>0 or min_forxmoves>0) calculate_secprmove(); if (secprmove>0) {last_iteration=20; ant_sel_ply=ANTSELPLY+w_antselply; /*everplay_setup();*/ last_sel_ply=ant_sel_ply; // ok.....? check_search=0;} keyboard_stop=false; time_stop=false; if (status != self_play) {gem_pb_on=pb_on; pb_on=false; show_board(); pb_on=gem_pb_on;} vu=0; if (status equal everplay) printf("\nEverplay score - white: %5.2f black: %5.2f (white %3.2f%)", w_ever, b_ever, (w_ever*100/(w_ever+b_ever+0.0001))); for (x=0; x<=max_ply; ++x) {simple_kill1_to[x]=99; simple_kill2_to[x]=99; simple_kill1_fr[x]=0; simple_kill2_fr[x]=0; tv_s_kill1[x]=0; tv_s_kill2[x]=0; s_kill1_oldpre[x]=0; s_kill2_oldpre[x]=0; simple_kill1_vu[x]=0; simple_kill2_vu[x]=0; // hjaelper det? nej.... if (x>0) p[x].e_p=107; // dirty... //nu ll mo ve[ply]=99; // dirtysmart, but not enough... } random_move=0; vurd_node=-1; gem_sel_vurd[0]=30111; always=always_cut; if (always equal 2) {if (last_iteration>=4) always=0; else always=1;} // test p† secprmove centre[0]=0; timemovestart=henttid(); tv_pseudo_moves=0; tv_nodes=0; tv_cutoff=0; tv_last_ply=0; tv_error=0; tv_repeat=0; tv_pat=0; matesearch_score=no_good_found; gem_full_evalu=full_evalu; iteration=1; sel_ply_now=false; if (mate_search != 0 and iterativ equal +1 and pb_on equal false) {sel_ply_now=true; ant_sel_ply=0; iteration=0; skift=0; swhash=0; full_evalu=0; first_dynamic_sel_ply[0]=0; sel_side[0]=intern; gen_moves_ply_zero(); if (mobilitet[0] equal 0) {iteration=1; skift=gem_skift; full_evalu=gem_full_evalu; swhash=gem_swhash;} else {mslim[0]=8; if (secprmove equal 0) {mate_sch_pos[0]=((double)speedfactor/10)* (double)mate_search*1000*(double)last_iteration/4; msmax=(((double)last_iteration*20000)-10000) *((double)mate_search/10) *(double)speedfactor/10; // if (mate_sch_pos[0]<80000) {printf("<80000.........");press_a_k_t_c();} } else {mate_sch_pos[0]=9000+(100*(double)speedfactor); // mate_sch_pos[0]=10000; // msmax=secprmove*100; msmax=(double)secprmove*(double)speedfactor*50; // if (msmax>5000) msmax=5000; } } } tv_printline= -1 * trace; initialize_best_score(); q_test=false; if (iterativ != +1 and secprmove equal 0) iteration=last_iteration; for (; (iteration<=last_iteration and (mate_found() equal false or mate_ply>=iteration or pb_on equal true) and keyboard_stop equal false and time_stop equal false and q_test equal false and (iteration<3 or move_fr[0][1] != stop or pb_on equal true)); ++iteration) {if (iteration equal 1 or iterativ != +1) {skift=gem_skift; swhash=gem_swhash; // tv_last_ply=0; first_dynamic_sel_ply[0]=99; sel_ply_now=false; gen_moves_ply_zero(); // for (x=0; x<=mobilitet[0]; ++x) /* tr‘k i ply 0 gemmes*/ // {kill_fr[x][1]=move_fr[0][x];/* i killarray */ // kill_to[x][1]=move_to[0][x]; // kill_fr[x][0]=0; /*gemmes en for meget?*/ // } } if (move_fr [0][0] equal stop) {iteration=last_iteration+1; goto zzz2; } else computer_x(); } make_display(); zzz2: // if (maxmovetime>22000) {printf(" >220"); press_any_key_to_continue();} if (gameinxmin>0 or min_forxmoves>0) secprmove=0; tv_allnodes+=tv_nodes; skift=gem_skift; swhash=gem_swhash; full_evalu=gem_full_evalu; // aht mat i matesch } /* void eco() // tager 1 sekund {FILE *filptr; char *i; strcpy(filnavn,"eco.pgn"); filptr = fopen(filnavn, "r"); if (filptr equal NULL) {printf("Bad OPEN of file..."); goto eco_exit;} read: i = fgets(xxx, 120, filptr); if (i != NULL) goto read; fclose(filptr); eco_exit: } */ void testfil() {FILE *filptr; char *i; int solu=0, gem_trace=trace, gem_info=info_out, take_a_look=0, posnr; int i2, gemwrand=wrand, gemposnr, solved=0, unsolved=0; double timeteststart, timefortest, scoresum=0; trace=-30000; info_out=0; filtrc_error=0; wrand=0; #ifdef DAB4KORR #else printf("Type a filename\n"); printf(" (e=endgame, i=insufmat, rb=rookbish\n"); printf(" b=badmoves, bt=bt2630, c=Colditz, l=Larsen1,"); printf(" m=matesrch, t=timetest)\n? "); scanf_string(); strcpy(filnavn, xxx); if (strcmp(filnavn,"b") equal 0) strcpy(filnavn,"badmoves.epd"); if (strcmp(filnavn,"bt") equal 0) strcpy(filnavn,"bt2630.epd"); if (strcmp(filnavn,"c") equal 0) strcpy(filnavn,"Colditz.epd"); if (strcmp(filnavn,"e") equal 0) strcpy(filnavn,"endgmate.epd"); if (strcmp(filnavn,"i") equal 0) strcpy(filnavn,"insufmat.epd"); if (strcmp(filnavn,"rb") equal 0) strcpy(filnavn,"rookbish.epd"); if (strcmp(filnavn,"l") equal 0) strcpy(filnavn,"Larsen1.epd"); if (strcmp(filnavn,"m") equal 0) strcpy(filnavn,"matesrch.epd"); if (strcmp(filnavn,"t") equal 0) strcpy(filnavn,"timetest.epd"); // if (strcmp(filnavn,"w") equal 0) strcpy(filnavn,"pb.epd"); #endif filptr = fopen(filnavn, "r"); if (filptr equal NULL) {printf("Bad OPEN of file..."); goto testfil_exit;} strcpy(solution_xxx,".................................................."); run_test = true; init_hash(); mpc=0; #ifdef DAB4KORR trace=0; posnr=1; gemposnr=1; take_a_look=1; disctrace=false; exitsolfound=false; goto hopdab4; #endif printf("Which position number do you want (0=all)\n? "); scanf_int(&posnr); gemposnr=posnr; if (posnr <= 0) {printf("Pause at every position (1=yes)\n? "); scanf_int(&take_a_look);} else take_a_look=1; printf("Make a tracefile (dabbaba.trc) (1=yes)\n? "); scanf_int(&disctrace); if (disctrace equal true) fp=fopen("dabbaba.trc","w"); printf("Exit position when right move is found (1=yes)\n? "); scanf_int(&exitsolfound); hopdab4: i = fgets(xxx, 120, filptr); timeteststart=henttid(); for (; i != NULL and solu<50;) {printf("\n%s",xxx); if (xxx[0] != '#' and posnr>=0) {++solu; if (posnr==solu or posnr==0) {make_array_ply_zero(); show_board(); printf("\n%s",solution_xxx); if (take_a_look==1) {press_any_key_to_continue(); printf("\nComputing a move now.....");} computer_and_display(); pb_move_ready=false; scoresum+=best_score[0]; mpc+=2; if (solution_mark equal '!' and solution_to != false) {if (best_move_fr[0]==solution_fr and best_move_to[0]==solution_to) {++solved; solution_xxx[solu-1]='+';} else {++unsolved; solution_xxx[solu-1]='-';} } else if (solution_mark equal '?' and solution_to != false) {if (best_move_fr[0]!=solution_fr or best_move_to[0]!=solution_to) {++solved; solution_xxx[solu-1]='+';} else {++unsolved; solution_xxx[solu-1]='-';} } else { solution_xxx[solu-1]='?';} if (take_a_look equal 1) press_any_key_to_continue(); i = fgets(xxx, 120, filptr); if (posnr>0 or keyboard_stop equal true) i=NULL; } else i = fgets(xxx, 120, filptr); } else {if (xxx[1] equal 'x') /* n›dl›sning indtil videre.. */ i=NULL; else {if (posnr<0 and xxx[0] != '#') ++posnr; i = fgets(xxx, 120, filptr);} } } line_with_numbers(); printf("\n%s",solution_xxx); timefortest=(henttid()-timeteststart)/100; printf("\n The test lasted for %8.2f sec. %d positions solved", timefortest, solved); printf("\n Sumscore = %10.0f", scoresum); if (filtrc_error>0) printf("\n*** %8.0f errors found ***",filtrc_error); if (gemposnr <= 0) {press_any_key_to_continue();} run_test = false; trace=gem_trace; info_out=gem_info; fclose(filptr); testfil_exit: wrand=gemwrand; if (disctrace equal true) {fprintf(fp,"\n%8.2f sec. End of Disc-trace\n",timefortest); disctrace=false; i2=fclose(fp);} } void menu_variants() { #ifdef VARIANTS signed char valg='0', dum; //for (; valg!='X'; ) {normal_chess(); printf("\n Chess variant is now set to normal chess -"); printf("\n Choose another if you like..."); #ifdef MENU4TXT printf("\n 1 Stationary Chess (king cannot move; no castle)"); printf("\n 2 Knightmate Chess (K=N & N=K. K=200; no castle)"); printf("\n 3 Chancellor Chess (Q=RN; 1000-->900)"); printf("\n 4 Archbishop Chess (Q=BN; 1000-->800)"); printf("\n 5 Nightrider (300-->625)"); printf("\n 6 Knight is also wazir(0,1) (300-->500)"); printf("\n 7 Knight is also ferz(1,1) (300-->500)"); printf("\n 8 Knight is also dabbaba(0,2) (300-->500)"); printf("\n 9 Knight is also alfil(2,2) (300-->500)"); printf("\n A Rooksquare Chess (my 'Corner Chess'). See README.TXT"); printf("\n B Grid Chess (but cares about checks inside grid...)"); printf("\n C Pawnfreeze Chess - pawncovered men cannot move"); #ifdef EXTINCT printf("\n D Extinction Chess (but no promotion to king)"); #endif printf("\n X Back to the main menu\n\n? "); #endif scanf_char(&valg); valg=toupper(valg); strcpy(filnavn,"P?.EPD"); filnavn[1]=valg; if (valg equal '1') {chess_variant=stationary; /*valg='X';*/} if (valg equal '2') {memcpy(king, nc_knight, 20); memcpy(knight, nc_king, 20); men_value[3]=200; chess_variant=knightmate; /*valg='X';*/ } if (valg equal '3') {memcpy(queen, nc_rook, 20); men_value[6]=900; chess_variant=q_is_rn; /*valg='X';*/ } if (valg equal '4') {memcpy(queen, nc_bishop, 20); men_value[6]=800; chess_variant=q_is_bn; /*valg='X';*/ } if (valg equal '5') {men_value[3]=625; chess_variant=nightrider; knight[0]=more_steps; /*valg='X';*/} if (valg equal '6') {men_value[3]=500; chess_variant=knightwazir; memcpy(knight+9, wazir, 5); /*valg='X';*/} if (valg equal '7') {men_value[3]=500; chess_variant=knightferz; memcpy(knight+9, ferz, 5); /*valg='X';*/} if (valg equal '8') {men_value[3]=500; chess_variant=knightdabbaba; memcpy(knight+9, dabbaba, 5); /*valg='X';*/} if (valg equal '9') {men_value[3]=500; chess_variant=knightalfil; memcpy(knight+9, alfil, 5); /*valg='X';*/} if (valg equal 'A') {chess_variant=rooksquare; /*valg='X';*/} if (valg equal 'B') {chess_variant=gridchess; /*valg='X';*/} if (valg equal 'C') {chess_variant=pawnfreeze; /*valg='X';*/} #ifdef EXTINCT if (valg equal 'D') {chess_variant=extinct; /*valg='X';*/} #endif new_game(); } #endif } void make_real_move() { --ply; --ply_1; p[0]=p[1]; ++mpc; //draw50move=p[0].draw50; calculate_hashkey(); // kan slettes..... if (p[0].hash_id!=uli_id or p[0].hash_idx!=uli_idx) // kan slettes..... {happens[2]='2'; #ifdef ONLYFORJENS //print_line(); show_board(); press_a_k_t_c(); #endif p[0].hash_id=uli_id; p[0].hash_idx=uli_idx; // kan slettes..... } store_hash_for_3xrepeat(); b_materiel[0]=b_materiel[1]; w_materiel[0]=w_materiel[1]; } void help_gameplay() { printf("\n\n\nThe game starts - enter moves like e2e4, a7a8Q, e1g1, d5c6 etc."); printf("\n commands: x/exit/end/stop=exit"); // printf("\n a =analyze position"); printf("\n new/AN =new game"); printf("\n DR/AUTO232 =AUTO232 on/off"); printf("\n g/go/SP =compute a move (change side)"); printf("\n ?/h/help =this help"); printf("\n m/monitor/MZ =you make all the moves"); printf("\n s/selfplay =Dabbaba makes all the moves (160)"); printf("\n e/everplay =Dabbaba plays games forever..."); printf("\n p =show value of pawns"); printf("\n i/info =turns info during gameplay off/on"); printf("\n b/beep =turns beep on/off"); printf("\n savegames/sg =turns gamesaving on"); printf("\n s =stop Dabbabas computing"); printf("\n . =play the move dabbaba is thinking on"); press_any_key_to_continue(); } void remove_evt_pseudomoves() { // for ogsaa at fjerne pseudomoves i varianter af skak, // laves en minisearch... int aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al; aa=last_iteration; ab=last_sel_ply; ac=check_search; ad=mate_search; ae=iterativ; af=info_out; ag=secprmove; ah=gameinxmin; ai=mateinx; aj=swhash; ak=moves_inxmin; al=min_forxmoves; last_iteration=1; last_sel_ply=1; check_search=0; mate_search=0; iterativ=0; info_out=0; secprmove=0; gameinxmin=0; mateinx=0; swhash=0; moves_inxmin=0; min_forxmoves=0; intern*=-1; noprint=true; computer_and_display(); intern*=-1; noprint=false; last_iteration=aa; last_sel_ply=ab; check_search=ac; mate_search=ad; iterativ=ae; info_out=af; secprmove=ag; gameinxmin=ah; mateinx=ai; swhash=aj; moves_inxmin=ak; min_forxmoves=al; } void end_selfplay_game() { status=normal_game; if (move_fr [0][0] != stop) press_any_key_to_continue(); show_board(); show_seconds_used(); press_any_key_to_continue(); } void turn_gamesaving_on() { if (save_games equal false) {save_games=true; pgn=fopen("games.txt","w"); fprintf(pgn,"\n\n\n[Event \"x\"]\n"); printf("\n\nSaving games is now turned on");} } int game_over() { if (game_evt_draw() equal true #ifdef VARIANTS or (chess_variant equal rooksquare and rooksquare_mate() equal true) #ifdef EXTINCT or (chess_variant equal extinct and extinct_mate() equal true) #endif #endif ) return true; else return false; } void play_a_game() { signed char fr, to, fri, toi, fri2, toi2, x/*, asp*/; int w_int; signed char to_9_10_11, promote_piece, y, gem_info=info_out; signed char pb_remember_fr, pb_remember_to; signed char ch2, ch3, valg; int moves, gsqwidth=sqwidth; double everscore; // signed char t[16]; // kingpawn-test; skal slettes igen // char tt[16]; // skal slettes igen if (gsqwidth equal 35) sqwidth=42; is_castle_allowed(); gameplay=true; info_out=0; trace=0; help_gameplay(); gi=fopen("gameinfo.trc","w"); status=normal_game; solution_mark=false; if (count_black_8_row()<8) {show_board(); printf("\n\nNew game (y/n) ? "); scanf_char(&valg); valg=toupper(valg); if (valg equal 'Y') new_game(); } intern*=-1; a: dummy_search=true; remove_evt_pseudomoves(); dummy_search=false; show_board(); if (game_over()==true or move_fr[0][0] equal stop) {move_fr[0][0]=stop; goto end_the_game;} //no! or (drucker equal false and dead_draw() equal true) ) goto end_the_game; printf("\n\n Your move? "); // if (henttid()-startmovetime>50) beep(); // er denne der beep'es! startmovetime=henttid(); // un›dvendig? pb_sw_move_guessed=false; pb_sw_move_received=false; if (pb_move_ready equal true) {pb_on=true; pb_time_used=false; pb_tv_1_4=0; //set_pb_guessmove_last(); printf(" ...thinking on "); #ifdef HIDEINFO #else print_kqrbnp(sq[pb_move_fr]); print_a1_h8(&pb_move_fr); print_a1_h8(&pb_move_to); #endif printf("\n"); intern*=-1; computer_and_display(); intern*=-1; pb_on=false; // if (pb_sw_move_guessed equal true) strcpy(xxx,pb_move_received); //mainline(true); //press_a_k_t_c(); // goto efter_scanstring; //*/ } else {if (save_games equal true) fprintf(pgn," {no perm.brain} "); scanf_string(); intern*=-1; add_movetime(henttid() - startmovetime, true, 0, 0); intern*=-1; startmovetime=henttid(); } //efter_scanstring: /* xxx=tolower(fri) */ if (xxx[0] equal 'x') goto end_the_game; if (strcmp(xxx,"exit") equal 0) goto end_the_game; if (strcmp(xxx,"end") equal 0) goto end_the_game; if (strcmp(xxx,"stop") equal 0) goto end_the_game; if (strcmp(xxx,"m") equal 0) strcpy(xxx,"monitor"); if (strcmp(xxx,"MZ") equal 0) strcpy(xxx,"monitor"); if (strcmp(xxx,"AN") equal 0) strcpy(xxx,"new"); if (strcmp(xxx,"new") equal 0) {new_game(); intern*=-1; goto a;} if (strcmp(xxx,"b") equal 0) strcpy(xxx,"beep"); if (strcmp(xxx,"sg") equal 0) strcpy(xxx,"savegames"); if (strcmp(xxx,"savegames") equal 0) {turn_gamesaving_on(); goto a;} if (strcmp(xxx,"beep") equal 0) {if (sound_on equal false) {sound_on=true; beep();} else sound_on=false; goto a; } if (strcmp(xxx,"monitor") equal 0) { #ifdef TRACEMONITORANDGO if (save_games equal true) {fprintf(pgn," {monitor} ");} // is it this command that disturbs the permanent brain against humans // via auto232??? #endif pb_move_ready=false; status=monitor; goto a;} if (strcmp(xxx,"p") equal 0) {pawninfo=true; printf("\npawn-evaluation(incl. rooks) : %d ",bewerte_stellung() ); printf(" (limit now = %d)\n",limitpawnscore); press_any_key_to_continue(); pawninfo=false; goto a;} if (strcmp(xxx,"?") equal 0) strcpy(xxx,"help"); if (strcmp(xxx,"h") equal 0) strcpy(xxx,"help"); if (strcmp(xxx,"help") equal 0) {help_gameplay(); goto a;} // if (strcmp(xxx,"a") equal 0) {computer_and_display(); goto a;} analyze... if (strcmp(xxx,"i") equal 0) strcpy(xxx,"info"); if (strcmp(xxx,"info") equal 0) {if (gameplay_info==true) {gameplay_info=false; printf("\nInfo is now OFF");} else {gameplay_info=true; printf("\nInfo is now ON");} goto a;} if (strcmp(xxx,"AUTO232") equal 0) strcpy(xxx,"DR"); if (strcmp(xxx,"DR") equal 0) {if (drucker==true) {drucker=false; printf("\nAUTO232 is now OFF");} else {drucker=true; printf("\nAUTO232 is now ON"); turn_gamesaving_on();} goto a;} if (strcmp(xxx,"g") equal 0) strcpy(xxx,"go"); if (strcmp(xxx,"SP") equal 0) strcpy(xxx,"go"); if (strcmp(xxx,"go") equal 0) { #ifdef TRACEMONITORANDGO if (save_games equal true) {fprintf(pgn," {go} ");} // is it this command that disturbs the permanent brain against humans // via auto232??? #endif status=normal_game; goto b; } if (strcmp(xxx,"e16") equal 0) {strcpy(xxx,"everplay"); evermoves_160=16;} if (strcmp(xxx,"e2") equal 0) {strcpy(xxx,"everplay"); evermoves_160=2;} if (strcmp(xxx,"e60") equal 0) {strcpy(xxx,"everplay"); evermoves_160=60;} if (strcmp(xxx,"e") equal 0) strcpy(xxx,"everplay"); if (strcmp(xxx,"s") equal 0) strcpy(xxx,"selfplay"); if (strcmp(xxx,"selfplay") equal 0) {status=self_play; goto play2;} if (strcmp(xxx,"everplay") != 0) goto play3; status=everplay; w_ever=0; b_ever=0; fclose(gi); play2: gameplay_info=-1; moves=0; sqwidth=gsqwidth; goto b; play3: fri=xxx[0]; fri=tolower(fri); fri2=xxx[1]; fr = (10 + (fri2 - '1' + 1) * 10) + (fri - 'a' + 1); toi=xxx[2]; toi=tolower(toi); toi2=xxx[3]; to = (10 + (toi2 - '1' + 1) * 10) + (toi - 'a' + 1); promotion: if ((sq[fr]==w_p or sq[fr]==b_p) and (to>=a8 or to<=h1)) {w_int=0; if (drucker equal true) {xxx[4]='Q'; xxx[5]=0;} // auto232 only Q if (xxx[4]==0) {printf("Promote to Queen, Rook, Bishop or KNight"); printf("\n\n? "); scanf_char(&y);} else {if (xxx[4]=='=') y=xxx[5]; else y=xxx[4];} y=toupper(y); if (y equal 'Q') {w_int=6; goto prom;} if (y equal 'R') {w_int=5; goto prom;} if (y equal 'B') {w_int=4; goto prom;} if (y equal 'K' or y equal 'N') {w_int=3; goto prom;} xxx[4]=0; beep(); goto promotion; prom: for (x=prom_q_9; x<=prom_n_11; ++x) {unpack_promotion(&x, &to_9_10_11, &promote_piece); if (w_int==promote_piece and to==fr + wh_bl * to_9_10_11) to=x; } // if (to<=h8) {printf("error.... "); beep(); goto promotion;} // ????? }; iteration=0; // fjernes engang..... x=0; loop_x: if (move_fr[0][x] equal stop) {beep(); printf("\n\n"); goto a;} if ((move_fr[0][x] != fr) or (move_to[0][x] != to)) {++x; goto loop_x;} fprintf(gi,"\n Human move: %s\n", xxx); if (save_games equal true) {fprintf(pgn," %s ", xxx); if ((mpc+1) % 10 equal 0) fprintf(pgn,"\n");} last_ply=77; // fjernes engang..... if (pb_sw_move_guessed equal true) {best_move_fr[0]=pb_move_fr; best_move_to[0]=pb_move_to; mainline(false); if (pb_move_ready equal false) #ifdef USEBESTMOVE1 {//pb_sw_move_guessed=false; //beep(); // slettes igen //mainline(true); //change_black_white(); //mainline(true); //change_black_white(); //press_a_k_t_c(); if (mobilitet[1]>0) {pb_remember_fr=best_move_fr[1]; pb_remember_to=best_move_to[1]; if (pb_remember_fr==stop) {happens[7]='7'; pb_sw_move_guessed=false; if (save_games equal true) fprintf(pgn," {*stop} "); } else {pb_move_ready=true; if (save_games equal true) fprintf(pgn," {*ok} "); #ifdef ONLYFORJENS // * = the move to respond (immediately) if the pb-move was guessed printf(" **"); print_kqrbnp(sq[pb_remember_fr]); print_a1_h8(&pb_remember_fr); print_a1_h8(&pb_remember_to); printf("**\n"); #endif } } else {pb_sw_move_guessed=false; if (save_games equal true) fprintf(pgn," {*mob=0} "); } } #else pb_sw_move_guessed=false; #endif else {pb_remember_fr=pb_move_fr; pb_remember_to=pb_move_to; #ifdef CHECKBESTMOVE1 if (pb_move_fr!=best_move_fr[1] or pb_move_to!=best_move_to[1]) {happens[8]='8'; if (save_games equal true) {fprintf(pgn," {* "); sq120_to_koordinat(&pb_move_fr, &ch2, &ch3); fprintf(pgn,"%1c%1c",'a' - 1 + ch2, '0' + ch3); sq120_to_koordinat(&pb_move_to, &ch2, &ch3); fprintf(pgn,"%1c%1c ",'a' - 1 + ch2, '0' + ch3); sq120_to_koordinat(&best_move_fr[1], &ch2, &ch3); fprintf(pgn,"%1c%1c",'a' - 1 + ch2, '0' + ch3); sq120_to_koordinat(&best_move_to[1], &ch2, &ch3); fprintf(pgn,"%1c%1c ",'a' - 1 + ch2, '0' + ch3); fprintf(pgn,"} "); } } #endif } } make_move(&fr, &to, true); //mainline2(true); //press_a_k_t_c(); make_real_move(); intern*=-1; //mainline2(true); //press_a_k_t_c(); if (status equal monitor) goto a; b: if (game_over() equal true) {printf("\n"); move_fr[0][0]=stop; goto end_the_game;} intern*=-1; if (pb_sw_move_guessed equal false) {//startmovetime=henttid(); computer_and_display(); } else {best_move_fr[0]=pb_remember_fr; best_move_to[0]=pb_remember_to; if (drucker equal true) make_evt_drucker_delay(startmovetime); make_display(); //show_board(); press_a_k_t_c(); } add_movetime(henttid() - startmovetime, false, pb_opponents_time, pb_oppo_nodes); // giver midnatsfejl... if (status!=self_play) show_seconds_used(); if (move_fr [0][0] equal stop) goto end_the_game; last_ply=1; // fjernes engang....... mainline(false); #ifdef PBSILLY if (pb_move_ready equal false) {happens[9]='9'; if (best_move_fr[0]==pb_silly1_fr and best_move_to[0]==pb_silly1_to and pb_silly2_fr!=stop and pb_sw_move_guessed equal true) {pb_move_fr=pb_silly2_fr; pb_move_to=pb_silly2_to; pb_move_ready=true; {if (save_games equal true) fprintf(pgn," {:ok} ");} #ifdef ONLYFORJENS // : = the move Dabbaba guesses and uses in permanent brain printf(" ::"); print_kqrbnp(sq[pb_move_fr]); print_a1_h8(&pb_move_fr); print_a1_h8(&pb_move_to); printf("::"); #endif } else {if (save_games equal true) fprintf(pgn," {:bad} "); happens[11]='1';} } #endif make_move(&best_move_fr[0], &best_move_to[0], true); ++moves; if (status equal self_play and moves < 57) show_board(); if (status equal self_play and moves % 8 equal 0) printf("\n"); make_real_move(); if (status equal self_play or status equal everplay) {if (moves < evermoves_160 and (keyboard_stop equal false or magic>99) ) {startmovetime=henttid(); goto b;} else goto end_the_game; } goto a; end_the_game: if (move_fr [0][0] equal stop and status != everplay) {if (drucker equal true) {new_game(); moves=0; intern=-1; goto a;} beep(); pb_move_ready=false; printf("\n Oh, the game is over... "); press_any_key_to_continue(); } if (status equal self_play) end_selfplay_game(); if (status equal everplay and keyboard_stop equal false) {everscore=abs((double)best_score[0]); if (everscore>300) everscore=300; everscore=(everscore+((300-everscore)/2))/300; if (best_score[0]>0) {w_ever+=everscore; b_ever+=(1-everscore);} else {b_ever+=everscore; w_ever+=(1-everscore);} //fclose(gi); gi=fopen("gameinfo.trc","w"); new_game(); moves=0; intern=-1; goto b; } info_out=gem_info; fclose(gi); intern*=-1; gameplay=false; sqwidth=gsqwidth; } void main_menu() {signed char valg='0', dum; int dumint, valg2; for (; valg!='!'; ) {printf("\n\n\n\nWelcome to D A B B A B A 1998 Nov. 06."); printf(" by: Jens B‘k Nielsen\n"); // printf(" tester: Alastair Scott and"); // printf("\nD A B B A B A plays chess "); // printf("and variants of chess... Torben Osted\n"); #ifdef SCHOOP printf(" >>> Special rele"); printf("ase for Torsten Schoop (avoid midnight) <<<"); #else printf(" "); printf(" tester: Torsten Schoop(auto232) and Torben Osted "); #endif #ifdef VARIANTS printf("\nV D A B B A B A plays chess "); printf("and variants of chess... \n"); #endif #ifdef ONLYFORJENS printf("%lu",(long unsigned int)henttid() ); #endif printf("\n 0 Level: "); if (secprmove>0) printf(" %d seconds pr. move",secprmove); if (gameinxmin>0) printf(" Game in %d minutes",gameinxmin); if (moves_inxmin>0) printf(" %d moves in %d minutes", moves_inxmin, min_forxmoves); if (mateinx>0) printf(" Mate in %d moves",mateinx); if (secprmove equal 0 and gameinxmin equal 0 and mateinx equal 0 and moves_inxmin equal 0) {printf("fixed depth - see next line"); printf("\n 1 (x,x,x) Brute-force depth: %d",(int)last_iteration); printf(" selektive depth: %d",(int)last_sel_ply); printf(" check-search depth : %d",check_search); } printf("\n 2 Compute a single move in the current testposition"); printf("\n 3 Play against Dabbaba"); #ifdef VARIANTS printf("\n 4 Menu: Variants of Chess"); #endif printf("\n 5 Menu: positions"); printf("\n 6 Menu: Special options"); printf("\n 7 Chesspositions in files"); if (whole_menu equal false) goto menu_50; printf("\n 8"); // Top-kill : %d",top_kill); printf(" selektiv search dynamic limit: %d",it4_qdyn); printf(" initiativ change : %d",skift); printf("\n 9 Iterativ search : %d",iterativ); printf(" simple-kill : %d",s_kill); printf(" always-cutoff it. 2: %d",always_cut); printf("\n A Trace: %d",trace); printf(" screen-info: %d",info_out); printf(" full evaluation: %d",full_evalu); // printf("\n B TRACE ON (set trace=33, screen-info=0; iterativ=0; full-evaluation=0)"); printf("\n C Weights - mobility : %d",wmobil); printf(" centre : %d",wcentr); printf(" opening-tips : %d",wopen); printf(" king safety : %d",wkingsaf); printf("\n D matesearch : %d hash : %d random: %d" ,mate_search, swhash, wrand); // printf("\n E Position: Staircasemate with extra Q... mate in 12 "); printf("\n E Bishop pair......: %d",bishoppair); printf(" exchange factor... : %d",exchf); // printf("\n F Position: 'Morphy'-problem... mate in 8"); // printf("\n G Position: A lot of Knights..... mate in 8 (4,x,x)"); // printf("\n H Position: 1.-,Rc7-c5+ wins the bishop....."); // printf("\n I Position: 1.Ne5xf7? played by Dabbaba at (3,4,2)"); printf("\n J Magic number.....: %d",magic); printf(" weight pawnstruct. : %d",wpawn); printf(" quiet-pos sel.depth: %d",quiet_depth); // printf("\n K Position: Larsen 02 - timetest simple killers"); printf("\n K on/off(=0) King centre: %d",king_centre); printf(" King corner: %d",king_corner); printf(" Q near K: %d",Q_near_enemy_K); printf(" Rook: %d",rook_placement); menu_50: if (whole_menu equal false) printf("\n W See the whole menu"); printf("\n\n Read README.TXT and DABBABA.TXT for more information\n"); printf("\n ! Exit DABBABA "); #ifdef CHECKALL printf(" CHECKALL"); #endif #ifdef CHECKSQAVOID printf(" CHECKSQAVOID"); #endif #ifdef VARIANTS printf(" -INSUF.MAT."); #else printf(" -VARIANTS"); #endif #ifdef PLAYEARLYGAMEFAST #else printf(" -FAST_OPENINGPLAY"); #endif #ifdef RANDOM4 printf(" RANDOM4"); #endif #ifdef RANDOM16 printf(" RANDOM16"); #endif #ifdef RANDOMOFF printf(" RANDOMOFF"); #endif #ifdef SAMERANDOM printf(" SAMERANDOM"); #endif #ifdef CHECKJENSPCTIME printf(" CHECKJENSPCTIME"); #endif #ifdef ONLYFORJENS printf(" ONLYFORJENS"); #endif #ifdef TVHASH printf(" TVHASH"); #endif #ifdef CHECKHASH printf(" CHECKHASH"); #endif printf("\n\n? "); scanf_char(&valg); valg=toupper(valg); if (valg equal '0') {printf("\n 1. x seconds pr. move"); printf("\n 2. game in x minutes"); printf("\n 3. y moves in x minutes"); printf("\n 4. fixed depth"); printf("\n 5. mate in x moves\n\n? "); secprmove=0; gameinxmin=0; mateinx=0; full_evalu=1; mate_search=10; moves_inxmin=0; min_forxmoves=0; scanf_int(&valg2); if (valg2 equal 1) {printf("\nseconds pr. move\n? "); scanf_int(&dumint); secprmove=dumint;} if (valg2 equal 2) {printf("\nminutes pr. game\n? "); scanf_int(&dumint); gameinxmin=dumint;} if (valg2 equal 3) {printf("\nnumber of moves\n? "); scanf_int(&dumint); moves_inxmin=dumint; printf("\nin minutes\n? "); scanf_int(&dumint); min_forxmoves=dumint;} if (valg2 equal 4) valg='1'; if (valg2 equal 5) {printf("\nnumber of moves\n? "); scanf_int(&dumint); mateinx=dumint; full_evalu=0; mate_search=0; matelvl_stop=true; if (mateinx<0) {mateinx=0-mateinx; matelvl_stop=false;} last_iteration=(2*mateinx)-1; ant_sel_ply=1; check_search=0; } } if (valg equal '1') {printf("Brute-force depth\n? "); scanf_int(&dumint); last_iteration=(char)dumint; printf("selektive depth\n? "); // printf("(should be even; 4 evt. 2 is recommended)\n? "); scanf_int(&dumint); last_sel_ply=(char)dumint; printf("check-search depth\n? "); // printf("check-search depth (should be even; 4 evt. 2 is recommended)\n? "); scanf_int(&dumint); check_search=dumint; } if (valg equal '2') {strcpy(xxx,gem_xxx); if (magic!=5) make_array_ply_zero(); computer_and_display(); pb_move_ready=false; } if (valg equal '3') play_a_game(); if (valg equal '4') menu_variants(); if (valg equal '5') menu_positions(); if (valg equal '6') menu_diverse(); if (valg equal '7') testfil(); if (valg equal '8') {//printf("use top_killers (1=yes)\n? "); //scanf_int(&dumint); top_kill=dumint; printf("selektiv search DYNAMIC limit (100=no)\n? "); scanf_int(&dumint); it4_qdyn=dumint; printf("initiative change side in selektiv search (1=yes)\n? "); scanf_int(&dumint); skift=dumint; } if (valg equal '9') { printf("iterative search (1=yes)\n? "); scanf_int(&dumint); iterativ=dumint; printf("simple killers (0=no, 1,2(mate) (3='advanced'...) )\n? "); scanf_int(&dumint); s_kill=dumint; printf("always cut off (0=no,1=yes,2=auto)\n? "); scanf_int(&dumint); always_cut=dumint; } if (valg equal 'A') {printf("Trace depth 0-99\n"); printf(" (-30000 = print line every 30000 nodes)\n\n? "); scanf_int(&trace); printf("information on screen (1=yes)\n? "); scanf_int(&dumint); info_out=dumint; printf("full evaluation (1=yes, 0=no=only materiel)\n? "); scanf_int(&dumint); full_evalu=dumint; } // if (valg equal 'B') // {trace=33; info_out=0; iterativ=0; full_evalu=0;} if (valg equal 'C') {printf("weights (8=normal, 16=double, 4=half etc.)\n"); printf("mobility\n? "); scanf_int(&wmobil); printf("centre\n? "); scanf_int(&wcentr); printf("opening-tips\n? "); scanf_int(&wopen); printf("king safety\n? "); scanf_int(&wkingsaf); } if (valg equal 'D') {printf("mate search size at iteration 4 (0=none)\n? "); scanf_int(&dumint); mate_search=dumint; printf("use hashtables (0=no)\n? "); scanf_int(&dumint); swhash=dumint; // printf("repeated positions (draw) 1=on; 0=off\n? "); // scanf_int(&dumint); swrepeat4=dumint; printf("weight random opening moves\n? "); scanf_int(&dumint); wrand=dumint; } if (valg equal 'E') {printf("bishoppair weight\n? "); scanf_int(&dumint); bishoppair=dumint; printf("exchange factor (0=off)\n? "); scanf_int(&dumint); exchf=dumint; } // {strcpy(xxx,"6bb/3PR1rQ/2BN1KP1/k1P2PN1/4PB2/3PR3/2PP4/2Q5/b Rg7-f7+!"); // make_array_ply_zero(); // show_board(); // } // if (valg equal 'F') //{strcpy(xxx,"1rb2nnb/1p1pp1P1/4p1k1/P1p3pN/4P2p/K4QP1/4r2q/8/w Qf3-f7+!"); // make_array_ply_zero(); // show_board(); // } // if (valg equal 'G') // {strcpy(xxx,"N7/PPPPPPPP/K1k3qB/brpnn3/7N/6rb/8/8/w b7-b8N+!"); // make_array_ply_zero(); // show_board(); // } // if (valg equal 'H') // {strcpy(xxx,"4N2k/2r3N1/1r6/7K/8/8/B7/8/b Rc7-c5+!"); // make_array_ply_zero(); // show_board(); // } // if (valg equal 'I') //{strcpy(xxx,"rnb1k1nr/pp3ppp/8/1qp1N3/8/2P5/PP2NPPP/R2QKB1R/w Ne5xf7?"); // make_array_ply_zero(); // show_board(); // } if (valg equal 'J') {//printf(" 2 also consider promotion to bishop and rook\n"); // printf(" 3 allow more than one quiet move in each line\n"); printf("( 3 iteration 1: no cut-off; try all moves)\n"); printf("( 4 don't try to save time on pawn-evaluation)\n"); printf("( 5 no extra make-array-ply-zero in 2) compute a move)\n"); printf("( 6 no change side by non-quiet positions)\n"); printf(" 7 show all positions searched\n"); printf(" 8 show the board slowly\n"); printf("(13 don't display ++-+-+...... line)\n"); scanf_int(&magic); printf("\n\n weight pawn structure\n\n? "); scanf_int(&wpawn); printf("\n\n check quiet pos. depth in sel. search(0=never)\n\n? "); scanf_int(&quiet_depth); } if (valg equal 'R') {if (wrand==0) wrand=8; else wrand=0;} if (valg equal 'S') {if (mate_search==0) mate_search=10; else mate_search=0;} if (valg equal 'T') {last_iteration=2; last_sel_ply=2; check_search=2; mate_search=0; wrand=0; it4_qdyn=100; secprmove=0; } if (valg equal 'W') {if (whole_menu==false) whole_menu=true; else whole_menu=false;} if (valg equal 'Y') {strcpy(xxx,"2bq3k/2p4p/p2p4/7P/1nBPPQP1/r1p5/8/1K1R2R1/b Bc8e6"); make_array_ply_zero(); show_board(); } // if (valg equal 'Z') eco(); } } #ifdef FILTRACE void make_tracefile() { /* 4R3/p1p2kpp/8/2br4/5B2/P5P1/1Pp2P1P/6K1/w Re8-e1! not h3??? 5nk1/p2p2bp/1p1qp3/3N4/2P3QP/1P2B1P1/P7/5K2/b e6xd5! 1r2k2r/p1p2pp1/2pb3p/5p2/2PPpqP1/2N2b1P/PPQ2P2/R1N2RK1/w Qc2xe4! ArcChess rn2kbr1/pp1qpNpp/4B3/2p5/3pP3/8/PPPB2PP/RN1Q1RK1/b Qd7xe6! r4rk1/1ppqp1b1/p1n1pn1p/1B1p2p1/3P4/6B1/PPPN1PPP/R2QR1K1/w */ /* last_iteration=3; last_sel_ply=6; check_search=0; mate_search=10; iterativ=1; // 0=off; 1=on always_cut=1; // 2=automatic trace=2; hash=1; wrand=0; wpawn=4; s_kill=3; // 0=off; 3=advanced... info_out=0; gameinxmin=0; secprmove=0; it4_qdyn=50; // 100=off; 50=normal skift=1; top_kill=1; full_evalu=1; quiet_depth=3; exchf=50; king_centre=1; king_corner=1; Q_near_enemy_K=1; rook_placement=1; strcpy(xxx,"r4rk1/1ppqp1b1/p1n1pn1p/1B1p2p1/3P4/6B1/PPPN1PPP/R2QR1K1/w"); make_array_ply_zero(); computer_and_display(); */ /* last_iteration=2; last_sel_ply=6; check_search=0; mate_search=10; iterativ=1; // 0=off; 1=on always_cut=1; // 2=automatic trace=2; swhash=1; wrand=0; wpawn=4; s_kill=1; // 0=off; 2=advanced... info_out=0; gameinxmin=0; secprmove=0; it4_qdyn=50; // 100=off; 50=normal skift=1; top_kill=1; full_evalu=1; quiet_depth=3; exchf=50; king_centre=1; king_corner=1; Q_near_enemy_K=1; rook_placement=1; strcpy(xxx,"r4rk1/1ppqp1b1/p1n1pn1p/1B1p2p1/3P4/6B1/PPPN1PPP/R2QR1K1/w"); make_array_ply_zero(); computer_and_display(); last_iteration=4; last_sel_ply=8; check_search=0; mate_search=10; iterativ=1; // 0=off; 1=on always_cut=1; // 2=automatic trace=2; swhash=1; wrand=0; wpawn=4; s_kill=3; // 0=off; 3=advanced... info_out=0; gameinxmin=0; secprmove=40; it4_qdyn=50; // 100=off; 50=normal skift=1; top_kill=1; full_evalu=1; quiet_depth=3; exchf=50; king_centre=1; king_corner=1; Q_near_enemy_K=1; rook_placement=1; strcpy(xxx,"rnbqk2r/pp3ppp/3b4/4N3/1P1pQ3/8/P1P2PPP/RNB2RK1/b Bd6xb4?"); make_array_ply_zero(); computer_and_display(); */ /* last_iteration=2; last_sel_ply=8; check_search=0; mate_search=10; iterativ=1; // 0=off; 1=on always_cut=1; // 2=automatic trace=2; swhash=1; wrand=0; wpawn=4; s_kill=3; // 0=off; 3=advanced... info_out=0; gameinxmin=0; secprmove=0; it4_qdyn=50; // 100=off; 50=normal skift=1; top_kill=1; full_evalu=1; quiet_depth=3; exchf=50; king_centre=1; king_corner=1; Q_near_enemy_K=1; rook_placement=1; strcpy(xxx,"rnbqk2r/pp3ppp/3b4/4N3/1P1pQ3/8/P1P2PPP/RNB2RK1/b Bd6xb4?"); make_array_ply_zero(); // score 30002 dukker op... computer_and_display(); */ last_iteration=3; last_sel_ply=8; check_search=0; mate_search=10; iterativ=1; // 0=off; 1=on always_cut=1; // 2=automatic trace=2; swhash=1; wrand=0; wpawn=4; s_kill=3; // 0=off; 3=advanced... info_out=0; gameinxmin=0; secprmove=0; it4_qdyn=50; // 100=off; 50=normal skift=1; /*top_kill=1;*/ full_evalu=1; quiet_depth=1; exchf=50; king_centre=1; king_corner=1; Q_near_enemy_K=1; rook_placement=1; strcpy(xxx,"2kr3r/1p1qppbp/p1b4p/2QpP3/8/2N2N1P/PPP2PP1/3RR1K1/b"); //r‘kkeflg. i it. 3 // Bc6-a4 bliver f›rst removed i iteration 2...... make_array_ply_zero(); computer_and_display(); } #endif //void zread_hash(unsigned long int key) //{ /* {wfarp=farp+key*sizeof(hash); movedata(FP_SEG(hashint), FP_OFF(hashint), FP_SEG(wfarp), FP_OFF(wfarp), sizeof(hash)); memcpy(&hash, hashint, sizeof(hash)); } */ // {wfarp=farp+key*sizeof(hash); // movedata(FP_SEG(farp)+key*sizeof(hash), FP_OFF(farp)+key*sizeof(hash), // FP_SEG(&hash), FP_OFF(&hash), // sizeof(hash)); //memcpy(&hash, hashint, sizeof(hash)); // } //} //void zwrite_hash(unsigned long int key) //{ /* {memcpy(hashint, &hash, sizeof(hash)); wfarp=farp+key*sizeof(hash); movedata(FP_SEG(wfarp), FP_OFF(wfarp), FP_SEG(hashint), FP_OFF(hashint), sizeof(hash)); } */ // {//memcpy(hashint, &hash, sizeof(hash)); // wfarp=farp+key*sizeof(hash); // movedata(FP_SEG(&hash), FP_OFF(&hash), // FP_SEG(farp)+key*sizeof(hash), FP_OFF(farp)+key*sizeof(hash), // sizeof(hash)); // } //} int main() {long unsigned int qqq; int x, y; nullmove[0]=99; #ifdef QUIETEXPERIMENT quiet_depth=3; #endif #ifdef RANDOM4 wrand=4; #endif #ifdef RANDOM16 wrand=16; #endif initgraph(&gdriver, &gmode, ""); errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ {printf("Graphics error: %s\n", grapherrormsg(errorcode)); press_any_key_to_continue(); exit(1); } setlinestyle(SOLID_LINE, LINE_FILL, NORM_WIDTH); if (rand() % 2 == 0) boardcolor=MAGENTA; else boardcolor=rand() % 16; setfillstyle(SOLID_FILL,WHITE); // board_y = (getmaxy()-(8*sqwidth))/5; board_x = (getmaxx()-(8*sqwidth))/2; board_x = (getmaxx()-(10*sqwidth)); //char far *farptr; //char *str = "Hello"; do_alloc: // hash_totbytes=(hash_maxindex)*sizeof(hash); hash_totbytes=32768; //* allocate memory for the far pointer // farptr = (char far *) farmalloc(1000); #ifdef MET2 farp = (hash_struct far *) farmalloc((unsigned) hash_totbytes); #else farp = /*(char far *)*/ farmalloc((unsigned) hash_totbytes); #endif // if (farp==NULL) // {if (hash_maxindex>=256) // {hash_maxindex=hash_maxindex/2; goto do_alloc;} // } if (farp==NULL) {printf("bad alloc......\n"); getch(); goto shit;} // printf("allocated %lu bytes for hashtables\n", hash_totbytes); //make_delay(300); #ifdef COMPACT hash_maxindex=256; #endif hash_maxindex-=1; #define noTTTT #define noTT #ifdef TTTT printf("TTTT\n"); #ifdef TT printf("TT\n"); #endif #endif plydyb=4; // vi pr›ver kun med 3...... if (hash_maxindex>512) plydyb=4; // if (hash_maxindex>8000) plydyb=5; // if (hash_maxindex>32000) plydyb=6; // if (hash_maxindex>128000) plydyb=7; //gemplydyb=plydyb; #ifdef CHECKHASH for (qqq=0; qqq