Exemple #1
0
        public void SortByScoreTest()
        {
            Moves moves = new Moves();
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 1));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 4));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 2));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 5));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 7));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8));
            moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0));

            moves.SortByScore();

            for (int i = 0; i < moves.Count - 1; i++)
            {
                Assert.IsTrue(moves[i].Score >= moves[i + 1].Score);
            }
        }
Exemple #2
0
        /// <summary>
        ///   Initializes static members of the <see cref="Game" /> class.
        /// </summary>
        static Game()
        {
            EnableFeatures();
            ClockIncrementPerMove = new TimeSpan(0, 0, 0);
            ClockFixedTimePerMove = new TimeSpan(0, 0, 2);
            //DifficultyLevel = 12;
            ClockTime = new TimeSpan(0, 5, 0);
            ClockMaxMoves = 40;
            UseRandomOpeningMoves = true;
            EnablePondering = false;
            MoveRedoList = new Moves();
            //MaximumSearchDepth = 32;
            MoveAnalysis = new Moves();
            MoveHistory = new Moves();
            FenStartPosition = string.Empty;
            HashTable.Initialise();
            HashTablePawn.Initialise();
            HashTableCheck.Initialise();

            PlayerWhite = new PlayerWhite();
            //PlayerWhite.Intellegence = Player.PlayerIntellegenceNames.Computer;

            PlayerBlack = new PlayerBlack();
            //PlayerBlack.Intellegence = Player.PlayerIntellegenceNames.Human;

            PlayerToPlay = PlayerWhite;

            Board.EstablishHashKey();
            OpeningBookSimple.Initialise();

            PlayerWhite.Brain.ReadyToMakeMoveEvent += PlayerReadyToMakeMove;
            PlayerBlack.Brain.ReadyToMakeMoveEvent += PlayerReadyToMakeMove;

            TryRegistryKey ();

            // OpeningBook.BookConvert(Game.PlayerWhite);
        }
Exemple #3
0
        /// <summary>
        ///   Initializes static members of the <see cref="Game" /> class.
        /// </summary>
        static Game()
        {
            EnableFeatures();
            ClockIncrementPerMove = new TimeSpan(0, 0, 0);
            ClockFixedTimePerMove = new TimeSpan(0, 0, 0);
            DifficultyLevel       = 1;
            ClockTime             = new TimeSpan(0, 5, 0);
            ClockMaxMoves         = 40;
            UseRandomOpeningMoves = true;
            MoveRedoList          = new Moves();
            MaximumSearchDepth    = 1;
            MoveAnalysis          = new Moves();
            MoveHistory           = new Moves();
            FenStartPosition      = string.Empty;
            HashTable.Initialise();
            HashTablePawn.Initialise();
            HashTableCheck.Initialise();

            PlayerWhite  = new PlayerWhite();
            PlayerBlack  = new PlayerBlack();
            PlayerToPlay = PlayerWhite;
            Board.EstablishHashKey();
            OpeningBookSimple.Initialise();

            PlayerWhite.Brain.ReadyToMakeMoveEvent += PlayerReadyToMakeMove;
            PlayerBlack.Brain.ReadyToMakeMoveEvent += PlayerReadyToMakeMove;

            RegistryKey registryKeySoftware = Registry.CurrentUser.OpenSubKey("Software", true);

            if (registryKeySoftware != null)
            {
                RegistryKey registryKeySharpChess = registryKeySoftware.CreateSubKey(@"PeterHughes.org\SharpChess");

                if (registryKeySharpChess != null)
                {
                    if (registryKeySharpChess.GetValue("FileName") == null)
                    {
                        saveGameFileName = string.Empty;
                    }
                    else
                    {
                        saveGameFileName = registryKeySharpChess.GetValue("FileName").ToString();
                    }

                    if (registryKeySharpChess.GetValue("ShowThinking") == null)
                    {
                        ShowThinking = true;
                    }
                    else
                    {
                        ShowThinking = registryKeySharpChess.GetValue("ShowThinking").ToString() == "1";
                    }

                    // Delete deprecated values
                    if (registryKeySharpChess.GetValue("EnablePondering") != null)
                    {
                        registryKeySharpChess.DeleteValue("EnablePondering");
                    }

                    if (registryKeySharpChess.GetValue("DisplayMoveAnalysisTree") != null)
                    {
                        registryKeySharpChess.DeleteValue("DisplayMoveAnalysisTree");
                    }

                    if (registryKeySharpChess.GetValue("ClockMoves") != null)
                    {
                        registryKeySharpChess.DeleteValue("ClockMoves");
                    }

                    if (registryKeySharpChess.GetValue("ClockMinutes") != null)
                    {
                        registryKeySharpChess.DeleteValue("ClockMinutes");
                    }
                }
            }

            // OpeningBook.BookConvert(Game.PlayerWhite);
        }
