示例#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();
        }
示例#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();
        }
示例#3
0
        public static void ShowPositionEditorForm(IWin32Window owner, ChessFacade chessFacade)
        {
            PositionEditorForm editorForm = new PositionEditorForm(chessFacade);

            editorForm.ShowDialog(owner);
            editorForm.Dispose();
        }
示例#4
0
        public void HighlightSquare(Square square)
        {
            if (square != Square.None)
            {
                switch (m_viewFromBlack)
                {
                case true:
                    m_picturePainter.DrawRectangle(m_highlightPen, ((7 - ChessFacade.File(square)) * SquareSize) + EdgeSize, (ChessFacade.Rank(square) * SquareSize) + EdgeSize, SquareSize, SquareSize);
                    break;

                case false:
                    m_picturePainter.DrawRectangle(m_highlightPen, (ChessFacade.File(square) * SquareSize) + EdgeSize, ((7 - ChessFacade.Rank(square)) * SquareSize) + EdgeSize, SquareSize, SquareSize);
                    break;
                }
            }
        }
示例#5
0
        public void DrawPiece(Square square, Piece piece)
        {
            if (square != Square.None && piece != Piece.None)
            {
                Image image = PieceImage(piece);

                switch (m_viewFromBlack)
                {
                case true:
                    m_picturePainter.DrawImage(image, ((7 - ChessFacade.File(square)) * SquareSize) + EdgeSize, (ChessFacade.Rank(square) * SquareSize) + EdgeSize, SquareSize, SquareSize);
                    break;

                case false:
                    m_picturePainter.DrawImage(image, (ChessFacade.File(square) * SquareSize) + EdgeSize, ((7 - ChessFacade.Rank(square)) * SquareSize) + EdgeSize, SquareSize, SquareSize);
                    break;
                }
            }
        }
示例#6
0
        public Square CoordinateToSquare(int x, int y)
        {
            if (x > FactoredEdgeWidth && x < (FactoredSquareWidth * 8) + FactoredEdgeWidth &&
                y > FactoredEdgeHeight && y < (FactoredSquareHeight * 8) + FactoredEdgeHeight)
            {
                int file = (x - FactoredEdgeWidth) / FactoredSquareWidth;
                int rank = (y - FactoredEdgeHeight) / FactoredSquareHeight;

                if (m_viewFromBlack)
                {
                    file = 7 - file;
                }
                else
                {
                    rank = 7 - rank;
                }

                return(ChessFacade.Position(file, rank));
            }

            return(Square.None);
        }
示例#7
0
 public static void Main()
 {
     //System.Console.WriteLine(true || false || false || false);
     ChessFacade.Start();
 }
示例#8
0
 public static void Main()
 {
     ChessFacade.Start();
 }
示例#9
0
 public static void Main(string[] args)
 {
     //Use raster fonts 8x8;
     ChessFacade.Start();
 }
示例#10
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();
        }
示例#11
0
 public static void Main(string[] args)
 {
     ChessFacade.Start();
 }