Ejemplo n.º 1
0
        private PositionEditorForm(ChessFacade chessFacade)
        {
            InitializeComponent();

              m_chessFacade = chessFacade;
              m_graphicHandler = new BasicDesign(m_pictureBoxBoard);

              m_pictureBoxWhiteKing.Image = m_graphicHandler.PieceImage(Piece.WhiteKing);
              m_pictureBoxWhiteQueen.Image = m_graphicHandler.PieceImage(Piece.WhiteQueen);
              m_pictureBoxWhiteRook.Image = m_graphicHandler.PieceImage(Piece.WhiteRook);
              m_pictureBoxWhiteBishop.Image = m_graphicHandler.PieceImage(Piece.WhiteBishop);
              m_pictureBoxWhiteKnight.Image = m_graphicHandler.PieceImage(Piece.WhiteKnight);
              m_pictureBoxWhitePawn.Image = m_graphicHandler.PieceImage(Piece.WhitePawn);
              m_pictureBoxBlackKing.Image = m_graphicHandler.PieceImage(Piece.BlackKing);
              m_pictureBoxBlackQueen.Image = m_graphicHandler.PieceImage(Piece.BlackQueen);
              m_pictureBoxBlackRook.Image = m_graphicHandler.PieceImage(Piece.BlackRook);
              m_pictureBoxBlackBishop.Image = m_graphicHandler.PieceImage(Piece.BlackBishop);
              m_pictureBoxBlackKnight.Image = m_graphicHandler.PieceImage(Piece.BlackKnight);
              m_pictureBoxBlackPawn.Image = m_graphicHandler.PieceImage(Piece.BlackPawn);

              m_comboEnPassant.Items.Add(Square.None);
              for (Square square = Square.A4; square <= Square.H5; ++square)
            m_comboEnPassant.Items.Add(square);

              SetEditorPiece(Piece.None);
              m_positionEditor = m_chessFacade.PositionEditor;
              m_positionEditor.BoardChanged += HandleBoardChangedEvent;
              UpdateInterface();
        }
Ejemplo n.º 2
0
        public MainForm()
        {
            InitializeComponent();

              m_panelFont = new Font(FontFamily.GenericSerif, 16, FontStyle.Regular);
              m_whiteBrush = new SolidBrush(Color.White);
              m_blackBrush = new SolidBrush(Color.Black);
              pictureWhiteTime.Image = new Bitmap(pictureWhiteTime.Width - 4, pictureWhiteTime.Height - 4);
              pictureBlackTime.Image = new Bitmap(pictureBlackTime.Width - 4, pictureBlackTime.Height - 4);
              pictureStateMessages.Image = new Bitmap(pictureStateMessages.Width - 4, pictureStateMessages.Height - 4);
              m_whiteTimeGraphic = Graphics.FromImage(pictureWhiteTime.Image);
              m_blackTimeGraphic = Graphics.FromImage(pictureBlackTime.Image);
              m_messagesGraphic = Graphics.FromImage(pictureStateMessages.Image);

              m_chessFacade = new ChessFacade();
              m_graphicHandler = new BasicDesign(boardPicture);

              m_chessFacade.BoardChanged += HandleBoardChangedEvent;
              m_chessFacade.WhitePawnPromoted += HandleWhitePawnPromotedEvent;
              m_chessFacade.BlackPawnPromoted += HandleBlackPawnPromotedEvent;
              m_chessFacade.StatusInfo += HandleStateChangedEvent;
              m_chessFacade.WhiteClockNotifier += HandleWhiteTimeEvent;
              m_chessFacade.BlackClockNotifier += HandleBlackTimeEvent;
              OutputWriter.WriteOutput += HandleWriteOutput;

              m_chessFacade.RaiseEvents();
              m_chessFacade.LoadOpeningBook();
        }