Exemple #4
0
 /// <summary>
 /// Generate "lazy" moves for all pieces. Lazy means we include moves that put our own king in check.
 /// </summary>
 /// <param name="moves">
 /// Move list to be filled with moves.
 /// </param>
 /// <param name="movesType">
 /// Type of moves to be generated. e.g. all or just captures.
 /// </param>
 public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
 {
     foreach (Piece piece in this.Pieces)
     {
         piece.GenerateLazyMoves(moves, movesType);
     }
 }
Exemple #5
0
 /// <summary>
 /// Appends a list of moves of all the pieces that are attacking this square.
 /// </summary>
 /// <param name="moves">
 /// Moves of pieces that are attacking this square.
 /// </param>
 /// <param name="player">
 /// Player whose turn it is
 /// </param>
 public void AttackersMoveList(Moves moves, Player player)
 {
     foreach (Piece p in player.Pieces)
     {
         if (p.CanAttackSquare(this))
             moves.Add(0, 0, Move.MoveNames.Standard, p, p.Square, this, this.Piece, 0, 0);
     }
 }
Exemple #6
0
        /// <summary>
        /// The generate lazy moves.
        /// </summary>
        /// <param name="depth">
        /// The depth.
        /// </param>
        /// <param name="moves">
        /// The moves.
        /// </param>
        /// <param name="movesType">
        /// The moves type.
        /// </param>
        /// <param name="squareAttacking">
        /// The square attacking.
        /// </param>
        public void GenerateLazyMoves(int depth, Moves moves, Moves.MoveListNames movesType, Square squareAttacking)
        {
            // if (squareAttacking==null)
            // {
            // All moves as defined by movesType
            foreach (Piece piece in this.Pieces)
            {
                piece.GenerateLazyMoves(moves, movesType);

                /*
                if (movesType != Moves.MoveListNames.All)
                {
                    int intIndex;
                    for (intIndex = moves.Count - 1; intIndex >= 0; intIndex--)
                    {
                        Move move = moves[intIndex];
                        if (!(
                             move.Name == Move.MoveNames.PawnPromotionQueen
                             &&
                             move.PieceCaptured == null
                             (move.Name == Move.MoveNames.Standard
                              && move.From.Piece.BasicValue < move.To.Piece.BasicValue)
                             ||
                             (move.Name == Move.MoveNames.Standard
                              && !move.To.PlayerCanMoveToThisSquare(move.Piece.Player.OtherPlayer))
                             ||
                             move.To.Ordinal==squareAttacking.Ordinal
                             ))
                        {
                            moves.Remove(move);
                        }
                    }
                }
                */
            }

            // }
            // else
            // {
            // Just re-capture moves
            // squareAttacking.AttackerMoveList(moves, this);
            // }
        }
