/// <summary>
 /// Create a new game using the specified list of moves
 /// </summary>
 /// <param name="chessBoardStarting">   Starting board or null if standard board</param>
 /// <param name="listMove">             List of moves</param>
 /// <param name="eNextMoveColor">       Color starting to play</param>
 /// <param name="strWhitePlayerName">   Name of the player playing white pieces</param>
 /// <param name="strBlackPlayerName">   Name of the player playing black pieces</param>
 /// <param name="eWhitePlayerType">     Type of player playing white pieces</param>
 /// <param name="eBlackPlayerType">     Type of player playing black pieces</param>
 /// <param name="spanPlayerWhite">      Timer for white</param>
 /// <param name="spanPlayerBlack">      Timer for black</param>
 public override void CreateGameFromMove(ChessBoard                  chessBoardStarting,
     List<ChessBoard.MovePosS>   listMove,
     ChessBoard.PlayerColorE     eNextMoveColor,
     string                      strWhitePlayerName,
     string                      strBlackPlayerName,
     PgnParser.PlayerTypeE       eWhitePlayerType,
     PgnParser.PlayerTypeE       eBlackPlayerType,
     TimeSpan                    spanPlayerWhite,
     TimeSpan                    spanPlayerBlack)
 {
     base.CreateGameFromMove(chessBoardStarting,
                             listMove,
                             eNextMoveColor,
                             strWhitePlayerName,
                             strBlackPlayerName,
                             eWhitePlayerType,
                             eBlackPlayerType,
                             spanPlayerWhite,
                             spanPlayerBlack);
     if (eWhitePlayerType == PgnParser.PlayerTypeE.Program) {
         if (eBlackPlayerType == PgnParser.PlayerTypeE.Program) {
             Father.PlayingMode              = MainWindow.PlayingModeE.ComputerAgainstComputer;
         } else {
             Father.PlayingMode              = MainWindow.PlayingModeE.PlayerAgainstComputer;
             Father.m_eComputerPlayingColor  = ChessBoard.PlayerColorE.White;
         }
     } else if (eBlackPlayerType == PgnParser.PlayerTypeE.Program) {
         Father.PlayingMode              = MainWindow.PlayingModeE.PlayerAgainstComputer;
         Father.m_eComputerPlayingColor  = ChessBoard.PlayerColorE.Black;
     } else {
         Father.PlayingMode = MainWindow.PlayingModeE.PlayerAgainstPlayer;
     }
     Father.SetCmdState();
 }
        private void GameSelected(bool bNoMove)
        {
            string                      strGame;
            PgnParser                   parser;
            List<ChessBoard.MovePosS>   listGame;
            int                         iSkip;
            int                         iTruncated;
            ChessBoard                  chessBoard;
            ChessBoard.PlayerColorE     eStartingColor;
            string                      strWhitePlayerName;
            string                      strBlackPlayerName;
            PgnParser.PlayerTypeE       eWhiteType;
            PgnParser.PlayerTypeE       eBlackType;
            TimeSpan                    spanWhitePlayer;
            TimeSpan                    spanBlackPlayer;

            strGame = GetSelectedGame();
            if (strGame != null) {
                listGame    = new List<ChessBoard.MovePosS>(256);
                parser      = new PgnParser(false);
                if (!parser.ParseSingle(strGame,
                                        bNoMove,
                                        listGame,
                                        out iSkip,
                                        out iTruncated,
                                        out chessBoard,
                                        out eStartingColor,
                                        out strWhitePlayerName,
                                        out strBlackPlayerName,
                                        out eWhiteType,
                                        out eBlackType,
                                        out spanWhitePlayer,
                                        out spanBlackPlayer)) {
                    MessageBox.Show("The specified board is invalid.");
                } else if (iSkip != 0) {
                    MessageBox.Show("The game is incomplete. Select another game.");
                } else if (iTruncated != 0) {
                    MessageBox.Show("The selected game includes an unsupported pawn promotion (only pawn promotion to queen is supported).");
                } else if (listGame.Count == 0 && chessBoard == null) {
                    MessageBox.Show("Game is empty.");
                } else {
                    StartingChessBoard  = chessBoard;
                    StartingColor       = eStartingColor;
                    WhitePlayerName     = strWhitePlayerName;
                    BlackPlayerName     = strBlackPlayerName;
                    WhitePlayerType     = eWhiteType;
                    BlackPlayerType     = eBlackType;
                    WhiteTimer          = spanWhitePlayer;
                    BlackTimer          = spanBlackPlayer;
                    MoveList            = listGame;
                    DialogResult        = true;
                    Close();
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a new game using the specified list of moves
 /// </summary>
 /// <param name="chessBoardStarting">   Starting board or null if standard board</param>
 /// <param name="listMove">             List of moves</param>
 /// <param name="eNextMoveColor">       Color starting to play</param>
 /// <param name="strWhitePlayerName">   Name of the player playing white pieces</param>
 /// <param name="strBlackPlayerName">   Name of the player playing black pieces</param>
 /// <param name="eWhitePlayerType">     Type of player playing white pieces</param>
 /// <param name="eBlackPlayerType">     Type of player playing black pieces</param>
 /// <param name="spanPlayerWhite">      Timer for white</param>
 /// <param name="spanPlayerBlack">      Timer for black</param>
 public virtual void CreateGameFromMove(ChessBoard                   chessBoardStarting,
                                        List<ChessBoard.MovePosS>    listMove,
                                        ChessBoard.PlayerColorE      eNextMoveColor,
                                        string                       strWhitePlayerName,
                                        string                       strBlackPlayerName,
                                        PgnParser.PlayerTypeE        eWhitePlayerType,
                                        PgnParser.PlayerTypeE        eBlackPlayerType,
                                        TimeSpan                     spanPlayerWhite,
                                        TimeSpan                     spanPlayerBlack)
 {
     m_board.CreateGameFromMove(chessBoardStarting,
                                listMove,
                                eNextMoveColor);
     if (m_moveListUI != null) {
         m_moveListUI.Reset(m_board);
     }
     WhitePlayerName = strWhitePlayerName;
     BlackPlayerName = strBlackPlayerName;
     WhitePlayerType = eWhitePlayerType;
     BlackPlayerType = eBlackPlayerType;
     OnUpdateCmdState(System.EventArgs.Empty);
     m_gameTimer.ResetTo(m_board.NextMoveColor,
                         spanPlayerWhite.Ticks,
                         spanPlayerBlack.Ticks);
     m_gameTimer.Enabled = true;
     Refresh(false); // bForceRefresh
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a book from files selected by the user
        /// </summary>
        public void CreateBookFromFiles()
        {
            OpenFileDialog          openDlg;
            SaveFileDialog          saveDlg;
            PgnParser               parser;
            Stream                  stream;
            TextReader              reader;
            Book                    book;
            string                  strText;
            List<int[]>             arrMoveList;
            int                     iSkip;
            int                     iTruncated;
            int                     iTotalSkip = 0;
            int                     iTotalTruncated = 0;
            int                     iTotalFiles = 0;
            int                     iBookEntries;
            bool                    bAbort = false;

            arrMoveList = new List<int[]>(8192);
            book        = new Book();
            openDlg = new OpenFileDialog();
            openDlg.AddExtension        = true;
            openDlg.CheckFileExists     = true;
            openDlg.CheckPathExists     = true;
            openDlg.DefaultExt          = "pgn";
            openDlg.Filter              = "Chess PGN Files (*.pgn)|*.pgn";
            openDlg.Multiselect         = true;
            if (openDlg.ShowDialog() == true) {
                foreach (string strFileName in openDlg.FileNames) {
                    try {
                        stream = File.OpenRead(strFileName);
                    } catch(System.Exception) {
                        MessageBox.Show("Unable to open the file - " + strFileName);
                        stream = null;
                    }
                    if (stream != null) {
                        reader  = new StreamReader(stream);
                        strText = reader.ReadToEnd();
                        parser  = new PgnParser(false);
                        try {
                            parser.Parse(strText, arrMoveList, out iSkip, out iTruncated);
                            iTotalSkip      += iSkip;
                            iTotalTruncated += iTruncated;
                            iTotalFiles++;
                        } catch(PgnParserException exc) {
                            MessageBox.Show("Error processing file '" + strFileName + "'\r\n" + exc.Message + "\r\n" + exc.CodeInError);
                            bAbort =  true;
                        }
                        stream.Close();
                    }
                    if (bAbort) {
                        break;
                    }
                }
                if (!bAbort) {
                    iBookEntries = book.CreateBookList(arrMoveList, 30, 10);
                    MessageBox.Show(iTotalFiles.ToString() + " PNG file(s) read. " + arrMoveList.Count.ToString() + " games processed. " + iTotalTruncated.ToString() + " truncated. " + iTotalSkip.ToString() + " skipped. " + iBookEntries.ToString() + " book entries defined.");
                    saveDlg = new SaveFileDialog();
                    saveDlg.AddExtension        = true;
                    saveDlg.CheckPathExists     = true;
                    saveDlg.DefaultExt          = "bin";
                    saveDlg.Filter              = "Chess Opening Book (*.bin)|*.bin";
                    saveDlg.OverwritePrompt     = true;
                    if (saveDlg.ShowDialog() == true) {
                        try {
                            book.SaveBookToFile(saveDlg.FileName);
                        } catch (System.Exception ex) {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void GameSelected(bool bNoMove)
        {
            string    strGame;
            PgnParser parser;
            List <ChessBoard.MovePosS> listGame;
            int        iSkip;
            int        iTruncated;
            ChessBoard chessBoard;

            ChessBoard.PlayerColorE eStartingColor;
            string strWhitePlayerName;
            string strBlackPlayerName;

            PgnParser.PlayerTypeE eWhiteType;
            PgnParser.PlayerTypeE eBlackType;
            TimeSpan spanWhitePlayer;
            TimeSpan spanBlackPlayer;

            strGame = GetSelectedGame();
            if (strGame != null)
            {
                listGame = new List <ChessBoard.MovePosS>(256);
                parser   = new PgnParser(false);
                if (!parser.ParseSingle(strGame,
                                        bNoMove,
                                        listGame,
                                        out iSkip,
                                        out iTruncated,
                                        out chessBoard,
                                        out eStartingColor,
                                        out strWhitePlayerName,
                                        out strBlackPlayerName,
                                        out eWhiteType,
                                        out eBlackType,
                                        out spanWhitePlayer,
                                        out spanBlackPlayer))
                {
                    MessageBox.Show("The specified board is invalid.");
                }
                else if (iSkip != 0)
                {
                    MessageBox.Show("The game is incomplete. Select another game.");
                }
                else if (iTruncated != 0)
                {
                    MessageBox.Show("The selected game includes an unsupported pawn promotion (only pawn promotion to queen is supported).");
                }
                else if (listGame.Count == 0 && chessBoard == null)
                {
                    MessageBox.Show("Game is empty.");
                }
                else
                {
                    StartingChessBoard = chessBoard;
                    StartingColor      = eStartingColor;
                    WhitePlayerName    = strWhitePlayerName;
                    BlackPlayerName    = strBlackPlayerName;
                    WhitePlayerType    = eWhiteType;
                    BlackPlayerType    = eBlackType;
                    WhiteTimer         = spanWhitePlayer;
                    BlackTimer         = spanBlackPlayer;
                    MoveList           = listGame;
                    DialogResult       = true;
                    Close();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Accept the content of the form
        /// </summary>
        /// <param name="sender">   Sender object</param>
        /// <param name="e">        Event argument</param>
        private void butOk_Click(object sender, RoutedEventArgs e)
        {
            string    strGame;
            PgnParser parser;
            List <ChessBoard.MovePosS> listGame;
            int        iSkip;
            int        iTruncated;
            ChessBoard chessBoardStarting;

            ChessBoard.PlayerColorE eStartingColor;
            string strWhitePlayerName;
            string strBlackPlayerName;

            PgnParser.PlayerTypeE eWhiteType;
            PgnParser.PlayerTypeE eBlackType;
            TimeSpan spanWhitePlayer;
            TimeSpan spanBlackPlayer;

            strGame = textBox1.Text;
            if (String.IsNullOrEmpty(strGame))
            {
                MessageBox.Show("No PGN text has been pasted.");
            }
            else
            {
                listGame = new List <ChessBoard.MovePosS>(256);
                parser   = new PgnParser(false);
                if (!parser.ParseSingle(strGame,
                                        false,
                                        listGame,
                                        out iSkip,
                                        out iTruncated,
                                        out chessBoardStarting,
                                        out eStartingColor,
                                        out strWhitePlayerName,
                                        out strBlackPlayerName,
                                        out eWhiteType,
                                        out eBlackType,
                                        out spanWhitePlayer,
                                        out spanBlackPlayer))
                {
                    MessageBox.Show("The specified board is invalid.");
                }
                else if (iSkip != 0)
                {
                    MessageBox.Show("The game is incomplete. Paste another game.");
                }
                else if (iTruncated != 0)
                {
                    MessageBox.Show("The selected game includes an unsupported pawn promotion (only pawn promotion to queen is supported).");
                }
                else if (listGame.Count == 0 && chessBoardStarting == null)
                {
                    MessageBox.Show("Game is empty.");
                }
                else
                {
                    MoveList           = listGame;
                    StartingChessBoard = chessBoardStarting;
                    StartingColor      = eStartingColor;
                    WhitePlayerName    = strWhitePlayerName;
                    BlackPlayerName    = strBlackPlayerName;
                    WhitePlayerType    = eWhiteType;
                    BlackPlayerType    = eBlackType;
                    WhiteTimer         = spanWhitePlayer;
                    BlackTimer         = spanBlackPlayer;
                    DialogResult       = true;
                    Close();
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Accept the content of the form
        /// </summary>
        /// <param name="sender">   Sender object</param>
        /// <param name="e">        Event argument</param>
        private void butOk_Click(object sender, RoutedEventArgs e)
        {
            string                      strGame;
            PgnParser                   parser;
            List<ChessBoard.MovePosS>   listGame;
            int                         iSkip;
            int                         iTruncated;
            ChessBoard                  chessBoardStarting;
            ChessBoard.PlayerColorE     eStartingColor;
            string                      strWhitePlayerName;
            string                      strBlackPlayerName;
            PgnParser.PlayerTypeE       eWhiteType;
            PgnParser.PlayerTypeE       eBlackType;
            TimeSpan                    spanWhitePlayer;
            TimeSpan                    spanBlackPlayer;

            strGame = textBox1.Text;
            if (String.IsNullOrEmpty(strGame)) {
                MessageBox.Show("No PGN text has been pasted.");
            } else {
                listGame    = new List<ChessBoard.MovePosS>(256);
                parser      = new PgnParser(false);
                if (!parser.ParseSingle(strGame,
                                        false,
                                        listGame,
                                        out iSkip,
                                        out iTruncated,
                                        out chessBoardStarting,
                                        out eStartingColor,
                                        out strWhitePlayerName,
                                        out strBlackPlayerName,
                                        out eWhiteType,
                                        out eBlackType,
                                        out spanWhitePlayer,
                                        out spanBlackPlayer)) {
                    MessageBox.Show("The specified board is invalid.");
                } else if (iSkip != 0) {
                    MessageBox.Show("The game is incomplete. Paste another game.");
                } else if (iTruncated != 0) {
                    MessageBox.Show("The selected game includes an unsupported pawn promotion (only pawn promotion to queen is supported).");
                } else if (listGame.Count == 0 && chessBoardStarting == null) {
                    MessageBox.Show("Game is empty.");
                } else {
                    MoveList            = listGame;
                    StartingChessBoard  = chessBoardStarting;
                    StartingColor       = eStartingColor;
                    WhitePlayerName     = strWhitePlayerName;
                    BlackPlayerName     = strBlackPlayerName;
                    WhitePlayerType     = eWhiteType;
                    BlackPlayerType     = eBlackType;
                    WhiteTimer          = spanWhitePlayer;
                    BlackTimer          = spanBlackPlayer;
                    DialogResult        = true;
                    Close();
                }
            }
        }