Ejemplo n.º 3
0
 public static void ShowPositionEditorForm(IWin32Window owner, ChessFacade chessFacade)
 {
     PositionEditorForm editorForm = new PositionEditorForm(chessFacade);
       editorForm.ShowDialog(owner);
       editorForm.Dispose();
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            ChessFacade chess = new ChessFacade();

              chess.WhitePawnPromoted += new EventHandler<PromotionEventArgs>(chess_WhitePawnPromoted);
              chess.BlackPawnPromoted += new EventHandler<PromotionEventArgs>(chess_BlackPawnPromoted);
              chess.StatusInfo += new EventHandler<GameStatusEventArgs>(chess_StatusChanged);

              EngineConfiguration engConfig = chess.EngineConfiguration;
              engConfig.EngineAutoPlay = false;
              chess.EngineConfiguration = engConfig;

              ClockConfiguration clockConfig = chess.ClockConfiguration;
              clockConfig.ClockType = ClockType.None;
              chess.ClockConfiguration = clockConfig;

              StreamReader file;
              if (args.Length == 1)
            file = File.OpenText(args[0]);
              else
            file = File.OpenText(@"..\..\input\book_1.00.pgn");

              int lineCounter = 0;
              string line;
              StringBuilder gameString = new StringBuilder();
              while ((line = file.ReadLine()) != null)
              {
            ++lineCounter;
            if (line.Length > 0 && line[0] != '[')
            {
              gameString.Append(line);
              if (line[line.Length - 1] != '.')
            gameString.Append(" ");
            }
            else if (gameString.Length > 0)
            {
              bool breaking = false;
              string[] lineBlocks = gameString.ToString().Split(new char[] { ' ' });

              PieceColor winner = PieceColor.None;
              if (lineBlocks[lineBlocks.Length - 2] == "1-0")
              {
            winner = PieceColor.White;
              }
              else if (lineBlocks[lineBlocks.Length - 2] == "0-1")
              {
            winner = PieceColor.Black;
              }
              else if (lineBlocks[lineBlocks.Length - 2] == "1/2-1/2" || lineBlocks[lineBlocks.Length - 2] == "*")
              {
            winner = PieceColor.None;
              }
              else
              {
            Console.WriteLine("Unknown result");
              }

              int itLength = Math.Min(lineBlocks.Length, 20);
              for (int i = 0; i < itLength; ++i)
              {
            string lineBlock = lineBlocks[i];
            if (lineBlock != "" && lineBlock != "*" && lineBlock != "1-0" && lineBlock != "0-1" && lineBlock != "1/2-1/2")
            {
              PgnMove pgnMove = new PgnMove(lineBlock);

              for (Square square = Square.A1; square <= Square.H8; ++square)
              {
                if ((pgnMove.PieceToPlay == chess.PieceAt(square)) &&
                  (pgnMove.FromFile == -1 || pgnMove.FromFile == ChessFacade.File(square)) &&
                  (pgnMove.FromRank == -1 || pgnMove.FromRank == ChessFacade.Rank(square)))
                {
                  promotion = pgnMove.PromotionPiece;
                  if (chess.PerformMove(square, pgnMove.DestinationSquare))
                  {
                    //Console.Write(square + "-" + pgnMove.DestinationSquare + " | ");
                    if (winner == PieceColor.None)
                      chess.AddToOpeningBook(1);
                    else if (winner == pgnMove.ColorToPlay)
                      chess.AddToOpeningBook(2);
                    //else
                    //	chess.AddToOpeningBook(1);
                    break;
                  }
                }

                if (square == Square.H8)
                {
                  Console.WriteLine("No move performed: " + lineCounter);
                  Console.ReadLine();
                  breaking = true;
                  break;
                }
              }
            }

            if (breaking)
              break;
              }

              //Console.WriteLine("new game");
              gameString = new StringBuilder();
              while (chess.UndoCount > 0)
            chess.UndoMove();
            }

            if (lineCounter % 1000 == 0)
              Console.WriteLine(lineCounter.ToString());
              }

              chess.SaveOpeningBook();
              Console.WriteLine("Done");
              Console.ReadLine();
        }