Exemple #7
0
        /// <summary>
        /// Appends a list of moves of all the pieces that are attacking this square.
        /// </summary>
        /// <param name="moves">
        /// Moves of pieces that are attacking this square.
        /// </param>
        /// <param name="player">
        /// Player whose turn it is
        /// </param>
        public void AttackersMoveList(Moves moves, Player player)
        {
            Piece piece;

            // Pawn
            piece = Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackLeftOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            piece = Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackRightOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            // Knight
            piece = Board.GetPiece(this.Ordinal + 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Bishop & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Rook & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // King!
            piece = Board.GetPiece(this.Ordinal + 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }
        }
        /// <summary>
        /// The add branch.
        /// </summary>
        /// <param name="intDepth">
        /// The int depth.
        /// </param>
        /// <param name="moves">
        /// The moves.
        /// </param>
        /// <param name="treeNodes">
        /// The tree nodes.
        /// </param>
        private void AddBranch(int intDepth, Moves moves, TreeNodeCollection treeNodes)
        {
            if (intDepth == 0)
            {
                return;
            }

            if (moves != null)
            {
                foreach (Move move in moves)
                {
                    TreeNode treeNode = treeNodes.Add(move.DebugText);
                    treeNode.Tag = move;
                    if (move.Moves != null && move.Moves.Count > 0)
                    {
                        this.AddBranch(intDepth - 1, move.Moves, treeNode.Nodes);
                    }
                }
            }
        }
Exemple #9
0
        /// <summary>
        /// The pic square_ mouse down.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void picSquare_MouseDown(object sender, MouseEventArgs e)
        {
            if (this.m_blnInMouseDown || e.Button != MouseButtons.Left)
            {
                return;
            }

            if (Game.PlayerToPlay.Brain.IsThinking && !Game.PlayerToPlay.Brain.IsPondering)
            {
                return;
            }

            this.m_blnIsLeftMouseButtonDown = true;
            this.m_blnInMouseDown = true;

            Game.SuspendPondering();

            PictureBox picFrom = (PictureBox)sender;

            int intOrdinalFrom = Convert.ToInt32(picFrom.Tag);

            Square squareFrom = Board.GetSquare(intOrdinalFrom);

            Piece pieceFrom = squareFrom.Piece;
            if (pieceFrom != null && pieceFrom.Player.Colour == Game.PlayerToPlay.Colour)
            {
                picFrom.Image = null;
                picFrom.Refresh();

                this.m_curPieceCursor = this.GetPieceCursor(pieceFrom);
                this.pnlEdging.Cursor = this.m_curPieceCursor;

                // Mark possible moves
                this.m_squareFrom = squareFrom;
                this.m_squareTo = null;
                this.m_movesPossible = new Moves();
                pieceFrom.GenerateLegalMoves(this.m_movesPossible);
                this.RenderBoardColours();
                this.pnlEdging.Refresh();

                Game.ResumePondering();

                if (this.m_blnIsLeftMouseButtonDown
                    && ((PictureBox)sender).DoDragDrop(pieceFrom, DragDropEffects.Move) == DragDropEffects.Move)
                {
                    Game.SuspendPondering();

                    bool blnMoveMade = false;
                    Piece pieceTo = this.m_squareTo.Piece;

                    // Is it an empty space or enemy piece
                    if (pieceTo == null || pieceTo != null && pieceTo.Player.Colour != Game.PlayerToPlay.Colour)
                    {
                        // Check to see it the move is valid, by comparing against all possible valid moves
                        bool blnIsPromotion = false;
                        Move.MoveNames movenamePromotion = Model.Move.MoveNames.NullMove;
                        foreach (Move move in this.m_movesPossible)
                        {
                            if (move.To == this.m_squareTo)
                            {
                                if (!blnIsPromotion)
                                {
                                    switch (move.Name)
                                    {
                                        case Model.Move.MoveNames.PawnPromotionQueen:
                                        case Model.Move.MoveNames.PawnPromotionRook:
                                        case Model.Move.MoveNames.PawnPromotionBishop:
                                        case Model.Move.MoveNames.PawnPromotionKnight:
                                            blnIsPromotion = true;
                                            frmPieceSelector formPieceSelector = new frmPieceSelector();
                                            formPieceSelector.Colour = move.Piece.Player.Colour;
                                            formPieceSelector.ShowDialog(this);
                                            movenamePromotion = formPieceSelector.MoveNameSelected;
                                            break;
                                    }
                                }

                                if (!blnIsPromotion || move.Name == movenamePromotion)
                                {
                                    this.m_squareFrom = null;
                                    this.m_movesPossible = new Moves();

                                    Game.MakeAMove(move.Name, move.Piece, move.To);
                                    blnMoveMade = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (!blnMoveMade)
                    {
                        this.m_picSquares[this.m_squareFrom.File, this.m_squareFrom.Rank].Image =
                            this.imgPieces.Images[this.m_squareFrom.Piece.ImageIndex];
                        this.m_squareFrom = null;
                        this.m_movesPossible = null;
                        this.RenderBoardColours();
                    }
                }
                else
                {
                    Game.SuspendPondering();

                    this.m_picSquares[this.m_squareFrom.File, this.m_squareFrom.Rank].Image =
                        this.imgPieces.Images[this.m_squareFrom.Piece.ImageIndex];
                    this.m_squareFrom = null;
                    this.m_movesPossible = null;
                    this.RenderBoardColours();

                    Game.ResumePondering();
                }

                this.pnlEdging.Cursor = Cursors.Default;
            }
            else
            {
                Game.ResumePondering();
            }

            this.m_blnInMouseDown = false;
        }
Exemple #10
0
        /// <summary>
        /// The game_ board position changed handler.
        /// </summary>
        private void Game_BoardPositionChangedHandler()
        {
            // 			if (Game.IsPaused) return;
            if (Game.MoveHistory.Count > 0)
            {
                Move move = Game.MoveHistory.Last;
                if (this.sbr.Text.StartsWith("Thinking..."))
                {
                    this.sbr.Text = this.sbr.Text.Substring("Thinking...".Length);
                }

                this.sbr.Text += "  Moved: " + move.Piece.Name.ToString() //+ " " + move.From.Name + "-" + move.To.Name
                                 + " " + move.Description;
            }

            this.pbr.Value = 0;

            this.m_squareFrom = null;
            this.m_movesPossible = new Moves();

            this.RenderMoveAnalysis();
            this.RenderBoard();
        }
Exemple #11
0
 /// <summary>
 /// The remove last history item.
 /// </summary>
 private void RemoveLastHistoryItem()
 {
     this.lvwMoveHistory.Items.RemoveAt(this.lvwMoveHistory.Items.Count - 1);
     this.m_squareFrom = null;
     this.m_movesPossible = new Moves();
 }
Exemple #12
0
        /// <summary>
        ///   Initializes static members of the <see cref="Game" /> class.
        /// </summary>
        static Game()
        {
            EnableFeatures();
            ClockIncrementPerMove = new TimeSpan(0, 0, 0);
            ClockFixedTimePerMove = new TimeSpan(0, 0, 0);
            DifficultyLevel = 1;
            ClockTime = new TimeSpan(0, 5, 0);
            ClockMaxMoves = 40;
            UseRandomOpeningMoves = true;
            MoveRedoList = new Moves();
            MaximumSearchDepth = 1;
            MoveAnalysis = new Moves();
            MoveHistory = new Moves();
            FenStartPosition = string.Empty;
            HashTable.Initialise();
            HashTablePawn.Initialise();
            HashTableCheck.Initialise();

            PlayerWhite = new PlayerWhite();
            PlayerBlack = new PlayerBlack();
            PlayerToPlay = PlayerWhite;
            Board.EstablishHashKey();
            OpeningBookSimple.Initialise();

            PlayerWhite.Brain.ReadyToMakeMoveEvent += PlayerReadyToMakeMove;
            PlayerBlack.Brain.ReadyToMakeMoveEvent += PlayerReadyToMakeMove;

            #if !MOBILE
            RegistryKey registryKeySoftware = Registry.CurrentUser.OpenSubKey("Software", true);
            if (registryKeySoftware != null)
            {
                RegistryKey registryKeySharpChess = registryKeySoftware.CreateSubKey(@"PeterHughes.org\SharpChess");

                if (registryKeySharpChess != null)
                {
                    if (registryKeySharpChess.GetValue("FileName") == null)
                    {
                        saveGameFileName = string.Empty;
                    }
                    else
                    {
                        saveGameFileName = registryKeySharpChess.GetValue("FileName").ToString();
                    }

                    if (registryKeySharpChess.GetValue("ShowThinking") == null)
                    {
                        ShowThinking = true;
                    }
                    else
                    {
                        ShowThinking = registryKeySharpChess.GetValue("ShowThinking").ToString() == "1";
                    }

                    // Delete deprecated values
                    if (registryKeySharpChess.GetValue("EnablePondering") != null)
                    {
                        registryKeySharpChess.DeleteValue("EnablePondering");
                    }

                    if (registryKeySharpChess.GetValue("DisplayMoveAnalysisTree") != null)
                    {
                        registryKeySharpChess.DeleteValue("DisplayMoveAnalysisTree");
                    }

                    if (registryKeySharpChess.GetValue("ClockMoves") != null)
                    {
                        registryKeySharpChess.DeleteValue("ClockMoves");
                    }

                    if (registryKeySharpChess.GetValue("ClockMinutes") != null)
                    {
                        registryKeySharpChess.DeleteValue("ClockMinutes");
                    }
                }
            }

            #endif
            // OpeningBook.BookConvert(Game.PlayerWhite);
        }
Exemple #13
0
        /*
         * private Move.enmName MoveName(Player.enmColour colourPlayer, Square squareTo)
         * {
         *  if (colourPlayer==Player.enmColour.White && squareTo.Rank==7 || colourPlayer==Player.enmColour.Black && squareTo.Rank==0)
         *  {
         *      return Move.enmName.PawnPromotion;
         *  }
         *  else
         *  {
         *      return Move.enmName.Standard;
         *  }
         * }
         */
        #region Public Methods

        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            // Types of promotion to generate. Removed bishop and Rook.
            Move.MoveNames[] promotionTypes =
            {
                Move.MoveNames.PawnPromotionQueen,  Move.MoveNames.PawnPromotionKnight,
                Move.MoveNames.PawnPromotionBishop, Move.MoveNames.PawnPromotionRook
            };

            Square square;
            bool   isPromotion = (this.Base.Player.Colour == Player.PlayerColourNames.White && this.Base.Square.Rank == 6)
                                 ||
                                 (this.Base.Player.Colour == Player.PlayerColourNames.Black && this.Base.Square.Rank == 1);

            int intMovesToGenerate = isPromotion ? promotionTypes.Length : 1;

            for (int intIndex = 0; intIndex < intMovesToGenerate; intIndex++)
            {
                // Take right
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset))
                    != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour &&
                        square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Take left
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset)) != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour &&
                        square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Forward one
                if (movesType == Moves.MoveListNames.All || isPromotion)
                {
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }
            }

            // Forward two
            if (movesType == Moves.MoveListNames.All)
            {
                if (!this.Base.HasMoved)
                {
                    // Check one square ahead is not occupied
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        if (
                            (square =
                                 Board.GetSquare(
                                     this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset
                                     + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null)
                        {
                            moves.Add(
                                0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                }
            }

            // En Passent
            if ((this.Base.Square.Rank == 4 && this.Base.Player.Colour == Player.PlayerColourNames.White) ||
                (this.Base.Square.Rank == 3 && this.Base.Player.Colour == Player.PlayerColourNames.Black))
            {
                Piece piecePassed;

                // Left
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal - 1)) != null && piecePassed.NoOfMoves == 1 &&
                    piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn &&
                    piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }

                // Right
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal + 1)) != null && piecePassed.NoOfMoves == 1 &&
                    piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn &&
                    piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// The append piece path.
        /// </summary>
        /// <param name="moves">
        /// The moves.
        /// </param>
        /// <param name="piece">
        /// The piece.
        /// </param>
        /// <param name="player">
        /// The player.
        /// </param>
        /// <param name="offset">
        /// The offset.
        /// </param>
        /// <param name="movesType">
        /// The moves type.
        /// </param>
        public static void AppendPiecePath(
            Moves moves, Piece piece, Player player, int offset, Moves.MoveListNames movesType)
        {
            int intOrdinal = piece.Square.Ordinal;
            Square square;

            intOrdinal += offset;
            while ((square = GetSquare(intOrdinal)) != null)
            {
                if (square.Piece == null)
                {
                    if (movesType == Moves.MoveListNames.All)
                    {
                        moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, null, 0, 0);
                    }
                }
                else if (square.Piece.Player.Colour != player.Colour && square.Piece.IsCapturable)
                {
                    moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, square, square.Piece, 0, 0);
                    break;
                }
                else
                {
                    break;
                }

                intOrdinal += offset;
            }
        }
