/// <summary> /// Checks if the specified game must be retained accordingly to the specified filter /// </summary> /// <param name="rawGame"> PGN Raw game</param> /// <param name="iAvgELO"> Game average ELO</param> /// <param name="filterClause"> Filter clause</param> /// <returns> /// true if must be retained /// </returns> private bool IsRetained(PgnGame rawGame, int iAvgELO, FilterClause filterClause) { bool bRetVal = true; string strGameResult; string strGameDate; if (iAvgELO == -1) { bRetVal = filterClause.m_bIncludesUnrated; } else if (filterClause.m_bAllRanges) { bRetVal = true; } else { iAvgELO = iAvgELO / 100 * 100; bRetVal = filterClause.m_hashRanges.ContainsKey(iAvgELO); } if (bRetVal) { if (!filterClause.m_bAllPlayers || !filterClause.m_bAllEnding) { GetPGNGameInfo(rawGame, out strGameResult, out strGameDate); if (!filterClause.m_bAllPlayers) { if (!filterClause.m_hashPlayerList.ContainsKey(rawGame.BlackPlayer) && !filterClause.m_hashPlayerList.ContainsKey(rawGame.WhitePlayer)) { bRetVal = false; } } if (bRetVal && !filterClause.m_bAllEnding) { if (strGameResult == "1-0") { bRetVal = filterClause.m_bEndingWhiteWinning; } else if (strGameResult == "0-1") { bRetVal = filterClause.m_bEndingBlackWinning; } else if (strGameResult == "1/2-1/2") { bRetVal = filterClause.m_bEndingDraws; } else { bRetVal = false; } } } } return(bRetVal); }
/// <summary> /// Gets the information about a PGN game /// </summary> /// <param name="rawGame"> Raw PGN game</param> /// <param name="strGameResult"> Result of the game</param> /// <param name="strGameDate"> Date of the game</param> private static void GetPGNGameInfo(PgnGame rawGame, out string strGameResult, out string strGameDate) { if (!rawGame.attrs.TryGetValue("Result", out strGameResult)) { strGameResult = null; } if (!rawGame.attrs.TryGetValue("Date", out strGameDate)) { strGameDate = null; } }
/// <summary> /// Write a PGN game in the specified output stream /// </summary> /// <param name="pgnBuffer"> PGN buffer</param> /// <param name="writer"> Text writer</param> /// <param name="pgnGame"> PGN game</param> private void WritePGN(PgnLexical pgnBuffer, TextWriter writer, PgnGame pgnGame) { writer.Write(pgnBuffer.GetStringAtPos(pgnGame.StartingPos, pgnGame.Length)); }