LCOV - code coverage report
Current view: top level - src - game.h (source / functions) Hit Total Coverage
Test: test_coverage.info Lines: 54 64 84.4 %
Date: 2017-06-21 14:32:49 Functions: 4 4 100.0 %

          Line data    Source code
       1             : //////////////////////////////////////////////////////////////////////
       2             : //
       3             : //  FILE:       game.h
       4             : //              Game class for Scid.
       5             : //
       6             : //  Part of:    Scid (Shane's Chess Information Database)
       7             : //  Version:    3.5
       8             : //
       9             : //  Notice:     Copyright (c) 2000-2003 Shane Hudson.  All rights reserved.
      10             : //
      11             : //  Author:     Shane Hudson (sgh@users.sourceforge.net)
      12             : //
      13             : //////////////////////////////////////////////////////////////////////
      14             : 
      15             : 
      16             : #ifndef SCID_GAME_H
      17             : #define SCID_GAME_H
      18             : 
      19             : #include "common.h"
      20             : #include "date.h"
      21             : #include "indexentry.h"
      22             : #include "position.h"
      23             : #include "namebase.h"
      24             : #include "matsig.h"
      25             : #include <vector>
      26             : #include <string>
      27             : class ByteBuffer;
      28             : class TextBuffer;
      29             : 
      30             : void transPieces(char *s);
      31             : char transPiecesChar(char c);
      32             : 
      33             : // Piece letters translation
      34             : extern int language; // default to english
      35             : //  0 = en, 1 = fr, 2 = es, 3 = de
      36             : extern const char * langPieces[];
      37             : 
      38             : //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      39             : //  Game: Constants
      40             : 
      41             : // Common NAG Annotation symbol values:
      42             : const byte
      43             :     NAG_GoodMove = 1,
      44             :     NAG_PoorMove = 2,
      45             :     NAG_ExcellentMove = 3,
      46             :     NAG_Blunder = 4,
      47             :     NAG_InterestingMove = 5,
      48             :     NAG_DubiousMove = 6,
      49             :     NAG_OnlyMove = 8, // new
      50             :     NAG_Equal = 10,
      51             :     NAG_Unclear = 13,
      52             :     NAG_WhiteSlight = 14,
      53             :     NAG_BlackSlight = 15,
      54             :     NAG_WhiteClear = 16,
      55             :     NAG_BlackClear = 17,
      56             :     NAG_WhiteDecisive = 18,
      57             :     NAG_BlackDecisive = 19,
      58             :     NAG_WhiteCrushing = 20,
      59             :     NAG_BlackCrushing = 21,
      60             :     NAG_ZugZwang = 22, // new
      61             :     NAG_BlackZugZwang = 23, // new
      62             :     NAG_MoreRoom = 26, // new
      63             :     NAG_DevelopmentAdvantage = 35,  // new
      64             :     NAG_WithInitiative = 36, //new
      65             :     NAG_WithAttack = 40, // new
      66             :     NAG_WithBlackAttack = 41, // new
      67             :     NAG_Compensation = 44,      // from Whites perspective
      68             :     NAG_SlightCentre = 48,      // from Whites perspective
      69             :     NAG_Centre = 50,            // new
      70             :     NAG_SlightKingSide = 54,    // from Whites perspective
      71             :     NAG_ModerateKingSide = 56,  // from Whites perspective
      72             :     NAG_KingSide = 58,          // from Whites perspective
      73             :     NAG_SlightQueenSide = 60,   // from Whites perspective
      74             :     NAG_ModerateQueenSide = 62, // from Whites perspective
      75             :     NAG_QueenSide = 64,         // from Whites perspective
      76             :     NAG_SlightCounterPlay = 130, // new
      77             :     NAG_CounterPlay = 132, // new
      78             :     NAG_DecisiveCounterPlay = 134, // new
      79             :     NAG_BlackSlightCounterPlay = 131, // new
      80             :     NAG_BlackCounterPlay = 133, // new
      81             :     NAG_BlackDecisiveCounterPlay = 135, // new
      82             :     NAG_TimeLimit = 136, // new
      83             :     NAG_WithIdea = 140, // new
      84             :     NAG_BetterIs = 142, // new
      85             :     NAG_VariousMoves = 144, // new
      86             :     NAG_Comment = 145, // new
      87             :     NAG_Novelty = 146,
      88             :     NAG_WeakPoint = 147, // new
      89             :     NAG_Ending = 148, // new
      90             :     NAG_File = 149, // new
      91             :     NAG_Diagonal = 150, // new
      92             :     NAG_BishopPair = 151, // new
      93             :     NAG_OppositeBishops = 153, // new
      94             :     NAG_SameBishops = 154, // new
      95             :     NAG_Etc = 190, // new
      96             :     NAG_DoublePawns = 191, // new
      97             :     NAG_SeparatedPawns = 192, // new
      98             :     NAG_UnitedPawns = 193, // new
      99             :     NAG_Diagram = 201,  // Scid-specific NAGs start at 201.
     100             :     NAG_See = 210,  // new
     101             :     NAG_Mate = 211, // new 
     102             :     NAG_PassedPawn = 212, // new
     103             :     NAG_MorePawns = 213, //new
     104             :     NAG_With = 214, // new
     105             :     NAG_Without = 215;
     106             : 
     107             : // MAX_NAGS: Maximum id of NAG codes
     108             : const byte MAX_NAGS_ARRAY = 215;
     109             :     
     110             : // MAX_TAGS: Maximum number of additional non-standard tags.
     111             : const uint MAX_TAGS =  40;
     112             : 
     113             : const uint MAX_TAG_LEN = 240;
     114             : 
     115             : typedef byte markerT;
     116             : const markerT
     117             :     NO_MARKER = 0,
     118             :     START_MARKER = 1,
     119             :     END_MARKER = 2,
     120             :     END_GAME = 3;
     121             : 
     122             : 
     123             : // patternT structure: a pattern filter for material searches.
     124             : //    It can specify, for example, a white Pawn on the f-fyle, or
     125             : //    a black Bishop on f2 and white King on e1.
     126             : struct patternT
     127             : {
     128             :     pieceT     pieceMatch;  // EMPTY, WK, BK, etc...
     129             :     rankT      rankMatch;   // RANK_1 .. RANK_8 or NO_RANK
     130             :     fyleT      fyleMatch;   // A_FYLE .. H_FYLE or NO_FYLE
     131             :     byte       flag;        // 0 means this pattern must NOT occur.
     132             :     patternT * next;
     133             : };
     134             : 
     135             : // MAX_NAGS is the maximum number of NAGs (annotation symbols) a single
     136             : // move can have:
     137             : 
     138             : #define MAX_NAGS 8
     139             : 
     140             : 
     141             : // The moveT structure stores all necessary information for one move:
     142             : //
     143    15166600 : class moveT
     144             : {
     145             :     friend class Game;
     146             :     simpleMoveT  moveData;      // piece moving, target square etc
     147             :     char         san[10];           // SAN representation of move
     148             :     std::string  comment;
     149             :     moveT      * prev;
     150             :     moveT      * next;
     151             :     moveT      * varChild;
     152             :     moveT      * varParent;
     153             :     markerT      marker;  // can be NO_MARKER, START_MARKER or END_MARKER
     154             :     byte         numVariations;
     155             :     byte         nagCount;
     156             :     byte         nags[MAX_NAGS];
     157             : 
     158     1558130 :     bool isNull () const { return moveData.isNullMove(); }
     159             : };
     160             : 
     161             : 
     162             : 
     163             : // Since we want allocation and freeing of moves to be FAST, we allocate
     164             : // in chunks, and keep a linked list of the chunks allocated.
     165             : // Freed moves can be added to the FreeList, but it is not essential to
     166             : // do so, since all space for moves is deleted when the game is cleared.
     167             : #define MOVE_CHUNKSIZE 100    // Allocate space for 100 moves at a time.
     168             : 
     169     4469254 : struct moveChunkT {
     170             :     moveT moves [MOVE_CHUNKSIZE];
     171             :     uint numFree;
     172             :     moveChunkT * next;
     173             : };
     174             : 
     175             : struct tagT
     176             : {
     177             :     char * tag;
     178             :     char * value;
     179             : };
     180             : 
     181             : 
     182             : #define GAME_DECODE_NONE 0
     183             : #define GAME_DECODE_TAGS 1
     184             : #define GAME_DECODE_COMMENTS 2
     185             : #define GAME_DECODE_ALL 3
     186             : 
     187             : enum gameExactMatchT {
     188             :     GAME_EXACT_MATCH_Exact = 0,
     189             :     GAME_EXACT_MATCH_Pawns,
     190             :     GAME_EXACT_MATCH_Fyles,
     191             :     GAME_EXACT_MATCH_Material
     192             : };
     193             : 
     194             : enum gameFormatT {
     195             :     PGN_FORMAT_Plain = 0,   // Plain regular PGN output
     196             :     PGN_FORMAT_HTML = 1,    // HTML format
     197             :     PGN_FORMAT_LaTeX = 2,   // LaTeX (with chess12 package) format
     198             :     PGN_FORMAT_Color = 3    // PGN, with color tags <red> etc
     199             : };
     200             : 
     201             : #define PGN_STYLE_TAGS             1
     202             : #define PGN_STYLE_COMMENTS         2
     203             : #define PGN_STYLE_VARS             4
     204             : #define PGN_STYLE_INDENT_COMMENTS  8
     205             : #define PGN_STYLE_INDENT_VARS     16
     206             : #define PGN_STYLE_SYMBOLS         32   // e.g. "! +-" instead of "$2 $14"
     207             : #define PGN_STYLE_SHORT_HEADER    64
     208             : #define PGN_STYLE_MOVENUM_SPACE  128   // Space after move numbers.
     209             : #define PGN_STYLE_COLUMN         256   // Column style: one move per line.
     210             : #define PGN_STYLE_SCIDFLAGS      512
     211             : #define PGN_STYLE_STRIP_MARKS   1024   // Strip [%mark] and [%arrow] codes.
     212             : #define PGN_STYLE_NO_NULL_MOVES 2048   // Convert null moves to comments.
     213             : #define PGN_STYLE_UNICODE       4096   // Use U+2654..U+2659 for figurine
     214             : 
     215             : 
     216             : void  game_printNag (byte nag, char * str, bool asSymbol, gameFormatT format);
     217             : byte  game_parseNag (const char * str);
     218             : 
     219             : uint strGetRatingType (const char * name);
     220             : 
     221             : 
     222             : //////////////////////////////////////////////////////////////////////
     223             : //  Game:  Class Definition
     224             : 
     225           6 : static Position staticPosition;
     226             : 
     227             : class Game
     228             : {
     229             : private:
     230             :     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     231             :     //  Game:  Data structures
     232             : 
     233             :     bool        NonStandardStart;      // 1 if non-standard start.
     234             :     colorT      ToMove;         // side to move in starting position
     235             :     ushort      NumHalfMoves;
     236             :     ushort      CurrentPlyCount;
     237             :     ushort      StartPlyCount;
     238             :     bool        KeepDecodedMoves;
     239             : 
     240             :     Game *      NextGame;     // For keeping a linked list of games.
     241             :     bool        Altered;
     242             : 
     243             :     matSigT     FinalMatSig;
     244             : 
     245             :     bool        PromotionsFlag;   // True if game has a promotion.
     246             :     bool        UnderPromosFlag;  // True if game has a promotion to R/B/N.
     247             :     char        ScidFlags [20];
     248             : 
     249             :     moveChunkT * MoveChunk;
     250             :     moveT *     FreeList;
     251             : 
     252             :     std::string EventStr;
     253             :     std::string SiteStr;
     254             :     std::string WhiteStr;
     255             :     std::string BlackStr;
     256             :     std::string RoundStr;
     257             :     dateT       Date;
     258             :     dateT       EventDate;
     259             :     resultT     Result;
     260             :     ecoT        EcoCode;
     261             :     eloT        WhiteElo;
     262             :     eloT        BlackElo;
     263             :     byte        WhiteRatingType;
     264             :     byte        BlackRatingType;
     265             :     eloT        WhiteEstimateElo;
     266             :     eloT        BlackEstimateElo;
     267             : 
     268             :     Position *  StartPos;
     269             :     Position *  CurrentPos;
     270             : 
     271             :     moveT *     FirstMove;
     272             :     moveT *     CurrentMove;
     273             :     uint        VarDepth;     // Current variation depth.
     274             : 
     275             :     // For saving and restoring game state:
     276             :     Position *  SavedPos;
     277             :     moveT *     SavedMove;
     278             :     ushort      SavedPlyCount;
     279             :     uint        SavedVarDepth;
     280             : 
     281             :     const NameBase* NBase;      // needed for referencing id numbers.
     282             : 
     283             :     tagT        TagList [       MAX_TAGS];
     284             :     uint        NumTags;
     285             : 
     286             :     uint        NumMovesPrinted; // Used in recursive WriteMoveList method.
     287             :     uint        StopLocation;    // Used in recursive WriteMoveList method.
     288             : 
     289             :     uint        PgnStyle;        // see PGN_STYLE macros above.
     290             :     gameFormatT PgnFormat;       // see PGN_FORMAT macros above.
     291             :     uint        HtmlStyle;       // HTML diagram style, see
     292             :                                  //   DumpHtmlBoard method in position.cpp.
     293             :     uint        PgnLastMovePos;
     294             : 
     295             :     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     296             :     //  Game:  Private Functions
     297             :     Game(const Game&);
     298             :     Game& operator=(const Game&);
     299             : 
     300             :     void       AllocateMoreMoves ();
     301             :     inline moveT *    NewMove();
     302             :     inline void       FreeMove (moveT * move);
     303             : 
     304             :     errorT     DecodeVariation (ByteBuffer * buf, byte flags, uint level);
     305             :     bool       calcAbsPlyNumber_ (moveT *m, moveT *s);
     306             : 
     307             :     static void encodeMove (ByteBuffer * buf, moveT * m);
     308             :     static errorT encodeVariation (ByteBuffer * buf, moveT * m, 
     309             :                                    uint * subVarCount, uint * nagCount, uint depth);
     310             :     static errorT encodeComments (ByteBuffer * buf, moveT * m, uint * commentCounter);
     311             :     static errorT decodeComments (ByteBuffer * buf, moveT * m);
     312             : 
     313             : public:
     314       12228 :     Game()      { Init(); }
     315             :     ~Game();
     316             : 
     317             :     void        Clear();
     318             :     void        ClearMoves();
     319             : 
     320             :     void        Init();
     321             : 
     322             :     // Set and Get attributes -- one-line (inline) methods
     323             :     void        SetNumHalfMoves (ushort x)  { NumHalfMoves = x; }
     324             :     ushort      GetNumHalfMoves ()          { return NumHalfMoves; }
     325             :     ushort      GetCurrentPly()             { return CurrentPlyCount; }
     326             : 
     327             :     void        SetNextGame (Game * g)      { NextGame = g; }
     328             :     Game *      GetNextGame ()              { return NextGame; }
     329             :     void        SetAltered (bool b)         { Altered = b; }
     330             :     bool        GetAltered (void)           { return Altered; }
     331             :     
     332             :     bool        HasNonStandardStart ()      { return NonStandardStart; }
     333             : //    byte        GetNagsFlag ()              { return NagsFlag; }
     334             : //    byte        GetVarsFlag ()              { return VarsFlag; }
     335             : //    byte        GetCommentsFlag ()          { return CommentsFlag; }
     336             :     bool        HasPromotions ()            { return PromotionsFlag; }
     337             :     bool        HasUnderPromotions ()       { return UnderPromosFlag; }
     338             : 
     339             :     void        SetStartPos (Position * pos);
     340             :     errorT      SetStartFen (const char * fenStr);
     341             : 
     342             :     void SetScidFlags(const char* s) {
     343           0 :         strncpy(ScidFlags, s, sizeof(ScidFlags) - 1);
     344           0 :         ScidFlags[sizeof(ScidFlags) - 1] = 0;
     345             :     }
     346             : 
     347             :     Position *  GetStartPos ()              { return StartPos; }
     348             :     Position *  GetCurrentPos ()            { return CurrentPos; }
     349             : 
     350             :     simpleMoveT * GetCurrentMove () {
     351             :         moveT * m = CurrentMove;
     352             :         if (m->marker == START_MARKER  ||  m->marker == END_MARKER) {
     353             :             return NULL;
     354             :         }
     355             :         return &(m->moveData);
     356             :     }
     357             : 
     358             :     inline void InitMove (moveT * m);
     359             : 
     360             :     void     SaveState ();
     361             :     errorT   RestoreState();
     362             : 
     363             :     void     SetMoveData (moveT * m, simpleMoveT * sm);
     364             :     errorT   AddMove (simpleMoveT * sm, char * san);
     365             :     errorT   AddVariation ();
     366             :     errorT   DeleteSubVariation (moveT * m);
     367             :     errorT   DeleteVariation (uint varNumber);
     368             :     errorT   DeleteVariationAndFree (uint varNumber);
     369             :     errorT   FirstVariation (uint varNumber);
     370             :     errorT   MainVariation ();
     371             :     uint     GetVarNumber();
     372             : 
     373             :     void     SetMoveComment (const char * comment);
     374        2248 :     const char* GetMoveComment () { return CurrentMove->prev->comment.c_str(); }
     375             :     /**
     376             :      * Game::GetPreviousMoveComment()
     377             :      * Return the comment on the move previously played by CurrentPos->ToMove
     378             :      * If there are no previous moves, return an empty comment.
     379             :      */
     380             :     const char* GetPreviousMoveComment() {
     381             :         ASSERT(CurrentMove != NULL);
     382             :         moveT* m = CurrentMove->prev;
     383             :         if (m == NULL || m->prev == NULL) return "";
     384             :         moveT* mp = m->prev->varParent;
     385             :         if (mp != NULL && mp->prev != NULL) m = mp;
     386             :         return m->prev->comment.c_str();
     387             :     }
     388             : 
     389             :     inline errorT AddNag (byte nag);
     390             :     inline errorT RemoveNag (bool isMoveNag);
     391        1124 :     byte *   GetNags () { return CurrentMove->prev->nags; }
     392             :     byte *   GetNextNags () { return CurrentMove->nags; }
     393             :     void     ClearNags () {
     394             :         CurrentMove->prev->nagCount = 0;
     395             :         CurrentMove->prev->nags[0] = 0;
     396             :     }
     397             : 
     398             :     void     MoveTo (const std::vector<int>& v);
     399             :     void     MoveToPly (ushort hmNumber);
     400             :     errorT   MoveForward ();
     401             :     errorT   MoveBackup ();
     402             :     errorT   MoveIntoVariation (uint varNumber);
     403             :     errorT   MoveExitVariation ();
     404             : 
     405             :     bool     AtStart ()
     406             :                  { return (CurrentMove->prev->marker == START_MARKER  &&
     407             :                            VarDepth == 0); }
     408             :     bool     AtEnd ()
     409             :                  { return (CurrentMove->marker == END_MARKER  &&
     410             :                            VarDepth == 0); }
     411             :     bool     AtVarStart ()
     412             :                  { return (CurrentMove->prev->marker == START_MARKER); }
     413             :     bool     AtVarEnd ()
     414             :                  { return (CurrentMove->marker == END_MARKER); }
     415             :     uint     GetVarLevel () { return VarDepth; }
     416             :     uint      GetNumVariations ()
     417        1270 :                  { return (uint) CurrentMove->numVariations; }
     418             : 
     419             :     void     Truncate ();
     420             :     void     TruncateAndFree ();
     421             : 
     422             :     void     TruncateStart ();
     423             : 
     424        4000 :     void     SetEventStr (const char * str) { EventStr = str; }
     425        4000 :     void     SetSiteStr  (const char * str) { SiteStr  = str; }
     426        4000 :     void     SetWhiteStr (const char * str) { WhiteStr = str; }
     427        4000 :     void     SetBlackStr (const char * str) { BlackStr = str; }
     428        4000 :     void     SetRoundStr (const char * str) { RoundStr = str; }
     429        3000 :     void     SetDate (dateT date)    { Date = date; }
     430        1000 :     void     SetEventDate (dateT date)  { EventDate = date; }
     431        1000 :     void     SetResult (resultT res) { Result = res; }
     432        1000 :     void     SetWhiteElo (eloT elo)  { WhiteElo = elo; }
     433        1000 :     void     SetBlackElo (eloT elo)  { BlackElo = elo; }
     434             :     void     SetWhiteEstimateElo (eloT elo)  { WhiteEstimateElo = elo; }
     435             :     void     SetBlackEstimateElo (eloT elo)  { BlackEstimateElo = elo; }
     436        1000 :     void     SetWhiteRatingType (byte b) { WhiteRatingType = b; }
     437        1000 :     void     SetBlackRatingType (byte b) { BlackRatingType = b; }
     438        1000 :     void     SetEco (ecoT eco)       { EcoCode = eco; }
     439       26018 :     const char* GetEventStr ()       { return EventStr.c_str(); }
     440       26018 :     const char* GetSiteStr ()        { return SiteStr.c_str();  }
     441       26018 :     const char* GetWhiteStr ()       { return WhiteStr.c_str(); }
     442       26018 :     const char* GetBlackStr ()       { return BlackStr.c_str(); }
     443       26018 :     const char* GetRoundStr ()       { return RoundStr.c_str(); }
     444             :     dateT    GetDate ()              { return Date; }
     445             :     dateT    GetEventDate ()         { return EventDate; }
     446             :     resultT  GetResult ()            { return Result; }
     447             :     eloT     GetWhiteElo ()          { return WhiteElo; }
     448             :     eloT     GetBlackElo ()          { return BlackElo; }
     449             :     eloT     GetWhiteEstimateElo()   { return WhiteEstimateElo; }
     450             :     eloT     GetBlackEstimateElo()   { return BlackEstimateElo; }
     451             :     byte     GetWhiteRatingType ()   { return WhiteRatingType; }
     452             :     byte     GetBlackRatingType ()   { return BlackRatingType; }
     453             :     ecoT     GetEco ()               { return EcoCode; }
     454             :     eloT     GetAverageElo ();
     455             : 
     456             :     // Adding/Removing Extra  tags:
     457             :     void     AddPgnTag (const char * tag, const char * value);
     458             :     bool     RemoveExtraTag (const char * tag);
     459             :     const char * FindExtraTag (const char * tag);
     460             :     uint     GetNumExtraTags ()      { return NumTags; }
     461             :     tagT *   GetExtraTags ()         { return TagList; }
     462             :     void     ClearExtraTags ();
     463             : 
     464             :     void     MakeHomePawnList (byte * pbPawnList);
     465             : 
     466             :     // Searching
     467             :     compareT CompareCurrentPos (Position * p);
     468             : 
     469             :     void      CopyStandardTags (Game * fromGame);
     470             :     errorT    LoadStandardTags (const IndexEntry* ie, const NameBase* nb);
     471             :     void      ClearStandardTags ();
     472             : 
     473             :     // PGN conversion
     474             :     void      GetSAN (char * str);
     475             :     void      GetPrevSAN (char * str);
     476             :     void      GetPrevMoveUCI (char * str);
     477             :     void      GetNextMoveUCI (char * str);
     478             : 
     479             :     bool      CommentEmpty ( const char * comment);
     480             :     void      WriteComment (TextBuffer * tb, const char * preStr,
     481             :                             const char * comment, const char * postStr);
     482             :     errorT    WriteMoveList (TextBuffer * tb, uint plyCount,
     483             :                              moveT * oldCurrentMove,
     484             :                              bool printMoveNum, bool inComment);
     485             :     errorT    WritePGN (TextBuffer * tb, uint stopLocation);
     486             :     std::pair<const char*, unsigned> WriteToPGN (uint lineWidth = 0,
     487             :                                                  bool NewLineAtEnd = false,
     488             :                                                  bool newLineToSpaces = true);
     489             :     errorT    MoveToLocationInPGN (uint stopLocation);
     490             :     errorT    WriteExtraTags (FILE * fp);
     491             : 
     492             :     uint      GetPgnOffset () {
     493             :                   PgnLastMovePos = 0;
     494             :                   moveT* lastMove = CurrentMove->prev;
     495             :                   if (AtVarStart()) {
     496             :                       lastMove = lastMove->varParent;
     497             :                       if (lastMove != 0) lastMove = lastMove->prev;
     498             :                   }
     499             :                   if (!calcAbsPlyNumber_(FirstMove, lastMove)) return 1;
     500             :                   return PgnLastMovePos;
     501             :               }
     502             : 
     503             :     void      ResetPgnStyle (void) { PgnStyle = 0; }
     504        2000 :     void      ResetPgnStyle (uint flag) { PgnStyle = flag; }
     505             : 
     506             :     uint      GetPgnStyle () { return PgnStyle; }
     507             :     void      SetPgnStyle (uint mask, bool setting) {
     508           0 :         if (setting) { AddPgnStyle (mask); } else { RemovePgnStyle (mask); }
     509             :     }
     510           0 :     void      AddPgnStyle (uint mask) { PgnStyle |= mask; }
     511           0 :     void      RemovePgnStyle (uint mask) { PgnStyle &= ~mask; }
     512             : 
     513        2000 :     void      SetPgnFormat (gameFormatT gf) { PgnFormat = gf; }
     514             :     bool      SetPgnFormatFromString (const char * str);
     515             :     static bool PgnFormatFromString (const char * str, gameFormatT * fmt);
     516             :     bool      IsPlainFormat () { return (PgnFormat == PGN_FORMAT_Plain); }
     517             :     bool      IsHtmlFormat  () { return (PgnFormat == PGN_FORMAT_HTML); }
     518             :     bool      IsLatexFormat () { return (PgnFormat == PGN_FORMAT_LaTeX); }
     519             :     bool      IsColorFormat () { return (PgnFormat == PGN_FORMAT_Color); }
     520             : 
     521             :     void      SetHtmlStyle (uint style) { HtmlStyle = style; }
     522             :     uint      GetHtmlStyle () { return HtmlStyle; }
     523             : 
     524             :     errorT    GetPartialMoveList (DString * str, uint plyCount);
     525             :     bool      MoveMatch (int m_argc, char ** m_argv, uint plyCount, bool wToMove, bool bToMove, int checkTest);
     526             : 
     527             :     errorT    Encode (ByteBuffer * buf, IndexEntry * ie);
     528             :     void      EncodeTags (ByteBuffer * buf);
     529             : 
     530             :     bool      MaterialMatch (ByteBuffer * buf, byte * min, byte * max,
     531             :                              patternT * pattern, int minPly, int maxPly,
     532             :                              int matchLength,
     533             :                              bool oppBishops, bool sameBishops,
     534             :                              int minDiff, int maxDiff);
     535             :     bool      ExactMatch (Position * pos, ByteBuffer * buf, simpleMoveT * sm,
     536             :                           gameExactMatchT searchType, bool * neverMatch);
     537             :     bool      VarExactMatch (Position * searchPos, gameExactMatchT searchType);
     538             :     inline bool ExactMatch (Position * pos, ByteBuffer * buf, simpleMoveT * sm)
     539             :       { return ExactMatch (pos, buf, sm, GAME_EXACT_MATCH_Exact, NULL); }
     540             :     inline bool ExactMatch (Position * pos, ByteBuffer * buf, simpleMoveT * sm,
     541             :                             bool * neverMatch)
     542             :       { return ExactMatch (pos, buf, sm, GAME_EXACT_MATCH_Exact, neverMatch); }
     543             :     inline bool ExactMatch (Position * pos, ByteBuffer * buf, simpleMoveT * sm,
     544             :                             gameExactMatchT searchType)
     545             :       { return ExactMatch (pos, buf, sm, searchType, NULL); }
     546             : 
     547             :     errorT    DecodeStart (ByteBuffer * buf);
     548             :     errorT    DecodeNextMove (ByteBuffer * buf, simpleMoveT * sm);
     549             :     errorT    Decode (ByteBuffer * buf, byte flags);
     550             :     errorT    DecodeTags (ByteBuffer * buf, bool storeTags);
     551             : 
     552             :     std::vector<int> GetCurrentLocation();
     553             :     Game* clone();
     554             : };
     555             : 
     556             : 
     557             : inline void
     558     4360793 : Game::InitMove (moveT * m)
     559             : {
     560     4360793 :     ASSERT(m != NULL);
     561     4360793 :     m->prev = m->next = m->varParent = m->varChild = NULL;
     562     4360793 :     m->numVariations = 0;
     563             :     //m->varLevel = 0;
     564     8721586 :     m->comment.clear();
     565     4360793 :     m->nagCount = 0;
     566     4360793 :     m->nags[0] = 0;
     567     4360793 :     m->marker = NO_MARKER;
     568     4360793 :     m->san[0] = 0;
     569     4360793 : }
     570             : 
     571             : inline errorT
     572         320 : Game::AddNag (byte nag)
     573             : {
     574         320 :     moveT * m = CurrentMove->prev;
     575         320 :     if (m->nagCount + 1 >= MAX_NAGS) { return ERROR_GameFull; }
     576         320 :     if (nag == 0) { /* Nags cannot be zero! */ return OK; }
     577             :         // If it is a move nag replace an existing
     578         320 :         if( nag >= 1 && nag <= 6)
     579         290 :                 for( int i=0; i<m->nagCount; i++)
     580           0 :                         if( m->nags[i] >= 1 && m->nags[i] <= 6)
     581             :                         {
     582           0 :                                 m->nags[i] = nag;
     583           0 :                                 return OK;
     584             :                         }
     585             :         // If it is a position nag replace an existing
     586         320 :         if( nag >= 10 && nag <= 21)
     587          50 :                 for( int i=0; i<m->nagCount; i++)
     588          10 :                         if( m->nags[i] >= 10 && m->nags[i] <= 21)
     589             :                         {
     590           0 :                                 m->nags[i] = nag;
     591           0 :                                 return OK;
     592             :                         }
     593         320 :         if( nag >= 1 && nag <= 6)
     594             :         {
     595             :                 // Put Move Nags at the beginning
     596         290 :                 for( int i=m->nagCount; i>0; i--)  m->nags[i] =  m->nags[i-1];
     597         290 :                 m->nags[0] = nag;
     598             :         }
     599             :         else
     600          30 :                 m->nags[m->nagCount] = nag;
     601         320 :         m->nagCount += 1;
     602         320 :         m->nags[m->nagCount] = 0;
     603         320 :     return OK;
     604             : }
     605             : 
     606             : inline errorT
     607             : Game::RemoveNag (bool isMoveNag)
     608             : {
     609             :     moveT * m = CurrentMove->prev;
     610             :         if( isMoveNag)
     611             :         {
     612             :                 for( int i=0; i<m->nagCount; i++)
     613             :                         if( m->nags[i] >= 1 && m->nags[i] <= 6)
     614             :                         {
     615             :                                 m->nagCount -= 1;
     616             :                                 for( int j=i; j<m->nagCount; j++)  m->nags[j] =  m->nags[j+1];
     617             :                                 m->nags[m->nagCount] = 0;
     618             :                                 return OK;
     619             :                         }
     620             :         }
     621             :         else
     622             :         {
     623             :                 for( int i=0; i<m->nagCount; i++)
     624             :                         if( m->nags[i] >= 10 && m->nags[i] <= 21)
     625             :                         {
     626             :                                 m->nagCount -= 1;
     627             :                                 for( int j=i; j<m->nagCount; j++)  m->nags[j] =  m->nags[j+1];
     628             :                                 m->nags[m->nagCount] = 0;
     629             :                                 return OK;
     630             :                         }
     631             :         }
     632             :     return OK;
     633             : }
     634             : 
     635             : #endif  // #ifndef SCID_GAME_H
     636             : 
     637             : //////////////////////////////////////////////////////////////////////
     638             : //  EOF:    game.h
     639             : //////////////////////////////////////////////////////////////////////

Generated by: LCOV version 1.12