Exemple #15
0
        /// <summary>
        /// Determines whether a proposed move is valid.
        /// </summary>
        /// <param name="moveProposed">
        /// The move proposed.
        /// </param>
        /// <returns>
        /// True if valid.
        /// </returns>
        public static bool IsValid(Move moveProposed)
        {
            if (moveProposed.Piece != Board.GetPiece(moveProposed.From.Ordinal))
            {
                return false;
            }

            Moves movesPossible = new Moves();
            moveProposed.Piece.GenerateLazyMoves(movesPossible, Moves.MoveListNames.All);
            foreach (Move move in movesPossible)
            {
                if (moveProposed.Name == move.Name && moveProposed.To.Ordinal == move.To.Ordinal)
                {
                    return true;
                }
            }

            return false;
        }
Exemple #16
0
 /// <summary>
 /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
 /// </summary>
 /// <param name="moves">
 /// Moves list that will be populated with lazy moves.
 /// </param>
 /// <param name="movesType">
 /// Types of moves to include. e.g. All, or captures-only.
 /// </param>
 public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
 {
     this.Top.GenerateLazyMoves(moves, movesType);
 }
Exemple #17
0
 /// <summary>
 /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
 /// </summary>
 /// <param name="moves">
 /// .
 /// </param>
 /// <param name="movesType">
 /// Types of moves to include. e.g. All, or captures-only.
 /// </param>
 public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
 {
     this.Top.GenerateLazyMoves(moves, movesType);
 }
 /// <summary>
 /// Recursive method to walk the move tree, calculating nodes per depth.
 /// </summary>
 /// <param name="depth">Depth of tree node.</param>
 /// <param name="moves">Branch at node of tree.</param>
 private void GetNodesAtDepth(int depth, Moves moves)
 {
     if (moves != null)
     {
         this.totalNodesPerDepth[depth] += moves.Count;
         foreach (Move move in moves)
         {
             if (move.Moves != null && move.Moves.Count > 0)
             {
                 this.GetNodesAtDepth(depth + 1, move.Moves);
             }
         }
     }
 }
