X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=hachu.c;h=e3290faa3d0ab64a71e22e2f7b99b45a6cc425c0;hb=public;hp=9cf4f273c1571959ad04346f233b7870596e5545;hpb=0504227a39e037ff953825e04a2b3d1e65b78416;p=hachu.git diff --git a/hachu.c b/hachu.c index 9cf4f27..e3290fa 100644 --- a/hachu.c +++ b/hachu.c @@ -160,7 +160,7 @@ typedef struct { char fireMask; } UndoInfo; -char *array, fenArray[4000], startPos[4000], *reason, checkStack[300]; +char *array, *IDs, fenArray[4000], startPos[4000], *reason, checkStack[300]; int bWidth, bHeight, bsize, zone, currentVariant, chuFlag, tenFlag, chessFlag, repDraws, stalemate; int tsume, pvCuts, allowRep, entryProm, okazaki, pVal; int stm, xstm, hashKeyH=1, hashKeyL=1, framePtr, msp, nonCapts, rootEval, filling, promoDelta; @@ -179,12 +179,14 @@ Move retMove, moveStack[20000], path[100], repStack[300], pv[1000], repeatMove[3 #define I -3 /* jump + step */ #define D -4 /* linear double move */ #define T -5 /* linear triple move */ -#define L -6 /* true Lion move */ -#define F -7 /* Lion + 3-step */ -#define S -8 /* Lion + range */ -#define H -9 /* hook move */ -#define C -10 /* capture only */ -#define M -11 /* non-capture only */ +#define K -6 /* triple + range */ +#define L -7 /* true Lion move */ +#define W -8 /* Werewolf move */ +#define F -9 /* Lion + 3-step */ +#define S -10 /* Lion + range */ +#define H -11 /* hook move */ +#define C -12 /* capture only */ +#define M -13 /* non-capture only */ #define LVAL 1000 /* piece value of Lion. Used in chu for recognizing it to implement Lion-trade rules */ #define FVAL 5000 /* piece value of Fire Demon. Used in code for recognizing moves with it and do burns */ @@ -246,133 +248,182 @@ PieceDesc daiPieces[] = { {"AB", "G", 60, { 1,0,1,0,1,0,1,0 }, 1 }, // Angry Boar {"I", "G", 80, { 1,1,0,0,0,0,0,1 }, 2 }, // Iron {"N", "G", 60, { N,0,0,0,0,0,0,N }, 0 }, // Knight - {"ST", "G", 50, { 0,1,0,0,0,0,0,1 }, 0 }, // Stone + {"SG", "G", 50, { 0,1,0,0,0,0,0,1 }, 0 }, // Stone { NULL } // sentinel }; PieceDesc waPieces[] = { {"TE", "", 720, { X,X,1,X,X,X,1,X }, 4 }, // Tenacious Falcon {"GS", "", 500, { X,0,X,0,X,0,X,0 }, 4 }, // Gliding Swallow (R) - {"DE", "", 430, { X,3,1,1,X,1,1,3 }, 3 }, // Cloud Eagle + {"CE", "", 430, { X,3,1,1,X,1,1,3 }, 3 }, // Cloud Eagle {"K", "", 410, { 1,1,1,1,1,1,1,1 }, 2 }, // Crane King (K) - {"BT", "", 390, { I,I,0,I,I,I,0,I }, 4 }, // Treacherous Fox - {"FL", "TE", 380, { 1,X,0,X,0,X,0,X }, 4 }, // Flying Falcon - {"FS", "", 290, { X,1,1,0,X,0,1,1 }, 3 }, // Raiding Falcon - {"S", "GS", 260, { 1,0,X,0,1,0,X,0 }, 6 }, // Swallow's Wing (SM) + {"TF", "", 390, { I,I,0,I,I,I,0,I }, 4 }, // Treacherous Fox + {"FF", "TE", 380, { 1,X,0,X,0,X,0,X }, 4 }, // Flying Falcon + {"RF", "", 290, { X,1,1,0,X,0,1,1 }, 3 }, // Raiding Falcon + {"SW", "GS", 260, { 1,0,X,0,1,0,X,0 }, 6 }, // Swallow's Wing (SM) {"PO", "", 260, { 1,1,1,1,1,1,1,1 }, 2 }, // Plodding Ox (K) - {"R", "BT", 260, { X,1,0,1,1,1,0,1 }, 2 }, // Running Rabit - {"B", "", 240, { 1,1,1,1,0,1,1,1 }, 2 }, // Roaming Boar + {"RR", "TF", 260, { X,1,0,1,1,1,0,1 }, 2 }, // Running Rabit + {"RB", "", 240, { 1,1,1,1,0,1,1,1 }, 2 }, // Roaming Boar {"HH", "", 220, { N,0,0,N,N,0,0,N }, 1 }, // Heavenly Horse - {"EW", "PO", 220, { 1,1,1,0,1,0,1,1 }, 2 }, // Violent Wolf (G) - {"VM", "B", 200, { 1,1,0,1,0,1,0,1 }, 2 }, // Violent Stag (S) - {"G", "S", 190, { 1,1,0,0,1,0,0,1 }, 2 }, // Flying Goose (C) - {"SM", "VM", 175, { 1,1,0,0,1,0,0,1 }, 2 }, // Climbing Monkey (C) - {"DH", "HH", 170, { X,0,0,0,2,0,0,0 }, 1 }, // Liberated Horse - {"DK", "EW", 150, { 0,1,1,0,1,0,1,1 }, 2 }, // Blind Dog - {"PH", "PO", 150, { X,0,0,0,0,0,0,0 }, 1 }, // Oxcart (L) - {"L", "FS", 130, { 0,1,1,0,0,0,1,1 }, 2 }, // Flying Cock - {"KN", "DE", 115, { 1,0,0,1,0,1,0,0 }, 2 }, // Swooping Owl - {"C", "FL", 105, { 1,0,0,1,0,1,0,0 }, 2 }, // Strutting Crow - {"P", "EW", 80, { 1,0,0,0,0,0,0,0 }, 2 }, // Sparrow Pawn (P) + {"VW", "PO", 220, { 1,1,1,0,1,0,1,1 }, 2 }, // Violent Wolf (G) + {"VS", "RB", 200, { 1,1,0,1,0,1,0,1 }, 2 }, // Violent Stag (S) + {"FG", "SW", 190, { 1,1,0,0,1,0,0,1 }, 2 }, // Flying Goose (C) + {"CM", "VS", 175, { 1,1,0,0,1,0,0,1 }, 2 }, // Climbing Monkey (C) + {"LH", "HH", 170, { X,0,0,0,2,0,0,0 }, 1 }, // Liberated Horse + {"BD", "VW", 150, { 0,1,1,0,1,0,1,1 }, 2 }, // Blind Dog + {"OC", "PO", 150, { X,0,0,0,0,0,0,0 }, 1 }, // Oxcart (L) + {"FC", "RF", 130, { 0,1,1,0,0,0,1,1 }, 2 }, // Flying Cock + {"SO", "CE", 115, { 1,0,0,1,0,1,0,0 }, 2 }, // Swooping Owl + {"SC", "FF", 105, { 1,0,0,1,0,1,0,0 }, 2 }, // Strutting Crow + {"P", "VW", 80, { 1,0,0,0,0,0,0,0 }, 2 }, // Sparrow Pawn (P) { NULL } // sentinel }; PieceDesc ddPieces[] = { - {"LO", "", 10, { 1,H,1,H,1,H,1,H } }, // Long-Nosed Goblin - {"OK", "LO", 10, { 2,1,2,0,2,0,2,1 } }, // Old Kite - {"PS", "HM", 10, { J,0,1,J,0,J,1,0 } }, // Poisonous Snake - {"GE", "", 10, { 3,3,5,5,3,5,5,3 } }, // Great Elephant - {"WS", "LD", 10, { 1,1,2,0,1,0,2,1 } }, // Western Barbarian - {"EA", "LN", 10, { 2,1,1,0,2,0,1,1 } }, // Eastern Barbarian - {"NO", "FE", 10, { 0,2,1,1,0,1,1,2 } }, // Northern Barbarian - {"SO", "WE", 10, { 0,1,1,2,0,2,1,1 } }, // Southern Barbarian - {"FE", "", 10, { 2,X,2,2,2,2,2,X } }, // Fragrant Elephant - {"WE", "", 10, { 2,2,2,X,2,X,2,2 } }, // White Elephant - {"FT", "", 10, { X,X,5,0,X,0,5,X } }, // Free Dream-Eater - {"FR", "", 10, { 5,X,X,0,5,0,X,X } }, // Free Demon - {"WB", "FT", 10, { 2,X,X,X,2,X,X,X } }, // Water Buffalo - {"RB", "FR", 10, { X,X,X,X,0,X,X,X } }, // Rushing Bird - {"SB", "", 10, { X,X,2,2,2,2,2,X } }, // Standard Bearer - - {"FH", "FK", 10, { 1,2,1,0,1,0,1,2 } }, // Flying Horse - {"NK", "SB", 10, { 1,1,1,1,1,1,1,1 } }, // Neighbor King + {"HM", "", 10, { H,0,H,0,H,0,H,0 } }, // Hook Mover H! + {"LO", "", 10, { 1,H,1,H,1,H,1,H } }, // Long-Nosed Goblin G! + {"OK", "LO", 10, { 2,1,2,0,2,0,2,1 } }, // Old Kite K' + {"PS", "HM", 10, { J,0,1,J,0,J,1,0 } }, // Poisonous Snake S' + {"FF", "", 10, { F,F,F,F,F,F,F,F } }, // Furious Fiend +L! + {"GE", "", 10, { 3,3,5,5,3,5,5,3 } }, // Great Elephant +W! + {"WS", "LD", 10, { 1,1,2,0,1,0,2,1 } }, // Western Barbarian W' + {"EA", "LN", 10, { 2,1,1,0,2,0,1,1 } }, // Eastern Barbarian E' + {"NO", "FE", 10, { 0,2,1,1,0,1,1,2 } }, // Northern Barbarian N' + {"SO", "WE", 10, { 0,1,1,2,0,2,1,1 } }, // Southern Barbarian S' + {"FE", "", 10, { 2,X,2,2,2,2,2,X } }, // Fragrant Elephant +N' + {"WE", "", 10, { 2,2,2,X,2,X,2,2 } }, // White Elephant +S' + {"FT", "", 10, { X,X,5,0,X,0,5,X } }, // Free Dream-Eater +W + {"FR", "", 10, { 5,X,X,0,5,0,X,X } }, // Free Demon +U + {"WB", "FT", 10, { 2,X,X,X,2,X,X,X } }, // Water Buffalo W + {"RU", "FR", 10, { X,X,X,X,0,X,X,X } }, // Rushing Bird U + {"SB", "", 10, { X,X,2,2,2,2,2,X } }, // Standard Bearer +N + {"FH", "FK", 10, { 1,2,1,0,1,0,1,2 } }, // Flying Horse H' + {"NK", "SB", 10, { 1,1,1,1,1,1,1,1 } }, // Neighbor King N + {"RG", "", 10, { 1,1,0,1,1,1,1,1 } }, // Right General R' + {"LG", "", 10, { 1,1,1,1,1,1,0,1 } }, // Left General L' {"BM", "MW", 10, { 0,1,1,1,0,1,1,1 } }, // Blind Monkey - {"DO", "", 10, { 2,X,2,X,2,X,2,X } }, // Dove - {"EB", "DO", 10, { 2,0,2,0,0,0,2,0 } }, // Enchanted Badger - {"EF", "SD", 10, { 0,2,0,0,2,0,0,2 } }, // Enchanted Fox - {"RA", "", 10, { X,0,X,1,X,1,X,0 } }, // Racing Chariot - {"SQ", "", 10, { X,1,X,0,X,0,X,1 } }, // Square Mover + {"DO", "", 10, { 2,5,2,5,2,5,2,5 } }, // Dove + {"EB", "DO", 10, { 2,0,2,0,0,0,2,0 } }, // Enchanted Badger B' + {"EF", "SD", 10, { 0,2,0,0,2,0,0,2 } }, // Enchanted Fox X' + {"RA", "", 10, { X,0,X,1,X,1,X,0 } }, // Racing Chariot A + {"SQ", "", 10, { X,1,X,0,X,0,X,1 } }, // Square Mover Q' {"PR", "SQ", 10, { 1,1,2,1,0,1,2,1 } }, // Prancing Stag - {"WT", "", 10, { X,1,2,0,X,0,2,X } }, // White Tiger - {"BD", "", 10, { 2,X,X,0,2,0,X,1 } }, // Blue Dragon - {"HD", "", 10, { X,0,0,0,1,0,0,0 } }, // Howling Dog - {"VB", "", 10, { 0,2,1,0,0,0,1,2 } }, // Violent Bear - {"SA", "", 10, { 2,1,0,0,2,0,0,1 } }, // Savage Tiger - {"W", "", 10, { 0,2,0,0,0,0,0,2 } }, // Wood - {"CS", "DH", 70, { 0,1,0,1,0,1,0,1 } }, // cat sword - {"FD", "DK", 150, { 0,2,0,2,0,2,0,2 } }, // flying dragon - {"KN", "GD", 150, { J,1,J,1,J,1,J,1 } }, // kirin - {"PH", "GB", 150, { 1,J,1,J,1,J,1,J } }, // phoenix - {"LN", "FF", 1000, { L,L,L,L,L,L,L,L } }, // lion - {"LD", "GE", 10, { T,T,T,T,T,T,T,T } }, // Lion Dog - {"AB", "", 10, { 1,0,1,0,1,0,1,0 } }, // Angry Boar - {"B", "", 10, { 0,X,0,X,0,X,0,X } }, // Bishop - {"C", "", 10, { 1,1,0,0,1,0,0,1 } }, // Copper - {"DH", "", 10, { 1,X,1,X,1,X,1,X } }, // Dragon Horse - {"DK", "", 10, { X,1,X,1,X,1,X,1 } }, // Dragon King - {"FK", "", 10, { } }, // - {"EW", "", 10, { 1,1,1,0,0,0,1,1 } }, // Evil Wolf - {"FL", "", 10, { } }, // - {"", "", 10, { } }, // - {"", "", 10, { } }, // + {"WT", "", 10, { X,1,2,0,X,0,2,X } }, // White Tiger T! + {"BD", "", 10, { 2,X,X,0,2,0,X,1 } }, // Blue Dragon D! + {"HD", "", 10, { X,0,0,0,1,0,0,0 } }, // Howling Dog D' + {"VB", "", 10, { 0,2,1,0,0,0,1,2 } }, // Violent Bear V + {"ST", "", 10, { 2,1,0,0,2,0,0,1 } }, // Savage Tiger T' + {"W", "", 10, { 0,2,0,0,0,0,0,2 } }, // Wood General V' + {"CS", "DH", 70, { 0,1,0,1,0,1,0,1 } }, // Cat Sword C' + {"FD", "DK", 150, { 0,2,0,2,0,2,0,2 } }, // Flying Dragon F' + {"LD", "GE", 10, { T,T,T,T,T,T,T,T } }, // Lion Dog W! + {"AB", "", 10, { 1,0,1,0,1,0,1,0 } }, // Angry Boar A' + {"EW", "", 10, { 1,1,1,0,0,0,1,1 } }, // Evil Wolf + {"SD", "", 10, { 5,2,5,2,5,2,5,2 } }, // She-Devil + {"GD", "", 10, { 2,3,X,3,2,3,X,3 } }, // Great Dragon + {"GO", "", 10, { X,3,2,3,X,3,2,3 } }, // Golden Bird + {"LC", "", 10, { X,0,0,X,1,0,0,X } }, // Left Chariot L' + {"RC", "", 10, { X,X,0,0,1,X,0,0 } }, // Right Chariot R' + // Chu pieces (but with different promotion) + {"LN", "FF",LVAL, { L,L,L,L,L,L,L,L }, 4 }, // lion + {"FK", "", 600, { X,X,X,X,X,X,X,X }, 4 }, // free king + {"DK", "", 400, { X,1,X,1,X,1,X,1 }, 4 }, // dragon king + {"DH", "", 350, { 1,X,1,X,1,X,1,X }, 4 }, // dragon horse + {"R", "", 300, { X,0,X,0,X,0,X,0 }, 4 }, // rook + {"K", "", 280, { 1,1,1,1,1,1,1,1 }, 2, 4 }, // king + {"B", "", 250, { 0,X,0,X,0,X,0,X }, 2 }, // bishop + {"VM", "", 200, { X,0,1,0,X,0,1,0 }, 2 }, // vertical mover + {"SM", "", 200, { 1,0,X,0,1,0,X,0 }, 6 }, // side mover + {"G", "", 151, { 1,1,1,0,1,0,1,1 }, 2 }, // gold + {"FL", "", 150, { 1,1,0,1,1,1,0,1 }, 2 }, // ferocious leopard + {"KN", "GD", 154, { J,1,J,1,J,1,J,1 }, 2 }, // kirin + {"PH", "GO", 153, { 1,J,1,J,1,J,1,J }, 2 }, // phoenix + {"RV", "", 150, { X,0,0,0,X,0,0,0 }, 1 }, // reverse chariot + {"L", "", 150, { X,0,0,0,0,0,0,0 }, 1 }, // lance + {"S", "", 100, { 1,1,0,1,0,1,0,1 }, 2 }, // silver + {"C", "", 100, { 1,1,0,0,1,0,0,1 }, 2 }, // copper + {"P", "", 40, { 1,0,0,0,0,0,0,0 }, 2 }, // pawn {"", "", 10, { } }, // {"", "", 10, { } }, // { NULL } // sentinel }; PieceDesc makaPieces[] = { - {"DV", "", 10, { 0,1,0,1,0,0,1,1 } }, // Deva - {"DS", "", 10, { 0,1,1,0,0,1,0,1 } }, // Dark Spirit - {"T", "", 10, { 0,1,0,0,1,0,0,1 } }, // Tile - {"CS", "", 10, { 1,0,0,1,1,1,0,0 } }, // Coiled Serpent - {"RD", "", 10, { 1,0,1,1,1,1,1,0 } }, // Reclining Dragon - {"CC", "", 10, { 0,1,1,0,1,0,1,1 } }, // Chinese Cock - {"OM", "", 10, { 0,1,0,1,1,1,0,1 } }, // Old Monkey - {"BB", "", 10, { 0,1,0,1,X,1,0,1 } }, // Blind Bear - {"OR", "", 10, { 0,2,0,0,2,0,0,2 } }, // Old Rat - {"LD", "WS", 10, { T,T,T,T,T,T,T,T } }, // Lion Dog - {"WR", "", 10, { 0,3,1,3,0,3,1,3 } }, // Wrestler - {"GG", "", 10, { 3,1,3,0,3,0,3,1 } }, // Guardian of the Gods - {"BD", "", 10, { 0,3,1,0,1,0,1,3 } }, // Budhist Devil - {"SD", "", 10, { 5,2,5,2,5,2,5,2 } }, // She-Devil - {"DY", "", 10, { J,0,1,0,J,0,1,0 } }, // Donkey - {"CP", "", 10, { 0,H,0,2,0,2,0,H } }, // Capricorn - {"HM", "", 10, { H,0,H,0,H,0,H,0 } }, // Hook Mover - {"SF", "", 10, { 0,1,X,1,0,1,0,1 } }, // Side Flier - {"LC", "", 10, { X,0,0,X,1,0,0,X } }, // Left Chariot - {"RC", "", 10, { X,X,0,0,1,X,0,0 } }, // Right Chariot - {"FG", "", 10, { X,X,X,0,X,0,X,X } }, // Free Gold - {"FS", "", 10, { X,X,0,X,0,X,0,X } }, // Free Silver - {"FC", "", 10, { X,X,0,0,X,0,0,X } }, // Free Copper - {"FI", "", 10, { X,X,0,0,0,0,0,X } }, // Free Iron - {"FT", "", 10, { 0,X,0,0,X,0,0,X } }, // Free Tile - {"FN", "", 10, { 0,X,0,0,0,0,0,X } }, // Free Stone - {"FTg", "", 10, { 0,X,X,X,X,X,X,X } }, // Free Tiger - {"FLp", "", 10, { X,X,0,X,X,X,0,X } }, // Free Leopard (Free Boar?) - {"FSp", "", 10, { X,0,0,X,X,X,0,0 } }, // Free Serpent (Whale?) - {"FrD", "", 10, { X,0,X,X,X,X,X,0 } }, // Free Dragon - {"FC", "", 10, { 0,X,0,X,0,X,0,X } }, // Free Cat (Bishop?) - {"EM", "", 10, { } }, // Emperor - {"TK", "", 10, { } }, // Teaching King - {"BS", "", 10, { } }, // Budhist Spirit - {"WS", "", 10, { X,X,0,X,1,X,0,X } }, // Wizard Stork - {"MW", "", 10, { 1,X,0,X,X,X,0,X } }, // Mountain Witch - {"FF", "", 10, { } }, // Furious Fiend - {"GD", "", 10, { 2,3,X,3,2,3,X,3 } }, // Great Dragon - {"GB", "", 10, { X,3,2,3,X,3,2,3 } }, // Golden Bird - {"FrW", "", 10, { } }, // Free Wolf - {"FrB", "", 10, { } }, // Free Bear - {"BT", "", 10, { X,0,0,X,0,X,0,0 } }, // Bat + {"DV", "TK", 10, { 0,1,0,1,0,0,1,1 } }, // Deva I' + {"DS", "BS", 10, { 0,1,1,0,0,1,0,1 } }, // Dark Spirit J' + {"T", "fT", 10, { 0,1,0,0,1,0,0,1 } }, // Tile General Y + {"CO", "fS", 10, { 1,0,0,1,1,1,0,0 } }, // Coiled Serpent S! + {"RD", "fD", 10, { 1,0,1,1,1,1,1,0 } }, // Reclining Dragon D! + {"CC", "WS", 10, { 0,1,1,0,1,0,1,1 } }, // Chinese Cock N' + {"OM", "MW", 10, { 0,1,0,1,1,1,0,1 } }, // Old Monkey M' + {"BB", "fB", 10, { 0,1,0,1,X,1,0,1 } }, // Blind Bear B' + {"OR", "BA", 10, { 0,2,0,0,2,0,0,2 } }, // Old Rat O' + {"LD", "WS", 10, { T,T,T,T,T,T,T,T } }, // Lion Dog W! + {"WR", "G", 10, { 0,3,1,3,0,3,1,3 } }, // Wrestler W' + {"GG", "G", 10, { 3,1,3,0,3,0,3,1 } }, // Guardian of the Gods G' + {"BD", "G", 10, { 0,3,1,0,1,0,1,3 } }, // Budhist Devil D' + {"SD", "G", 10, { 5,2,5,2,5,2,5,2 } }, // She-Devil S' + {"DY", "G", 10, { J,0,1,0,J,0,1,0 } }, // Donkey Y' + {"CA", "G", 10, { 0,H,0,2,0,2,0,H } }, // Capricorn C! + {"HM", "G", 10, { H,0,H,0,H,0,H,0 } }, // Hook Mover H! + {"SF", "G", 10, { 0,1,X,1,0,1,0,1 } }, // Side Flier F! + {"LC", "G", 10, { X,0,0,X,1,0,0,X } }, // Left Chariot L' + {"RC", "G", 10, { X,X,0,0,1,X,0,0 } }, // Right Chariot R' + {"fT", "", 10, { 0,X,X,X,X,X,X,X } }, // Free Tiger +T + {"fD", "", 10, { X,0,X,X,X,X,X,0 } }, // Free Dragon +D! + {"fG", "", 10, { X,X,X,0,X,0,X,X } }, // Free Gold +G + {"fS", "", 10, { X,X,0,X,0,X,0,X } }, // Free Silver +S + {"fI", "", 10, { X,X,0,0,0,0,0,X } }, // Free Iron +I + {"fY", "", 10, { 0,X,0,0,X,0,0,X } }, // Free Tile +Y + {"fU", "", 10, { 0,X,0,0,0,0,0,X } }, // Free Stone +U + {"EM", "", 10, { 0,0,0,0,0,0,0,0 } }, // Emperor +K + {"TK", "", 10, { K,K,K,K,K,K,K,K } }, // Teaching King +I' + {"BS", "", 10, { S,S,S,S,S,S,S,S } }, // Budhist Spirit +J' + {"WS", "", 10, { X,X,0,X,1,X,0,X } }, // Wizard Stork +N' + {"MW", "", 10, { 1,X,0,X,X,X,0,X } }, // Mountain Witch +M' + {"FF", "", 10, { F,F,F,F,F,F,F,F } }, // Furious Fiend +L! + {"GD", "", 10, { 2,3,X,3,2,3,X,3 } }, // Great Dragon +W! + {"GO", "", 10, { X,3,2,3,X,3,2,3 } }, // Golden Bird +X + {"fW", "", 10, { X,X,X,0,0,0,X,X } }, // Free Wolf +W + {"BA", "", 10, { X,0,0,X,0,X,0,0 } }, // Bat +O' + {"FD", "G", 150, { 0,2,0,2,0,2,0,2 }, 2 }, // Flying Dragon + // Dai pieces with different promotion + {"FD", "G", 150, { 0,2,0,2,0,2,0,2 }, 2 }, // Flying Dragon + {"VO", "G", 200, { 2,0,2,0,2,0,2,0 }, 2 }, // Violent Ox + {"EW", "fW", 80, { 1,1,1,0,0,0,1,1 }, 2 }, // Evil Wolf + {"CS", "B", 70, { 0,1,0,1,0,1,0,1 }, 1 }, // Cat Sword + {"AB", "FB", 60, { 1,0,1,0,1,0,1,0 }, 1 }, // Angry Boar + {"T", "fY", 80, { 0,1,0,0,1,0,0,1 }, 2 }, // Tile + {"I", "fI", 80, { 1,1,0,0,0,0,0,1 }, 2 }, // Iron + {"N", "G", 60, { N,0,0,0,0,0,0,N }, 0 }, // Knight + {"SG", "fU", 50, { 0,1,0,0,0,0,0,1 }, 0 }, // Stone + // Chu pieces (but with different promotion) + {"LN", "FF",LVAL, { L,L,L,L,L,L,L,L }, 4 }, // lion + {"FK", "", 600, { X,X,X,X,X,X,X,X }, 4 }, // free king + {"FO", "", 400, { X,X,0,X,X,X,0,X }, 4 }, // flying ox (free leopard) + {"FB", "", 400, { 0,X,X,X,0,X,X,X }, 4 }, // free boar + {"DK", "", 400, { X,1,X,1,X,1,X,1 }, 4 }, // dragon king + {"DH", "", 350, { 1,X,1,X,1,X,1,X }, 4 }, // dragon horse + {"WH", "", 350, { X,X,0,0,X,0,0,X }, 3 }, // white horse (free copper) + {"R", "G", 300, { X,0,X,0,X,0,X,0 }, 4 }, // rook + {"WL", "", 250, { X,0,0,X,X,X,0,0 }, 4 }, // whale (free serpent) + {"K", "EM", 280, { 1,1,1,1,1,1,1,1 }, 2, 4 }, // king + {"CP", "", 270, { 1,1,1,1,1,1,1,1 }, 2, 4 }, // king + {"B", "G", 250, { 0,X,0,X,0,X,0,X }, 2 }, // bishop + {"VM", "G", 200, { X,0,1,0,X,0,1,0 }, 2 }, // vertical mover + {"SM", "G", 200, { 1,0,X,0,1,0,X,0 }, 6 }, // side mover + {"DE", "CP", 201, { 1,1,1,1,0,1,1,1 }, 2 }, // drunk elephant + {"BT", "fT", 152, { 0,1,1,1,1,1,1,1 }, 2 }, // blind tiger + {"G", "fG", 151, { 1,1,1,0,1,0,1,1 }, 2 }, // gold + {"FL", "FO", 150, { 1,1,0,1,1,1,0,1 }, 2 }, // ferocious leopard + {"KN", "GD", 154, { J,1,J,1,J,1,J,1 }, 2 }, // kirin + {"PH", "GB", 153, { 1,J,1,J,1,J,1,J }, 2 }, // phoenix + {"RV", "G", 150, { X,0,0,0,X,0,0,0 }, 1 }, // reverse chariot + {"L", "G", 150, { X,0,0,0,0,0,0,0 }, 1 }, // lance + {"S", "fS", 100, { 1,1,0,1,0,1,0,1 }, 2 }, // silver + {"C", "WH", 100, { 1,1,0,0,1,0,0,1 }, 2 }, // copper + {"GB", "RV", 50, { 1,0,0,0,1,0,0,0 }, 1 }, // go between + {"P", "G", 40, { 1,0,0,0,0,0,0,0 }, 2 }, // pawn {"", "", 10, { } }, // { NULL } // sentinel }; @@ -419,87 +470,123 @@ PieceDesc taikyokuPieces[] = { }; PieceDesc chessPieces[] = { - {"FK", "", 950, { X,X,X,X,X,X,X,X } }, + {"Q", "", 950, { X,X,X,X,X,X,X,X } }, {"R", "", 500, { X,0,X,0,X,0,X,0 } }, {"B", "", 320, { 0,X,0,X,0,X,0,X } }, {"N", "", 300, { N,N,N,N,N,N,N,N } }, {"K", "", 280, { 1,1,1,1,1,1,1,1 } }, - {"P", "FK", 80, { M,C,0,0,0,0,0,C } }, + {"P", "Q", 80, { M,C,0,0,0,0,0,C } }, { NULL } // sentinel }; PieceDesc lionPieces[] = { - {"LN","", LVAL, { L,L,L,L,L,L,L,L } }, - {"FK", "", 600, { X,X,X,X,X,X,X,X } }, + {"L", "", LVAL, { L,L,L,L,L,L,L,L } }, + {"Q", "", 600, { X,X,X,X,X,X,X,X } }, {"R", "", 300, { X,0,X,0,X,0,X,0 } }, {"K", "", 280, { 1,1,1,1,1,1,1,1 } }, {"B", "", 190, { 0,X,0,X,0,X,0,X } }, {"N", "", 180, { N,N,N,N,N,N,N,N } }, - {"P", "FK", 50, { M,C,0,0,0,0,0,C } }, + {"P", "Q", 50, { M,C,0,0,0,0,0,C } }, { NULL } // sentinel }; PieceDesc shatranjPieces[] = { - {"FK", "", 150, { 0,1,0,1,0,1,0,1 } }, + {"Q", "", 150, { 0,1,0,1,0,1,0,1 } }, {"R", "", 500, { X,0,X,0,X,0,X,0 } }, {"B", "", 90, { 0,J,0,J,0,J,0,J } }, {"N", "", 300, { N,N,N,N,N,N,N,N } }, {"K", "", 280, { 1,1,1,1,1,1,1,1 } }, - {"P", "FK", 80, { M,C,0,0,0,0,0,C } }, + {"P", "Q", 80, { M,C,0,0,0,0,0,C } }, { NULL } // sentinel }; PieceDesc makrukPieces[] = { - {"SM","", 150, { 0,1,0,1,0,1,0,1 } }, + {"M", "", 150, { 0,1,0,1,0,1,0,1 } }, {"R", "", 500, { X,0,X,0,X,0,X,0 } }, {"S", "", 200, { 1,1,0,1,0,1,0,1 } }, // silver {"N", "", 300, { N,N,N,N,N,N,N,N } }, {"K", "", 280, { 1,1,1,1,1,1,1,1 } }, - {"P", "SM", 80, { M,C,0,0,0,0,0,C } }, + {"P", "M", 80, { M,C,0,0,0,0,0,C } }, { NULL } // sentinel }; -char chuArray[] = "L:FLCSGK:DEGSC:FLL/:RV.B.:BT:KN:PH:BT.B.:RV/:SM:VMR:DH:DK:LN:FK:DK:DHR:VM:SM/PPPPPPPPPPPP/...:GB....:GB..." - "/............/............/" - "...:gb....:gb.../pppppppppppp/:sm:vmr:dh:dk:fk:ln:dk:dhr:vm:sm/:rv.b.:bt:ph:kn:bt.b.:rv/l:flcsg:dekgsc:fll"; -char daiArray[] = "LN:STICSGKGSCI:STNL/:RV.:CS.:FL.:BT:DE:BT.:FL.:CS.:RV/.:VO.:AB.:EW:KN:LN:PH:EW.:AB.:VO./R:FD:SM:VMB:DH:DK:FK:DK:DHB:VM:SM:FDR" - "/PPPPPPPPPPPPPPP/....:GB.....:GB..../.............../.............../.............../....:gb.....:gb..../ppppppppppppppp/" - "r:fd:sm:vmb:dh:dk:fk:dk:dhb:vm:sm:fdr/.:vo.:ab.:ew:ph:ln:kn:ew.:ab.:vo./:rv.:cs.:fl.:bt:de:bt.:fl.:cs.:rv/ln:sticsgkgsci:stnl"; -char tenArray[] = "LN:FLICSGK:DEGSCI:FLNL/:RV.:CS:CS.:BT:KN:LN:FK:PH:BT.:CS:CS.:RV/:SS:VSB:DH:DK:WB:FI:LH:FE:FI:WB:DK:DHB:VS:SS/" - ":SM:VMR:HF:SE:BG:RG:GG:VG:RG:BG:SE:HFR:VM:SM/PPPPPPPPPPPPPPPP/....D......D..../" - "................/................/................/................/" - "....d......d..../pppppppppppppppp/:sm:vmr:hf:se:bg:rg:vg:gg:rg:bg:se:hfr:vm:sm/" - ":ss:vsb:dh:dk:wb:fi:fe:lh:fi:wb:dk:dhb:vs:ss/:rv.:cs:cs.:bt:ph:fk:ln:kn:bt.:cs:cs.:rv/ln:flicsg:dekgsci:flnl"; -char shoArray[] = "LNSGKGSNL/.B..:DE..R./PPPPPPPPP/........./........./........./ppppppppp/.r..:de..b./lnsgkgsnl"; -char waArray[] = ":PH:DKCG:EWK:VML:KN:SM:DH/.:FL...S...:DE./PPP:BTPPPRPPP/...P...P..." - "/.........../.........../..........." - "/...p...p.../ppprppp:btppp/.:de...s...:fl./:dh:sm:knl:vmk:ewgc:dk:ph"; -char chessArray[] = "RNB:FKKBNR/PPPPPPPP/......../......../......../......../pppppppp/rnb:fkkbnr"; -char lionArray[] = "R:LNB:FKKBNR/PPPPPPPP/......../......../......../......../pppppppp/r:lnb:fkkbnr"; -char shatArray[]= "RNBK:FKBNR/PPPPPPPP/......../......../......../......../pppppppp/rnbk:fkbnr"; -char thaiArray[]= "RNSK:SMSNR/......../PPPPPPPP/......../......../pppppppp/......../rns:smksnr"; +PieceDesc wolfPieces[] = { + {"W", "W",1050,{ W,W,W,W,W,W,W,W }, 6, 5 }, // kludge to get extra Werewolves + {"R", "", 500, { X,0,X,0,X,0,X,0 }, 3 }, + {"B", "", 320, { 0,X,0,X,0,X,0,X }, 1 }, + {"N", "", 300, { N,N,N,N,N,N,N,N }, 1 }, + {"K", "", 280, { 1,1,1,1,1,1,1,1 }, 0, 4 }, + {"P", "R", 80, { M,C,0,0,0,0,0,C } }, + { NULL } // sentinel +}; + +char chuArray[] = "lfcsgekgscfl/a1b1txot1b1a/mvrhdqndhrvm/pppppppppppp/3i4i3" + "/12/12/" + "3I4I3/PPPPPPPPPPPP/MVRHDNQDHRVM/A1B1TOXT1B1A/LFCSGKEGSCFL"; +char daiArray[] = "lnuicsgkgsciunl/a1c'1f1tet1f1c'1a/1x'1a'1wxl!ow1a'1x'1/rf'mvbhdqdhbvmf'r/" + "ppppppppppppppp/4p'5p'4/15/15/15/4P'5P'4/PPPPPPPPPPPPPPP/" + "RF'MVBHDQDHBVMF'R/1X'1A'1WOL!XW1A'1X'1/A1C'1F1TET1F1C'1A/LNUICSGKGSCIUNL"; +char tenArray[] = "lnficsgekgscifnl/a1c!c!1txql!ot1c!c!1a/s'v'bhdw!d!q!h!d!w!dhbv's'/" + "mvrf!e!b!r!v!q!r!b!e!f!rvm/pppppppppppppppp/4d6d4/" + "16/16/16/16/" + "4D6D4/PPPPPPPPPPPPPPPP/MVRF!E!B!R!Q!V!R!B!E!F!RVM/" + "S'V'BHDW!D!H!Q'D!W!DHBV'S'/A1C!C!TOL!QXT1C!C!1A/LNFICSGKEGSCIFNL"; +char cashewArray[]= "lh!f'dh'j'ki'qc'hg!l/t!p'w!+oogngx+xl!k'd!/r've'fst'+nt'sfw'vl'/ppppppppppppp/3d'5d'3/13/" + "13/13/3D'5D'3/PPPPPPPPPPPPP/L'VW'FST'+NT'SFE'VR'/D!K'L!+XXGNGO+OW!P'T!/LG!HC'QI'KJ'H'DF'H!L"; +char macadArray[] = "lxcsgi'kj'gscol/1f'1w!1tet1l!1f'1/rr'g'bdh!qc!dbw'l'r/ppppppppppppp/3p'5p'3/13/" + "13/13/3P'5P'3/PPPPPPPPPPPPP/RL'W'BDC!QH!DBG'R'R/1F'1L!1TET1W!1F'1/LOCSGI'KJ'GSCXL"; +char shoArray[] = "lnsgkgsnl/1r2e2b1/ppppppppp/9/9/9/PPPPPPPPP/1B2E2R1/LNSGKGSNL"; +char waArray[] = "hmlcvkwgudo/1e3s3f1/ppprpppxppp/3p3p3/11/11/11/3P3P3/PPPXPPPRPPP/1F3S3E1/ODUGWKVCLMH"; +char chessArray[] = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"; +char lionArray[] = "rlbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RLBQKBNR"; +char shatArray[] = "rnbkqbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBKQBNR"; +char thaiArray[] = "rnsmksnr/8/pppppppp/8/8/PPPPPPPP/8/RNSKMSNR"; +char wolfArray[] = "rnbwkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBWKBNR"; + +// translation tables for single-(dressed-)letter IDs to multi-letter names, per variant +// A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z. +char chuIDs[] = "RVB C DKDEFLG DHGB..K L SMLNKNP FKR S BT..VM..PH...."; +char daiIDs[] = "RVB C DKDEFLG DHI ..K L SMN KNP FKR S BTSGVMEWPH...." // L + "AB CS FD GB VO " // L' + " LN "; // L! +char tenIDs[] = "RVB C DKDEFLG DHI ..K L SMN KNP FKR S BT..VM..PH...." // L + ".. ..D .. FE SS VS " // L' + " BGCSFISEHF LH LN GGRG VGWB "; // L! +char waIDs[] = "....FCBDCEFFFGLH....K SOCM..OCP ..RRSW..SCVSVWTF...."; +char chessIDs[] = "A B ....E F ........K L M N ..P Q R S ......W ......"; // covers all chess-like variants +char makaIDs[] = "RVB C DKDEFLG DHI ..K L SMN KNP FKR S BTSG..EWPHT .." // L (also for Macadamia) + "ABBBCSBDE FDGG DVDS LCBMCCORGB RCSD WRVODY " // L' + " CARD HM LN CO VMLD "; // L! +char dadaIDs[] = "RVB C DKEFFLG DHI ..K L SMNKKNP FKR S ..SGVBEWPH...." // L (also for Cashew) + "ABEBCSHDEAFDPRFHLGRGOKLCOMNOORPS RCSOST W WSVO " // L' + "RAWB BD LGHM LN SQ WTRUVMLD "; // L! typedef struct { int boardWidth, boardFiles, boardRanks, zoneDepth, varNr; // board sizes char *name; // WinBoard name char *array; // initial position + char *IDs; } VariantDesc; -typedef enum { V_CHESS, V_SHO, V_CHU, V_DAI, V_DADA, V_MAKA, V_TAI, V_KYOKU, V_TENJIKU, V_SHATRANJ, V_MAKRUK, V_LION, V_WA } Variant; +typedef enum { V_CHESS, V_SHO, V_CHU, V_DAI, V_DADA, V_MAKA, V_TAI, V_KYOKU, V_TENJIKU, + V_CASHEW, V_MACAD, V_SHATRANJ, V_MAKRUK, V_LION, V_WA, V_WOLF } Variant; #define SAME (-1) VariantDesc variants[] = { - { 24, 12, 12, 4, V_CHU, "chu", chuArray }, // Chu - { 16, 8, 8, 1, V_CHESS, "nocastle", chessArray }, // FIDE - { 18, 9, 9, 3, V_SHO, "9x9+0_shogi", shoArray }, // Sho - { 18, 9, 9, 3, V_SHO, "sho", shoArray }, // Sho duplicat - { 30, 15, 15, 5, V_DAI, "dai", daiArray }, // Dai - { 32, 16, 16, 5, V_TENJIKU, "tenjiku", tenArray }, // Tenjiku - { 16, 8, 8, 1, V_SHATRANJ,"shatranj",shatArray}, // Shatranj - { 16, 8, 8, 3, V_MAKRUK, "makruk", thaiArray}, // Makruk - { 16, 8, 8, 1, V_LION, "lion", lionArray}, // Mighty Lion - { 22, 11, 11, 3, V_WA, "washogi", waArray}, // Wa + { 24, 12, 12, 4, V_CHU, "chu", chuArray, chuIDs }, // Chu + { 16, 8, 8, 1, V_CHESS, "nocastle", chessArray,chessIDs }, // FIDE + { 18, 9, 9, 3, V_SHO, "9x9+0_shogi", shoArray, chuIDs }, // Sho + { 18, 9, 9, 3, V_SHO, "sho", shoArray, chuIDs }, // Sho duplicat + { 30, 15, 15, 5, V_DAI, "dai", daiArray, daiIDs }, // Dai + { 32, 16, 16, 5, V_TENJIKU, "tenjiku", tenArray, tenIDs }, // Tenjiku + { 16, 8, 8, 1, V_SHATRANJ,"shatranj",shatArray, chessIDs}, // Shatranj + { 16, 8, 8, 3, V_MAKRUK, "makruk", thaiArray, chessIDs}, // Makruk + { 16, 8, 8, 1, V_LION, "lion", lionArray, chessIDs}, // Mighty Lion + { 22, 11, 11, 3, V_WA, "wa-shogi", waArray, waIDs}, // Wa + { 16, 8, 8, 1, V_WOLF, "werewolf",wolfArray, chessIDs}, // Werewolf Chess + { 26, 13, 13,13, V_CASHEW, "cashew-shogi", cashewArray, dadaIDs }, // Cashew + { 26, 13, 13,13, V_MACAD, "macadamia-shogi", macadArray, makaIDs }, // Macadamia { 0, 0, 0, 0, 0 }, // sentinel { 34, 17, 17, 0, V_DADA, "dada", chuArray }, // Dai Dai @@ -622,6 +709,7 @@ typedef struct { char mobWeight; unsigned char promoGain; char bulk; + char ranking; } PieceInfo; // piece-list entry int last[2], royal[2], kylin[2]; @@ -694,6 +782,12 @@ LookUp (char *name, int var) return ListLookUp(name, lionPieces); case V_WA: // Wa return ListLookUp(name, waPieces); + case V_WOLF: // Werewolf + return ListLookUp(name, wolfPieces); + case V_CASHEW: // Cashew + return ListLookUp(name, ddPieces); + case V_MACAD: // Cashew + return ListLookUp(name, makaPieces); } return NULL; } @@ -835,6 +929,7 @@ AddPiece (int stm, PieceDesc *list) p[i].pieceKey = *key; p[i].promoFlag = 0; p[i].bulk = list->bulk; + p[i].ranking = list->ranking; p[i].mobWeight = v > 600 ? 0 : v >= 400 ? 1 : v >= 300 ? 2 : v > 150 ? 3 : v >= 100 ? 2 : 0; if(Lance(list->range)) p[i].mobWeight = 0, p[i].pst = list->range[4] ? PST_NEUTRAL : PST_LANCE; // keep back @@ -851,12 +946,12 @@ AddPiece (int stm, PieceDesc *list) void SetUp (char *array, int var) { - int i, j, n, m, color; - char c, name[3], prince = 0; + int i, j, n, m, color, c; + char name[3], prince = 0; PieceDesc *p1, *p2; last[WHITE] = 1; last[BLACK] = 0; royal[WHITE] = royal[BLACK] = 0; - for(i=0; ; i++) { + for(i=BH-1; ; i--) { //printf("next rank: %s\n", array); for(j = BW*i; ; j++) { int pflag=0; @@ -864,17 +959,23 @@ SetUp (char *array, int var) c = name[0] = *array++; if(!c) goto eos; if(c == '.') continue; + if(c > '0' && c <= '9') { + c -= '0'; if(*array >= '0' && *array <= '9') c = 10*c + *array++ - '0'; + j += c - 1; continue; + } if(c == '/') break; name[1] = name[2] = 0; - if(c == ':') name[0] = *array++, name[1] = *array++; - if(name[0] >= 'a') { + if(c >= 'a') { color = BLACK; - name[0] += 'A' - 'a'; - if(name[1]) name[1] += 'A' - 'a'; + c += 'A' - 'a'; } else color = WHITE; + if(*array == '\'') c += 26, array++; else + if(*array == '!') c += 52, array++; + name[0] = IDs[2*(c - 'A')]; + name[1] = IDs[2*(c - 'A') + 1]; if(name[1] == ' ') name[1] = 0; if(!strcmp(name, "CP") || pflag && !strcmp(name, "DE")) prince |= color+1; // remember if we added Crown Prince p1 = LookUp(name, var); - if(!p1) printf("tellusererror Unknown piece '%s' in setup\n", name), exit(-1); + if(!p1) printf("tellusererror Unknown piece '%s' in setup (%d)\n", name, c), exit(-1); if(pflag && p1->promoted) p1 = LookUp(p1->promoted, var); // use promoted piece instead n = AddPiece(color, p1); p[n].pos = j; @@ -909,6 +1010,7 @@ SetUp (char *array, int var) if(x != ABSENT) for(j=0; j<8; j++) fireBoard[x+kStep[j]] |= n; n <<= 1; } + for(i=2; i<6; i++) if(p[i].ranking == 5) p[i].promo = -1, p[i].promoFlag = 0; // take promotability away from Werewolves for(i=0; ivalue : 0; // get Pawn value @@ -990,7 +1093,7 @@ Init (int var) // Lion-Dog triple moves toList[64+i] = 3*kStep[i]; epList[64+i] = kStep[i]; toList[72+i] = 3*kStep[i]; epList[72+i] = 2*kStep[i]; - toList[80+i] = 3*kStep[i]; epList[80+i] = kStep[i]; ep2List[80+i] = 2*kStep[i]; + toList[80+i] = 3*kStep[i]; epList[80+i] = 2*kStep[i]; ep2List[80+i] = kStep[i]; toList[88+i] = kStep[i]; epList[88+i] = 2*kStep[i]; } @@ -1197,18 +1300,22 @@ GenNonCapts (int promoSuppress) for(j=0; j<8; j++) { int y, v = kStep[j], r = p[i].range[j]; if(r < 0) { // jumping piece, special treatment - if(r == N) { // pure Knightm do off-ray jump + if(r == N) { // pure Knight, do off-ray jump NewNonCapture(x, x + nStep[j], pFlag); } else if(r >= S) { // in any case, do a jump of 2 int occup = NewNonCapture(x, x + 2*v, pFlag); if(r < I) { // Lion power, also single step - if(!NewNonCapture(x, x + v, pFlag)) nullMove = x; else occup = 1; + if(!NewNonCapture(x, x + v, pFlag)) nullMove = (r == W ? ABSENT : x); else occup = 1; if(r <= L) { // true Lion, also Knight jump if(!occup & r < L) for(y=x+2*v; !NewNonCapture(x, y+=v, pFlag) && r == S; ); // BS and FF moves v = nStep[j]; - NewNonCapture(x, x + v, pFlag); + if(r != W) NewNonCapture(x, x + v, pFlag); } else if(r == T) NewNonCapture(x, x+3*v, pFlag); // Lion Dog, also triple step + else if(r == K) { + occup |= NewNonCapture(x, x+3*v, pFlag); // Lion Dog, also triple step + if(!occup) for(y=x+3*v; !NewNonCapture(x, y+=v, pFlag); ); // TK moves + } } else if(r == I) NewNonCapture(x, x + v, pFlag); // also do step } else if(r == M) { // FIDE Pawn; check double-move @@ -1252,15 +1359,26 @@ MapOneColor (int start, int last, int *map) if(board[x + v] != EMPTY && board[x + v] != EDGE) map[2*(x + v) + start] += one[j]; if(r < I) { - if(r == T) { // Lion Dog, also jump of 3 + if(r == T || r == K) { // Lion Dog, also jump of 3 if(board[x + 3*v] != EMPTY && board[x + 3*v] != EDGE) map[2*(x + 3*v) + start] += one[j]; + if(r == K) { // also range (Teaching King) + int y = x, n = 0; + while(1) { + if(board[y+=v] == EDGE) break; + if(board[y] != EMPTY) { + if(n > 2) map[2*y + start] += one[j]; // outside Lion range + break; + } + n++; + } + } } else if(r <= L) { // true Lion, also Knight jump if(r < L) { // Lion plus (limited) range int y = x, n = 0; - r = (r == S ? 36 : 3); - while(n++ <= r) { + int rg = (r == S ? 36 : 3); + while(n++ < rg) { if(board[y+=v] == EDGE) break; if(board[y] != EMPTY) { if(n > 2) map[2*y + start] += one[j]; // outside Lion range @@ -1269,7 +1387,7 @@ MapOneColor (int start, int last, int *map) } } v = nStep[j]; - if(board[x + v] != EMPTY && board[x + v] != EDGE) + if(board[x + v] != EMPTY && board[x + v] != EDGE && r != W) map[2*(x + v) + start] += one[8]; } } @@ -1434,10 +1552,18 @@ MakeMove(Move m, UndoInfo *u) u->epVictim[0] = EDGE; // kludge to flag to UnMake this is special move } - u->booty += PST[p[u->new].pst + u->to] - PST[p[u->piece].pst + u->from]; - u->victim = board[u->to]; p[u->victim].pos = ABSENT; + if(p[u->victim].ranking == 5 && p[u->piece].ranking < 4) { // contageous piece captured by non-royal + u->booty -= p[u->new].value; + u->new = u->piece & 1 | 2; // promote to it + if(p[u->new].pos != ABSENT) u->new += 2; + p[u->piece].pos = ABSENT; + u->booty += p[u->new].value; + } + + u->booty += PST[p[u->new].pst + u->to] - PST[p[u->piece].pst + u->from]; + filling += p[u->new].bulk - p[u->piece].bulk - p[u->victim].bulk; promoDelta += p[u->new].promoGain - p[u->piece].promoGain + p[u->victim].promoGain; u->booty += p[u->victim].value + PST[p[u->victim].pst + u->to]; @@ -1584,6 +1710,7 @@ GenCapts (int sqr, int victimValue) } break; case T: // Lion-Dog move (awful!) + case K: if(d > 3) break; NewCapture(x, sqr + victimValue - SORTKEY(attacker), p[attacker].promoFlag); att -= one[i]; @@ -1626,6 +1753,18 @@ GenCapts (int sqr, int victimValue) NewCapture(x, sqr + victimValue - SORTKEY(attacker), p[attacker].promoFlag); att -= one[i]; break; + case W: // jump + locust jump + 3-slide (Werewolf) + if(d > 2) break; + NewCapture(x, sqr + victimValue - SORTKEY(attacker), p[attacker].promoFlag); + att -= one[i]; + if(d == 2) { // check if we can take intermediate with it + if((board[x-v] & TYPE) == xstm && board[x-v] > board[sqr]) + NewCapture(x, SPECIAL + 9*i + victimValue - SORTKEY(attacker), p[attacker].promoFlag); // e.p. + } else { // d=1; can move on to second + if(board[sqr-v] == EMPTY || (board[sqr-v] & TYPE) == xstm && board[sqr-v] > board[sqr]) + NewCapture(x, SPECIAL + 9*i + victimValue - SORTKEY(attacker), p[attacker].promoFlag); // hit and run + } + break; case C: // FIDE Pawn if(d != 1) break; NewCapture(x, sqr + victimValue - SORTKEY(attacker), p[attacker].promoFlag); @@ -1635,7 +1774,7 @@ GenCapts (int sqr, int victimValue) //printf("mask[%d] = %o\n", i, att); if((att & attackMask[i]) == 0) break; } - // more attacks to come; san for next stop + // more attacks to come; scan for next stop if(jcapt < p[board[x]].qval) jcapt = p[board[x]].qval; // raise barrier for range jumpers further upstream while(board[x+=v] == EMPTY); // this should never run off-board, if the attack map is not corrupted } while(1); @@ -1646,7 +1785,7 @@ GenCapts (int sqr, int victimValue) for(i=0; i<8; i++) { // scan all knight jumps to locate source int x = sqr - nStep[i], attacker = board[x]; if(attacker == EMPTY || (attacker & TYPE) != stm) continue; - if(p[attacker].range[i] <= L && p[attacker].range[i] >= S || p[attacker].range[i] == N) { // has Knight jump in our direction + if(p[attacker].range[i] == L || p[attacker].range[i] < W && p[attacker].range[i] >= S || p[attacker].range[i] == N) { // has Knight jump in our direction NewCapture(x, sqr + victimValue, p[attacker].promoFlag); // plain jump (as in N) if(p[attacker].range[i] < N) { // Lion power; generate double captures over two possible intermediates int v = kStep[i]; // leftish path @@ -1956,6 +2095,7 @@ if(PATH) printf("# probe hash index=%x hit=%d\n", index, hit),fflush(stdout); if(hit >= 0) { bestScore = hashTable[index].score[hit]; hashMove = hashTable[index].move[hit]; + if((bestScore <= alpha || hashTable[index].flag[hit] & H_LOWER) && (bestScore >= beta || hashTable[index].flag[hit] & H_UPPER) ) { iterDep = resDep = hashTable[index].depth[hit]; bestMoveNr = 0; @@ -2156,7 +2296,7 @@ attacks += 2*bsize; MapFromScratch(attacks); // for as long as incremental update does not work. //if(flag & depth >= 0) printf("%2d:%d mapped %d/%d %s\n", depth, iterDep, curMove, msp, MoveToText(moveStack[curMove], 0)); //if(PATH) pmap(attacks, stm); - if(chuFlag && p[tb.victim].value == LVAL) {// verify legality of Lion capture in Chu Shogi + if(chuFlag && (p[tb.victim].value == LVAL || p[tb.epVictim[0]].value == LVAL)) {// verify legality of Lion capture in Chu Shogi score = 0; if(p[tb.piece].value == LVAL) { // Ln x Ln: can make Ln 'vulnerable' (if distant and not through intemediate > GB) if(dist[tb.from-tb.to] != 1 && attacks[2*tb.to + stm] && p[tb.epVictim[0]].value <= 50) @@ -2282,7 +2422,7 @@ pplist() for(i=0; i<182; i++) { printf("%3d. %3d %3d %4d %02x %d %d %x %3d %4d ", i, p[i].value, p[i].promo, p[i].pos, p[i].promoFlag&255, p[i].mobWeight, p[i].qval, p[i].bulk, p[i].promoGain, p[i].pst); for(j=0; j<8; j++) printf(" %2d", p[i].range[j]); - if(i<2 || i>11) printf("\n"); else printf(" %02x\n", fireFlags[i-2]&255); + if(i<2 || i>11) printf("\n"); else printf(" %02x %d\n", fireFlags[i-2]&255, p[i].ranking); } printf("last: %d / %d\nroyal %d / %d\n", last[WHITE], last[BLACK], royal[WHITE], royal[BLACK]); } @@ -2395,6 +2535,8 @@ MakeMove2 (int stm, MOVE move) if(chuFlag && p[undoInfo.victim].value == LVAL && p[undoInfo.piece].value != LVAL) sup2 |= PROMOTE; rootEval = -rootEval - undoInfo.booty; for(i=0; i<200; i++) repStack[i] = repStack[i+1], checkStack[i] = checkStack[i+1]; + + repStack[199] = hashKeyH, checkStack[199] = inCheck; printf("# makemove %08x %c%d %c%d\n", move, sup1%BW+'a', sup1/BW, sup2%BW+'a', sup2/BW); return stm ^ WHITE; @@ -2410,61 +2552,22 @@ UnMake2 (MOVE move) sup2 = sup1; sup1 = sup0; } -char fenNames[] = "RV....DKDEFL..DHGB......SMLNKN..FK....BT..VMEWPH..LN"; // pairs of char -char fenPromo[] = "WLDHSMSECPB R HFDE....WHFB..LNG ..DKVMFS..FO..FK...."; // pairs of char - -char * -Convert (char *fen) -{ - char *p = fenArray, *q, *rows[36], tmp[4000]; - int n=0; - printf("# convert FEN '%s'\n", fen); - q = strchr(fen, ' '); if(q) *q = 0; q = fen; - do { rows[n++] = q; q = strchr(q, '/'); if(!q) break; *q++ = 0; } while(1); - *tmp = 0; - while(--n >= 0) { strcat(tmp, rows[n]); if(n) strcat(tmp, "/"); } - fen = tmp; - printf("# flipped FEN '%s'\n", fen); - while(*fen) { - if(*fen == ' ') { *p = 0; break; } - if(n=atoi(fen)) fen++; // digits read - if(n > 9) fen++; // double digit - while(n-- > 0) *p++ = '.'; // expand to empty squares - if(currentVariant == V_LION && (*fen == 'L' || *fen == 'l')) *fen += 'Z' - 'L'; // L in Mighty-Lion Chess changed in Z for Lion - if(isalpha(*fen)) { - char *table = fenNames; - n = *fen > 'Z' ? 'a' - 'A' : 0; - if((currentVariant == V_CHESS || currentVariant == V_SHATRANJ || currentVariant == V_LION || - currentVariant == V_MAKRUK || currentVariant == V_SHO) && *fen - n == 'N' // In Chess N is Knight, not Lion - || table[2* (*fen - 'A' - n)] == '.') *p++ = *fen; else { - *p++ = ':'; - *p++ = table[2* (*fen - 'A' - n)] + n; - *p++ = table[2* (*fen - 'A' - n)+1] + n; - } - } else *p++ = *fen; - if(!*fen) break; - fen++; - } - *p = '\0'; - printf("# converted FEN '%s'\n", fenArray); - return fenArray; -} - int Setup2 (char *fen) { + char *p; int stm = WHITE; + static char startFEN[4000]; if(fen) { char *q = strchr(fen, '\n'); if(q) *q = 0; if(q = strchr(fen, ' ')) stm = (q[1] == 'b' ? BLACK : WHITE); // fen contains color field - if(strchr(fen, '.') || strchr(fen, ':')) array = fen; else array = Convert(fen); - } + } else fen = array; rootEval = promoDelta = filling = cnt50 = moveNr = 0; - SetUp(array, currentVariant); - strcpy(startPos, array); + SetUp(fen, currentVariant); sup0 = sup1 = sup2 = ABSENT; hashKeyH = hashKeyL = 87620895*currentVariant + !!fen; + for(p=startPos; *p++ = *fen++; ) {} // remember last start position for undo return stm; } @@ -2496,19 +2599,19 @@ MoveToText (MOVE move, int multiLine) if(t >= SPECIAL) { if(t < CASTLE) { // castling is printed as a single move, implying its side effects int e = f + epList[t - SPECIAL]; -// printf("take %c%d\n", e%BW+'a', e/BW+ONE); - sprintf(buf, "%c%d%c%d,", f%BW+'a', f/BW+ONE, e%BW+'a', e/BW+ONE); f = e; - if(multiLine) printf("move %s\n", buf), buf[0] = '\0'; if(ep2List[t - SPECIAL]) { - e = g + ep2List[t - SPECIAL]; + int e2 = f + ep2List[t - SPECIAL]; // printf("take %c%d\n", e%BW+'a', e/BW+ONE); - sprintf(buf+strlen(buf), "%c%d%c%d,", f%BW+'a', f/BW+ONE, e%BW+'a', e/BW+ONE); f = e; - if(multiLine) printf("move %s\n", buf), buf[0] = '\0'; + sprintf(buf+strlen(buf), "%c%d%c%d,", f%BW+'a', f/BW+ONE, e2%BW+'a', e2/BW+ONE); f = e2; + if(multiLine) printf("move %s\n", buf), buf[0] = '\0'; } +// printf("take %c%d\n", e%BW+'a', e/BW+ONE); + sprintf(buf, "%c%d%c%d,", f%BW+'a', f/BW+ONE, e%BW+'a', e/BW+ONE); f = e; + if(multiLine) printf("move %s\n", buf), buf[0] = '\0'; } t = g + toList[t - SPECIAL]; } - if(move & PROMOTE) promoChar = currentVariant == V_MAKRUK ? "m" : repDraws ? "q" : "+"; + if(move & PROMOTE) promoChar = currentVariant == V_MAKRUK ? "m" : currentVariant == V_WOLF ? "r" : repDraws ? "q" : "+"; sprintf(buf+strlen(buf), "%c%d%c%d%s", f%BW+'a', f/BW+ONE, t%BW+'a', t/BW+ONE, promoChar); return buf; } @@ -2538,6 +2641,11 @@ MapFromScratch(attacks); listStart = retFirst; msp = retMSP; if(currentVariant == V_LION) GenCastlings(); listEnd = msp; + for(i=listStart; i> SQLEN & SQUARE; + if(to >= SPECIAL) continue; + if(p[board[to]].ranking == 5 && p[board[from]].ranking < 4) moveStack[i] |= PROMOTE; + } } MOVE @@ -2554,10 +2662,27 @@ ParseMove (char *moveText) e = t; moveText += ReadSquare(moveText, &t); for(i=0; i<8; i++) if(f + kStep[i] == e) break; - if(i >= 8) return INVALID; // this rejects Lion Dog 2+1 and 2-1 moves! - for(j=0; j<8; j++) if(e + kStep[j] == t) break; - if(j >= 8) return INVALID; // this rejects Lion Dog 1+2 moves! - t2 = SPECIAL + 8*i + j; + if(i >= 8) { // first leg not King step. Try Lion Dog 2+1 or 2-1 + for(i=0; i<8; i++) if(f + 2*kStep[i] == e) break; + if(i >= 8) return INVALID; // not even that + if(f + 3*kStep[i] == t) t2 = SPECIAL + 72 + i; // 2+1 + else if(f + kStep[i] == t) t2 = SPECIAL + 88 + i; // 2-1 + else return INVALID; + } else if(f + 3*kStep[i] == t) { // Lion Dog 1+2 move + t2 = SPECIAL + 64 + i; + } else if(*moveText == ',') { // 3rd leg follows! + if(f + 2*kStep[i] != t) return INVALID; // 3-leg moves must be linear! + moveText += ReadSquare(moveText, &e); + if(e != t) return INVALID; // must again continue with same piece + moveText += ReadSquare(moveText, &t); + if(f + 3*kStep[i] == t) t2 = SPECIAL + 80 + i; // 1+1+1 + else if(f + kStep[i] == t) t2 = SPECIAL + 88 + i; // 2-1 entered as 1+1-1 + else return INVALID; + } else { + for(j=0; j<8; j++) if(e + kStep[j] == t) break; + if(j >= 8) return INVALID; // this rejects Lion Dog 1+2 moves! + t2 = SPECIAL + 8*i + j; + } } else if(chessFlag && board[f] != EMPTY && p[board[f]].value == pVal && board[t] == EMPTY) { // Pawn to empty, could be e.p. if(t == f + BW + 1) t2 = SPECIAL + 16; else if(t == f + BW - 1) t2 = SPECIAL + 48; else @@ -2570,6 +2695,7 @@ ParseMove (char *moveText) if(t == f-2 && f > BW) t2 = CASTLE + 3; } ret = f<= listEnd) { @@ -2635,9 +2761,13 @@ Highlight(char *coords) int e, t = moveStack[i] & SQUARE; if(t < SPECIAL) continue; // only special moves e = lastLift + epList[t - SPECIAL]; // decode + if(sqr == lastLift + ep2List[t - SPECIAL]) { // second leg of 3-leg move + b[e] = 'C'; cnt++; + continue; + } t = lastLift + toList[t - SPECIAL]; if(e != sqr) continue; - b[t] = (!boardCopy[t] ? 'Y' : 'R'); cnt++; + if(!b[t]) b[t] = (!boardCopy[t] ? 'Y' : 'R'); cnt++; } } if(!cnt) return; @@ -2724,8 +2854,10 @@ printf("# setup done");fflush(stdout); int i, c; while(1) { // wait for input, and read it until we have collected a complete line - for(i = 0; (inBuf[i] = c = getchar()) != '\n'; i++) if(c == EOF || i>7997) exit(0); - inBuf[i+1] = 0; + do { + for(i = 0; (inBuf[i] = c = getchar()) != '\n'; i++) if(c == EOF || i>7997) exit(0); + inBuf[i+1] = 0; + } while(!i); // ignore empty lines // extract the first word sscanf(inBuf, "%s", command); @@ -2823,7 +2955,7 @@ pboard(board); } stm = MakeMove2(stm, move); // assumes MakeMove returns new side to move gameMove[moveNr++] = move; // remember game - printf("move %s\n", MoveToText(pMove, 1)); + printf("move %s%s\n", MoveToText(pMove, 1), p[undoInfo.victim].ranking == 5 && p[undoInfo.piece].ranking < 4 ? "w" : ""); listEnd = 0; continue; // go check if we should ponder } @@ -2938,11 +3070,27 @@ pboard(board); Init(curVarNr = i); stm = Setup2(NULL); break; } } + if(currentVariant == V_WOLF) + printf("setup (PNBR......................WKpnbr......................wk) 8x8+0_fairy rnbwkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBWKBNR w 0 1\n" + "piece W& K3cpafK\n"); if(currentVariant == V_SHO) printf("setup (PNBRLSE..G.+++++++Kpnbrlse..g.+++++++k) 9x9+0_shogi lnsgkgsnl/1r2e2b1/ppppppppp/9/9/9/PPPPPPPPP/1B2E2R1/LNSGKGSNL w 0 1\n"); if(currentVariant == V_WA) - printf("setup (P.C.EVLO.WGHDF.TRSXOM.+.+..+++.+++++..+++++Kp.c.evlo.wghdf.trsxom.+.+..+++.+++++..+++++k) 11x11+0_chu " - "hmolvkwgcdx/1e3s3f1/ppprppptppp/3p3p3/11/11/11/3P3P3/PPPTPPPRPPP/1F3S3E1/XDCGWKVLOMH w 0 1\n"); + printf("setup (P..^S^FV..^LW^OH.F.^R.E....R...D.GOL^M..^H.M.C.^CU.^W/.......^V.^P.^U..^DS.^GXK" + "p..^s^fv..^lw^oh.f.^r.e....r...d.gol^m..^h.m.c.^cu.^w/.......^v.^p.^u..^ds.^gxk) 11x11+0_chu " + "hmlcvkwgudo/1e3s3f1/ppprpppxppp/3p3p3/11/11/11/3P3P3/PPPXPPPRPPP/1F3S3E1/ODUGWKVCLMH w 0 1\n" + "piece P& fW\npiece O& fR\npiece H& fRbW2\npiece U& fWbF\npiece L& fWbF\npiece M& vWfF\npiece G& vWfF\npiece C& sWfF\n" + "piece +P& WfF\npiece +O& K\npiece +H& vN\npiece +U& BfW\npiece +L& vRfF3bFsW\npiece +M& FfW\npiece +G& sRvW\npiece +C& vRsWfF\n" + "piece D& sbWfF\npiece V& FfW\npiece W& WfF\npiece S& sRvW\npiece R& FfRbW\npiece F& BfW\npiece X& FvWAvD\n" + "piece +D& WfF\npiece +V& FfsW\npiece +W& K\npiece +S& R\npiece +R& FvWAvD\npiece +F& BvRsW\npiece E& vRfF3bFsW\n"); + if(currentVariant == V_MACAD) + printf("setup (P.*B*RQSEXOG....D^J'..*LP'.L!J'...*W!...*F'...^C.C.^L!.^P'^K.T*L'.*C!*H!^I'.^E...*R'^P^T*W'*G'^G^SI'^X^OK" + "p.*b*rqsexog....d^j'..*lp'.l!j'...*w!...*f'...^c.c.^l!.^p'^k.t*l'.*c!*h!^i'.^e...*r'^p^t*w'*g'^g^si'^x^ok) 13x13+0_chu " + "%s w 0 1\n", macadArray); + if(currentVariant == V_CASHEW) + printf("setup (P.^K'^S'QS.XOGND'.HDT!...P'.L!E'.^EK'W!..LF'V^W'J'H'...^L!^N..FT'L'C'G!H!D!I'.^H'..R'..^C'^F'..W'^X^OK" + "p.^k'^s'qs.xognd'.hdt!...p'.l!e'.^ek'w!..lf'v^w'j'h'...^l!^n..ft'l'c'g!h!d!i'.^h'..r'..^c'^f'..w'^x^ok) 13x13+0_chu " + "%s w 0 1\n", cashewArray); repStack[199] = hashKeyH, checkStack[199] = 0; continue; }