Пример #1
0
 //*********************************************************     
 //
 /// <summary>
 /// Called when a move is selected from the MoveViewer
 /// </summary>
 /// <param name="sender">   Sender object</param>
 /// <param name="e">        Event handler</param>
 //  
 //*********************************************************     
 void m_moveViewer_NewMoveSelected(object sender, MoveViewer.NewMoveSelectedEventArg e) {
     ChessBoard.MoveResultE  eResult;
     bool                    bSucceed;
     
     if (PlayingMode == PlayingModeE.PlayerAgainstPlayer) {
         eResult = m_chessCtl.SelectMove(e.NewIndex, out bSucceed);
         DisplayMessage(eResult, MessageModeE.Verbose);
         e.Cancel = !bSucceed;
     } else {
         e.Cancel = true;
     }
 }
Пример #2
0
 //*********************************************************     
 //
 /// <summary>
 /// Form constructor
 /// </summary>
 //  
 //*********************************************************     
 public frmChessBoard() {
     SrcChess.Properties.Settings            settings;
     SearchEngine.SearchMode.OptionE         eOption;
     SearchEngine.SearchMode.ThreadingModeE  eThreadingMode;
     int                                     iTransTableSize;
     IBoardEvaluation                        boardEvalWhite;
     IBoardEvaluation                        boardEvalBlack;
     ChessControl.ChessControlColorInfo      colorInfo;
     
     InitializeComponent();
     settings                        = SrcChess.Properties.Settings.Default;
     colorInfo.m_colBlackPiece       = NameToColor(settings.BlackPieceColor);
     colorInfo.m_colWhitePiece       = NameToColor(settings.WhitePieceColor);
     colorInfo.m_colLiteCase         = NameToColor(settings.LiteCaseColor);
     colorInfo.m_colDarkCase         = NameToColor(settings.DarkCaseColor);
     iTransTableSize                 = (settings.TransTableSize < 5 || settings.TransTableSize > 256) ? 32 : settings.TransTableSize;
     TransTable.TranslationTableSize = iTransTableSize / 32 * 1000000;
     eOption                         = settings.UseAlphaBeta ? SearchEngine.SearchMode.OptionE.UseAlphaBeta : SearchEngine.SearchMode.OptionE.UseMinMax;
     if (settings.UseBook) {
         eOption |= SearchEngine.SearchMode.OptionE.UseBook;
     }
     
     if (settings.UseTransTable) {
         eOption |= SearchEngine.SearchMode.OptionE.UseTransTable;
     }
     if (settings.UsePlyCountIterative) {
         eOption |= SearchEngine.SearchMode.OptionE.UseIterativeDepthSearch;
     }
     switch(settings.UseThread) {
     case 0:
         eThreadingMode = SearchEngine.SearchMode.ThreadingModeE.Off;
         break;
     case 1:
         eThreadingMode = SearchEngine.SearchMode.ThreadingModeE.DifferentThreadForSearch;
         break;
     default:
         eThreadingMode = SearchEngine.SearchMode.ThreadingModeE.OnePerProcessorForSearch;
         break;
     }
     m_boardEvalUtil                     = new BoardEvaluationUtil();
     boardEvalWhite                      = m_boardEvalUtil.FindBoardEvaluator(settings.WhiteBoardEval);
     if (boardEvalWhite == null) {
         boardEvalWhite = m_boardEvalUtil.BoardEvaluators[0];
     }
     boardEvalBlack                      = m_boardEvalUtil.FindBoardEvaluator(settings.BlackBoardEval);
     if (boardEvalBlack == null) {
         boardEvalBlack = m_boardEvalUtil.BoardEvaluators[0];
     }
     m_searchMode                        = new SearchEngine.SearchMode(boardEvalWhite,
                                                                       boardEvalBlack,
                                                                       eOption,
                                                                       eThreadingMode,
                                                                       settings.UsePlyCount | settings.UsePlyCountIterative ? ((settings.PlyCount > 1 && settings.PlyCount < 9) ? settings.PlyCount : 6) : 0,  // Maximum depth
                                                                       settings.UsePlyCount | settings.UsePlyCountIterative ? 0 : (settings.AverageTime > 0 && settings.AverageTime < 1000) ? settings.AverageTime : 15,
                                                                       (settings.RandomMode >= 0 && settings.RandomMode <= 2) ? (SearchEngine.SearchMode.RandomModeE)settings.RandomMode : SearchEngine.SearchMode.RandomModeE.On); // Average time
     m_chessCtl                          = new LocalChessControl();
     m_chessCtl.Location                 = new Point(0, 0);
     m_chessCtl.Size                     = new Size(60 * 9, 60 * 9);
     m_chessCtl.UpdateCmdState          += new EventHandler(m_chessCtl_UpdateCmdState);
     m_chessCtl.Father                   = this;
     m_chessCtl.ColorInfo                = colorInfo;
     panelBoard.Controls.Add(m_chessCtl);
     PlayingMode                         = PlayingModeE.PlayerAgainstComputer;
     m_eComputerPlayingColor             = ChessBoard.PlayerColorE.Black;
     m_lostPieceBlack                    = new LostPiecesControl();
     m_lostPieceBlack.Location           = new Point(0,0);
     m_lostPieceBlack.Size               = new Size(200, 200);
     m_lostPieceBlack.Dock               = DockStyle.Fill;
     m_lostPieceBlack.ChessControl       = m_chessCtl;
     m_lostPieceBlack.Color              = true;
     panelBlackLostPiece.Controls.Add(m_lostPieceBlack);
     m_lostPieceWhite                    = new LostPiecesControl();
     m_lostPieceWhite.Location           = new Point(0,0);
     m_lostPieceWhite.Size               = new Size(200, 200);
     m_lostPieceWhite.Dock               = DockStyle.Fill;
     m_lostPieceWhite.ChessControl       = m_chessCtl;
     m_lostPieceWhite.Color              = false;
     panelWhiteLostPiece.Controls.Add(m_lostPieceWhite);
     m_moveViewer                        = new MoveViewer();
     m_moveViewer.Location               = new Point(0,0);
     m_moveViewer.Size                   = panelMoveList.Size;
     m_moveViewer.Dock                   = DockStyle.Fill;
     m_moveViewer.NewMoveSelected       += new MoveViewer.NewMoveSelectedHandler(m_moveViewer_NewMoveSelected);
     m_moveViewer.DisplayMode            = (settings.MoveNotation == 0) ? MoveViewer.DisplayModeE.MovePos : MoveViewer.DisplayModeE.PGN;
     panelMoveList.Controls.Add(m_moveViewer);
     m_chessCtl.MoveListUI               = this;
     m_chessCtl.MoveSelected            += new ChessControl.MoveSelectedEventHandler(m_chessCtl_MoveSelected);
     m_chessCtl.QueryPiece              += new ChessControl.QueryPieceEventHandler(m_chessCtl_QueryPiece);
     m_chessCtl.QueryPawnPromotionType  += new ChessControl.QueryPawnPromotionTypeEventHandler(m_chessCtl_QueryPawnPromotionType);
     m_bSecondThreadBusy                 = false;
     timer1.Tick                        += new EventHandler(timer1_Tick);
     timer1.Start();
     ResizeChessCtl();
     SetCmdState();
     ShowSearchMode();
     flashPieceToolStripMenuItem.Checked  = settings.FlashPiece;
     pgnNotationToolStripMenuItem.Checked = (m_moveViewer.DisplayMode == MoveViewer.DisplayModeE.PGN);
 }