Exemple #19
0
        /// <summary>
        /// The generate legal moves.
        /// </summary>
        /// <param name="moves">
        /// The moves.
        /// </param>
        public void GenerateLegalMoves(Moves moves)
        {
            this.GenerateLazyMoves(moves, Moves.MoveListNames.All);
            for (int intIndex = moves.Count - 1; intIndex >= 0; intIndex--)
            {
                Move move = moves[intIndex];
                Move moveUndo = move.Piece.Move(move.Name, move.To);
                if (move.Piece.Player.IsInCheck)
                {
                    moves.Remove(move);
                }

                Model.Move.Undo(moveUndo);
            }
        }
Exemple #20
0
 /// <summary>
 /// The generate legal moves.
 /// </summary>
 /// <param name="moves">
 /// The moves.
 /// </param>
 public void GenerateLegalMoves(Moves moves)
 {
     foreach (Piece piece in this.Pieces)
     {
         piece.GenerateLegalMoves(moves);
     }
 }
Exemple #21
0
        /// <summary>
        /// Appends a list of moves of all the pieces that are attacking this square.
        /// </summary>
        /// <param name="moves">
        /// Moves of pieces that are attacking this square.
        /// </param>
        /// <param name="player">
        /// Player whose turn it is
        /// </param>
        public void AttackersMoveList(Moves moves, Player player)
        {
            Piece piece;

            // Pawn
            piece = Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackLeftOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackLeftOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            piece = Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset);
            if (piece != null && piece.Name == Piece.PieceNames.Pawn && piece.Player.Colour == player.Colour)
            {
                moves.Add(
                    0,
                    0,
                    Move.MoveNames.Standard,
                    Board.GetPiece(this.Ordinal - player.PawnAttackRightOffset),
                    Board.GetSquare(this.Ordinal - player.PawnAttackRightOffset),
                    this,
                    this.Piece,
                    0,
                    0);
            }

            // Knight
            piece = Board.GetPiece(this.Ordinal + 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 33);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 18);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 14);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 31);
            if (piece != null && piece.Name == Piece.PieceNames.Knight && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Bishop & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, 17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -15)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Bishop, this, -17)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // Rook & Queen
            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -1)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, 16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            if ((piece = Board.LinesFirstPiece(player.Colour, Piece.PieceNames.Rook, this, -16)) != null)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            // King!
            piece = Board.GetPiece(this.Ordinal + 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 16);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 17);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal - 1);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }

            piece = Board.GetPiece(this.Ordinal + 15);
            if (piece != null && piece.Name == Piece.PieceNames.King && piece.Player.Colour == player.Colour)
            {
                moves.Add(0, 0, Move.MoveNames.Standard, piece, piece.Square, this, this.Piece, 0, 0);
            }
        }
