Exemplo n.º 1
0
 /// <summary>
 /// Class Ctor
 /// </summary>
 public frmPgnGamePicker()
 {
     InitializeComponent();
     m_pgnUtil          = new PgnUtil();
     SelectedGame       = null;
     StartingColor      = ChessBoard.PlayerColorE.White;
     StartingChessBoard = null;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Class Ctor
 /// </summary>
 public frmPgnGamePicker()
 {
     InitializeComponent();
     m_pgnUtil          = new PgnUtil();
     m_pgnParser        = new PgnParser(false /*bDiagnose*/);
     SelectedGame       = null;
     StartingColor      = ChessBoard.PlayerE.White;
     StartingChessBoard = null;
     m_pgnGames         = new List <PgnGame>(65536);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Redisplay all the moves using the current setting
        /// </summary>
        private void Redisplay()
        {
            string[]     arrMoveName;
            int          iMoveCount;
            MovePosStack movePosStack;
            MoveExt      move;
            string       strMove;
            string       strMoveIndex;
            MoveItem     moveItem;
            ChessBoard   chessBoard;

            chessBoard = m_chessCtl.Board;
            if (chessBoard != null)
            {
                movePosStack = chessBoard.MovePosStack;
                iMoveCount   = movePosStack.Count;
                if (iMoveCount != 0)
                {
                    if (m_eDisplayMode == DisplayModeE.MovePos)
                    {
                        arrMoveName = null;
                    }
                    else
                    {
                        arrMoveName = PgnUtil.GetPGNArrayFromMoveList(chessBoard);
                    }
                    for (int iIndex = 0; iIndex < iMoveCount; iIndex++)
                    {
                        move = movePosStack[iIndex];
                        if (m_eDisplayMode == DisplayModeE.MovePos)
                        {
                            strMove      = ChessBoard.GetHumanPos(move);
                            strMoveIndex = (iIndex + 1).ToString();
                        }
                        else
                        {
                            strMove      = arrMoveName[iIndex];
                            strMoveIndex = (iIndex / 2 + 1).ToString() + ((Char)('a' + (iIndex & 1))).ToString();
                        }
                        moveItem         = MoveList[iIndex];
                        MoveList[iIndex] = new MoveItem(strMoveIndex, moveItem.Who, strMove);
                    }
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="pgnParser">        PGN parser</param>
        /// <param name="pgnUtil">          PGN utility class</param>
        /// <param name="pgnGames">         Raw games</param>
        /// <param name="iMinELO">          Minimum ELO in the PGN file</param>
        /// <param name="iMaxELO">          Maximum ELO in the PGN file</param>
        /// <param name="arrPlayers">       List of players found in the PGN file</param>
        /// <param name="strInpFileName">   Name of the input file.</param>
        public frmPgnFilter(PgnParser pgnParser, PgnUtil pgnUtil, List <PgnGame> pgnGames, int iMinELO, int iMaxELO, string[] arrPlayers, string strInpFileName) : this()
        {
            CheckBox checkBox;

            m_pgnParser = pgnParser;
            m_pgnUtil   = pgnUtil;
            m_pgnGames  = pgnGames;
            iMinELO     = iMinELO / 100 * 100;
            listBoxRange.Items.Clear();
            for (int iIndex = iMinELO; iIndex < iMaxELO; iIndex += 100)
            {
                checkBox           = new CheckBox();
                checkBox.Content   = new RangeItem(iIndex);
                checkBox.IsChecked = true;
                listBoxRange.Items.Add(checkBox);
            }
            listBoxPlayer.Items.Clear();
            foreach (string strPlayer in arrPlayers)
            {
                checkBox           = new CheckBox();
                checkBox.Content   = strPlayer;
                checkBox.IsChecked = true;
                listBoxPlayer.Items.Add(checkBox);
            }
            listBoxEnding.Items.Clear();
            checkBox           = new CheckBox();
            checkBox.Content   = "White Win";
            checkBox.IsChecked = true;
            listBoxEnding.Items.Add(checkBox);
            checkBox           = new CheckBox();
            checkBox.Content   = "Black Win";
            checkBox.IsChecked = true;
            listBoxEnding.Items.Add(checkBox);
            checkBox           = new CheckBox();
            checkBox.Content   = "Draws";
            checkBox.IsChecked = true;
            listBoxEnding.Items.Add(checkBox);
            checkBoxAllRanges.IsChecked  = true;
            checkBoxAllPlayer.IsChecked  = true;
            checkBoxAllEndGame.IsChecked = true;
            listBoxPlayer.IsEnabled      = false;
            listBoxRange.IsEnabled       = false;
            listBoxEnding.IsEnabled      = false;
            labelDesc.Content            = pgnGames.Count.ToString() + " games found in the file '" + strInpFileName + "'";
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the description of a move
        /// </summary>
        /// <param name="movePos">  Move to describe</param>
        /// <returns>
        /// Move description
        /// </returns>
        private string GetMoveDesc(ChessBoard.MovePosS movePos)
        {
            string strRetVal;

            if (m_eDisplayMode == DisplayModeE.MovePos)
            {
                strRetVal = ChessBoard.GetHumanPos(movePos);
            }
            else
            {
                strRetVal = PgnUtil.GetPGNMoveFromMove(m_chessBoard, movePos, false);
                if ((movePos.Type & ChessBoard.MoveTypeE.MoveFromBook) == ChessBoard.MoveTypeE.MoveFromBook)
                {
                    strRetVal = "(" + strRetVal + ")";
                }
            }
            return(strRetVal);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize the form with the content of the PGN file
        /// </summary>
        /// <param name="strFileName">  PGN file name</param>
        /// <returns>
        /// true if at least one game has been found.
        /// </returns>
        public bool InitForm(string strFileName)
        {
            bool bRetVal;

            m_streamInp = PgnUtil.OpenInpFile(strFileName);
            if (m_streamInp == null)
            {
                bRetVal = false;
            }
            else
            {
                if (m_pgnUtil.FillListBoxWithDesc(m_streamInp, listBoxGames) < 1)
                {
                    MessageBox.Show("No games found in the PGN File '" + strFileName + "'");
                    bRetVal = false;
                }
                else
                {
                    listBoxGames.SelectedIndex = 0;
                    bRetVal = true;
                }
            }
            return(bRetVal);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Parse FEN definition into a board representation
        /// </summary>
        /// <param name="strFEN">           FEN</param>
        /// <param name="eColorToMove">     Return the color to move</param>
        /// <param name="eBoardStateMask">  Return the mask of castling info</param>
        /// <param name="iEnPassant">       Return the en passant position or 0 if none</param>
        /// <returns>
        /// true if succeed, false if failed
        /// </returns>
        private bool ParseFEN(string strFEN, out ChessBoard.PlayerColorE eColorToMove, out ChessBoard.BoardStateMaskE eBoardStateMask, out int iEnPassant)
        {
            bool bRetVal = true;

            string[] arrCmd;
            string[] arrRow;
            string   strCmd;
            int      iPos;
            int      iLinePos;
            int      iBlankCount;

            ChessBoard.PieceE ePiece;

            eBoardStateMask = (ChessBoard.BoardStateMaskE) 0;
            iEnPassant      = 0;
            eColorToMove    = ChessBoard.PlayerColorE.White;
            arrCmd          = strFEN.Split(' ');
            if (arrCmd.Length != 6)
            {
                bRetVal = false;
            }
            else
            {
                arrRow = arrCmd[0].Split('/');
                if (arrRow.Length != 8)
                {
                    bRetVal = false;
                }
                else
                {
                    iPos = 63;
                    foreach (string strRow in arrRow)
                    {
                        iLinePos = 0;
                        foreach (char cChr in strRow)
                        {
                            ePiece = ChessBoard.PieceE.None;
                            switch (cChr)
                            {
                            case 'P':
                                ePiece = ChessBoard.PieceE.Pawn | ChessBoard.PieceE.White;
                                break;

                            case 'N':
                                ePiece = ChessBoard.PieceE.Knight | ChessBoard.PieceE.White;
                                break;

                            case 'B':
                                ePiece = ChessBoard.PieceE.Bishop | ChessBoard.PieceE.White;
                                break;

                            case 'R':
                                ePiece = ChessBoard.PieceE.Rook | ChessBoard.PieceE.White;
                                break;

                            case 'Q':
                                ePiece = ChessBoard.PieceE.Queen | ChessBoard.PieceE.White;
                                break;

                            case 'K':
                                ePiece = ChessBoard.PieceE.King | ChessBoard.PieceE.White;
                                break;

                            case 'p':
                                ePiece = ChessBoard.PieceE.Pawn | ChessBoard.PieceE.Black;
                                break;

                            case 'n':
                                ePiece = ChessBoard.PieceE.Knight | ChessBoard.PieceE.Black;
                                break;

                            case 'b':
                                ePiece = ChessBoard.PieceE.Bishop | ChessBoard.PieceE.Black;
                                break;

                            case 'r':
                                ePiece = ChessBoard.PieceE.Rook | ChessBoard.PieceE.Black;
                                break;

                            case 'q':
                                ePiece = ChessBoard.PieceE.Queen | ChessBoard.PieceE.Black;
                                break;

                            case 'k':
                                ePiece = ChessBoard.PieceE.King | ChessBoard.PieceE.Black;
                                break;

                            default:
                                if (cChr >= '1' && cChr <= '8')
                                {
                                    iBlankCount = Int32.Parse(cChr.ToString());
                                    if (iBlankCount + iLinePos <= 8)
                                    {
                                        for (int iIndex = 0; iIndex < iBlankCount; iIndex++)
                                        {
                                            m_chessBoard[iPos--] = ChessBoard.PieceE.None;
                                        }
                                        iLinePos += iBlankCount;
                                    }
                                }
                                else
                                {
                                    bRetVal = false;
                                }
                                break;
                            }
                            if (bRetVal && ePiece != ChessBoard.PieceE.None)
                            {
                                if (iLinePos < 8)
                                {
                                    m_chessBoard[iPos--] = ePiece;
                                    iLinePos++;
                                }
                                else
                                {
                                    bRetVal = false;
                                }
                            }
                        }
                        if (iLinePos != 8)
                        {
                            bRetVal = false;
                        }
                    }
                    if (bRetVal)
                    {
                        strCmd = arrCmd[1];
                        if (strCmd == "w")
                        {
                            eColorToMove = ChessBoard.PlayerColorE.White;
                        }
                        else if (strCmd == "b")
                        {
                            eColorToMove = ChessBoard.PlayerColorE.Black;
                        }
                        else
                        {
                            bRetVal = false;
                        }
                        strCmd = arrCmd[2];
                        if (strCmd != "-")
                        {
                            for (int iIndex = 0; iIndex < strCmd.Length; iIndex++)
                            {
                                switch (strCmd[iIndex])
                                {
                                case 'K':
                                    eBoardStateMask |= ChessBoard.BoardStateMaskE.WRCastling;
                                    break;

                                case 'Q':
                                    eBoardStateMask |= ChessBoard.BoardStateMaskE.WLCastling;
                                    break;

                                case 'k':
                                    eBoardStateMask |= ChessBoard.BoardStateMaskE.BRCastling;
                                    break;

                                case 'q':
                                    eBoardStateMask |= ChessBoard.BoardStateMaskE.BLCastling;
                                    break;
                                }
                            }
                        }
                        strCmd = arrCmd[3];
                        if (strCmd == "-")
                        {
                            iEnPassant = 0;
                        }
                        else
                        {
                            iEnPassant = PgnUtil.GetSquareIDFromPGN(strCmd);
                            if (iEnPassant == -1)
                            {
                                iEnPassant = 0;
                            }
                        }
                    }
                }
            }
            return(bRetVal);
        }