Beispiel #1
0
        private Move GetMove(string move, int moveNo, bool isWhite)
        {
            Move m = Move.NewMove();

            m.Game                       = this.Game;
            m.MoveNo                     = moveNo;
            m.IsWhite                    = isWhite;
            m.From                       = move.Substring(0, 2);
            m.To                         = move.Substring(2, 2);
            m.Piece                      = Board.PieceFromString(GameWrapper.GetMovingPiece(move));
            m.Flags.IsCapture            = GameWrapper.IsCapturingMove(move);
            m.Flags.IsPromotion          = GameWrapper.IsPromotionMove(move);
            m.Flags.IsLongCastling       = GameWrapper.IsLongCastlingMove(move);
            m.Flags.IsShortCastling      = GameWrapper.IsShortCastlingMove(move);
            m.Flags.IsInCheck            = GameWrapper.IsCheckingMove(move);
            m.Flags.IsMated              = GameWrapper.IsCheckMatingMove(move);
            m.Flags.IsStaleMated         = GameWrapper.IsStaleMatingMove(move);
            m.Flags.IsAmbigousMove       = GameWrapper.IsAmbiguousMove(move);
            m.Flags.IsAmbigousMoveColumn = GameWrapper.IsAmbiguousFile(move);
            m.Flags.IsAmbigousMoveRow    = GameWrapper.IsAmbiguousRank(move);

            if (m.Flags.IsMated)
            {
                m.Flags.IsInCheck = false;
            }

            return(m);
        }
Beispiel #2
0
        private Moves LoadMoves(string pv)
        {
            Moves moves = new Moves(Moves.GetMovesTable());

            try
            {
                GameWrapper.SetFen(fen);

                string[] pvMoves           = pv.Split(" ".ToCharArray());
                int      currentMoveNumber = 1;
                bool     isWhite           = true;
                int      tempMoveNumber    = currentMoveNumber;
                bool     isWhiteMove       = isWhite;
                Move     m;

                foreach (string move in pvMoves)
                {
                    if (string.IsNullOrEmpty(move))
                    {
                        continue;
                    }
                    if (GameWrapper.IsLegalMove(move))
                    {
                        m                            = App.Model.Move.NewMove();
                        m.Game                       = g;
                        m.MoveNo                     = tempMoveNumber;
                        m.IsWhite                    = isWhiteMove;
                        m.From                       = move.Substring(0, 2);
                        m.To                         = move.Substring(2, 2);
                        m.Piece                      = Board.PieceFromString(GameWrapper.GetMovingPiece(move));
                        m.Flags.IsCapture            = GameWrapper.IsCapturingMove(move);
                        m.Flags.IsPromotion          = GameWrapper.IsPromotionMove(move);
                        m.Flags.IsLongCastling       = GameWrapper.IsLongCastlingMove(move);
                        m.Flags.IsShortCastling      = GameWrapper.IsShortCastlingMove(move);
                        m.Flags.IsInCheck            = GameWrapper.IsCheckingMove(move);
                        m.Flags.IsMated              = GameWrapper.IsCheckMatingMove(move);
                        m.Flags.IsStaleMated         = GameWrapper.IsStaleMatingMove(move);
                        m.Flags.IsAmbigousMove       = GameWrapper.IsAmbiguousMove(move);
                        m.Flags.IsAmbigousMoveColumn = GameWrapper.IsAmbiguousFile(move);
                        m.Flags.IsAmbigousMoveRow    = GameWrapper.IsAmbiguousRank(move);

                        if (m.Flags.IsCapture)
                        {
                            m.CapturedPiece = Board.PieceFromString(GameWrapper.GetMovingPiece(move));
                        }
                        if (m.Flags.IsMated)
                        {
                            m.Flags.IsInCheck = false;
                        }
                        GameWrapper.AppendMove(move);

                        moves.DataTable.ImportRow(m.DataRow);

                        isWhiteMove = !isWhiteMove;

                        if (isWhiteMove)
                        {
                            tempMoveNumber++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TestDebugger.Instance.Write(ex);
            }
            return(moves);
        }