Exemple #22
0
        /// <summary>
        /// Convert the Principal Variation to a string
        /// </summary>
        /// <param name="moveList">
        /// the list of moves of the variation
        /// </param>
        /// <returns>
        /// the string of the Principal Variation. Ex: 5 Bb3a4 Bc8d7 Ba4xc6
        /// </returns>
        private static string PvLine(Moves moveList)
        {
            if (moveList != null)
            {
                PlayerDebug.m_strbPV.Remove(0, PlayerDebug.m_strbPV.Length);
                for (int intIndex = 0; intIndex < moveList.Count; intIndex++)
                {
                    Move move = moveList[intIndex];
                    if (move != null)
                    {
                        PlayerDebug.m_strbPV.Append(move.Piece.Abbreviation);
                        PlayerDebug.m_strbPV.Append(move.From.Name);
                        if (move.PieceCaptured != null)
                        {
                            PlayerDebug.m_strbPV.Append("x");
                        }

                        PlayerDebug.m_strbPV.Append(move.To.Name);
                        PlayerDebug.m_strbPV.Append(" ");
                    }
                }
            }

            return PlayerDebug.m_strbPV.ToString();
        }
Exemple #23
0
        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            // Types of promotion to generate. Removed bishop and Rook.
            Move.MoveNames[] promotionTypes = {
                                                  Move.MoveNames.PawnPromotionQueen, Move.MoveNames.PawnPromotionKnight

                                                  // Move.MoveNames.PawnPromotionBishop, Move.MoveNames.PawnPromotionRook // Why bother?
                                              };

            Square square;
            bool isPromotion = (this.Base.Player.Colour == Player.PlayerColourNames.White && this.Base.Square.Rank == 6)
                               ||
                               (this.Base.Player.Colour == Player.PlayerColourNames.Black && this.Base.Square.Rank == 1);

            int intMovesToGenerate = isPromotion ? promotionTypes.Length : 1;

            for (int intIndex = 0; intIndex < intMovesToGenerate; intIndex++)
            {
                // Take right
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset))
                    != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour
                        && square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Take left
                if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset)) != null)
                {
                    if (square.Piece != null && square.Piece.Player.Colour != this.Base.Player.Colour
                        && square.Piece.IsCapturable)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }

                // Forward one
                if (movesType == Moves.MoveListNames.All || isPromotion)
                {
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        moves.Add(
                            0,
                            0,
                            isPromotion ? promotionTypes[intIndex] : Move.MoveNames.Standard,
                            this.Base,
                            this.Base.Square,
                            square,
                            square.Piece,
                            0,
                            0);
                    }
                }
            }

            // Forward two
            if (movesType == Moves.MoveListNames.All)
            {
                if (!this.Base.HasMoved)
                {
                    // Check one square ahead is not occupied
                    if ((square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset))
                        != null && square.Piece == null)
                    {
                        if (
                            (square =
                             Board.GetSquare(
                                 this.Base.Square.Ordinal + this.Base.Player.PawnForwardOffset
                                 + this.Base.Player.PawnForwardOffset)) != null && square.Piece == null)
                        {
                            moves.Add(
                                0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                }
            }

            // En Passent
            if ((this.Base.Square.Rank == 4 && this.Base.Player.Colour == Player.PlayerColourNames.White)
                || (this.Base.Square.Rank == 3 && this.Base.Player.Colour == Player.PlayerColourNames.Black))
            {
                Piece piecePassed;

                // Left
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal - 1)) != null && piecePassed.NoOfMoves == 1
                    && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn
                    && piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackLeftOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }

                // Right
                if ((piecePassed = Board.GetPiece(this.Base.Square.Ordinal + 1)) != null && piecePassed.NoOfMoves == 1
                    && piecePassed.LastMoveTurnNo == Game.TurnNo && piecePassed.Name == Piece.PieceNames.Pawn
                    && piecePassed.Player.Colour != this.Base.Player.Colour)
                {
                    square = Board.GetSquare(this.Base.Square.Ordinal + this.Base.Player.PawnAttackRightOffset);
                    moves.Add(0, 0, Move.MoveNames.EnPassent, this.Base, this.Base.Square, square, piecePassed, 0, 0);
                }
            }
        }
Exemple #24
0
// ReSharper restore FunctionNeverReturns

        /// <summary>
        /// Process a WinBoard make move message.
        /// </summary>
        /// <param name="strMove">
        /// The move.
        /// </param>
        /// <exception cref="WinBoardInputException">
        /// Winboard exception
        /// </exception>
        private static void MakeMove(string strMove)
        {
            /*
                    See below for the syntax of moves. If the move is illegal, print an error message; see the section "Commands from the engine to xboard". If the move is legal and in turn, make it. If not in force mode, stop the opponent's clock, start the engine's clock, start thinking, and eventually make a move. 
                    When xboard sends your engine a move, it normally sends coordinate algebraic notation. Examples: 

                    Normal moves: e2e4  
                    Pawn promotion: e7e8q  
                    Castling: e1g1, e1c1, e8g8, e8c8  
                    Bughouse/crazyhouse drop: P@h3  
                    ICS Wild 0/1 castling: d1f1, d1b1, d8f8, d8b8  
                    FischerRandom castling: O-O, O-O-O (oh, not zero)  

                    Beginning in protocol version 2, you can use the feature command to select SAN (standard algebraic notation) instead; for example, e4, Nf3, exd5, Bxf7+, Qxf7#, e8=Q, O-O, or P@h3. Note that the last form, P@h3, is a extension to the PGN standard's definition of SAN, which does not support bughouse or crazyhouse. 

                    xboard doesn't reliably detect illegal moves, because it does not keep track of castling unavailability due to king or rook moves, or en passant availability. If xboard sends an illegal move, send back an error message so that xboard can retract it and inform the user; see the section "Commands from the engine to xboard". 
                */
            Game.SuspendPondering();

            Move.MoveNames movename = Move.MoveNames.NullMove;

            if (strMove.Length == 5)
            {
                switch (strMove.Substring(4, 1))
                {
                    case "q":
                        movename = Move.MoveNames.PawnPromotionQueen;
                        break;

                    case "r":
                        movename = Move.MoveNames.PawnPromotionRook;
                        break;

                    case "b":
                        movename = Move.MoveNames.PawnPromotionBishop;
                        break;

                    case "n":
                        movename = Move.MoveNames.PawnPromotionKnight;
                        break;
                }
            }

            Moves moves = new Moves();
            Game.PlayerToPlay.GenerateLegalMoves(moves);

            foreach (Move move in moves)
            {
                if (move.From.Name == strMove.Substring(0, 2) && move.To.Name == strMove.Substring(2, 2)
                    && (movename == Move.MoveNames.NullMove || move.Name == movename))
                {
                    Game.MakeAMove(move.Name, move.Piece, move.To);
                    return;
                }
            }

            throw new WinBoardInputException("Illegal move: " + strMove);
        }
Exemple #25
0
        /// <summary>
        /// Generate "lazy" moves for this piece, which is all usual legal moves, but also includes moves that put the king in check.
        /// </summary>
        /// <param name="moves">
        /// Moves list that will be populated with lazy moves.
        /// </param>
        /// <param name="movesType">
        /// Types of moves to include. e.g. All, or captures-only.
        /// </param>
        public void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType)
        {
            Square square;

            switch (movesType)
            {
                case Moves.MoveListNames.All:
                    for (int i = 0; i < moveVectors.Length; i++) //Sil
                    {
                        square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]);

                        if (square != null && (square.Piece == null || (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
                        {
                            moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                    break;

                case Moves.MoveListNames.CapturesPromotions:
                    for (int i = 0; i < moveVectors.Length; i++)
                    {
                        square = Board.GetSquare(this.Base.Square.Ordinal + moveVectors[i]);

                        if (square != null && (square.Piece != null && (square.Piece.Player.Colour != this.Base.Player.Colour && square.Piece.IsCapturable)))
                        {
                            moves.Add(0, 0, Move.MoveNames.Standard, this.Base, this.Base.Square, square, square.Piece, 0, 0);
                        }
                    }
                    break;
            }
        }