private double GetChessPieceRating(ChessPieceType chessPiece)
        {
            switch (chessPiece)
            {
            case ChessPieceType.King:
                return(0);

            case ChessPieceType.Queen:
                return(9);

            case ChessPieceType.Rook:
                return(5);

            case ChessPieceType.Bishop:
                return(3);

            case ChessPieceType.Knight:
                return(3);

            case ChessPieceType.Pawn:
                return(1);

            default:
                throw new ArgumentOutOfRangeException(nameof(chessPiece), chessPiece, null);
            }
        }
        public async Task <IActionResult> PutChessPieceType([FromRoute] int id, [FromBody] ChessPieceType chessPieceType)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != chessPieceType.ChessPieceTypeId)
            {
                return(BadRequest());
            }

            _context.Entry(chessPieceType).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ChessPieceTypeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#3
0
    private static string GetPgnMove(ChessPieceType pieceType)
    {
        string move = "";

        if (pieceType == ChessPieceType.Bishop)
        {
            move += "B";
        }
        else if (pieceType == ChessPieceType.King)
        {
            move += "K";
        }
        else if (pieceType == ChessPieceType.Knight)
        {
            move += "N";
        }
        else if (pieceType == ChessPieceType.Queen)
        {
            move += "Q";
        }
        else if (pieceType == ChessPieceType.Rook)
        {
            move += "R";
        }

        return(move);
    }
示例#4
0
 public ChessPiece(ChessPieceColor color, ChessPieceType type, Position position, IMovementStrategy movementStrategy)
 {
     Color    = color;
     Type     = type;
     Position = position;
     movement = movementStrategy;
 }
示例#5
0
 public ChessPiece(TeamID teamId, ChessPieceType chessPieceType, int x, int z)
 {
     this.teamId         = teamId;
     this.chessPieceType = chessPieceType;
     this.x = x;
     this.z = z;
 }
示例#6
0
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType promoteTo, ChessMoveType moveType = ChessMoveType.Normal)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     PromoteTo     = promoteTo;
 }
示例#7
0
        private static void GenerateMoves(uint squareFrom, ulong targetBitboard, ChessPieceType pieceType, List <ChessMove> moveList)
        {
            if (pieceType == ChessPieceType.Pawn && ((targetBitboard & Precomputed.Rows[7]) != 0 || (targetBitboard & Precomputed.Rows[0]) != 0))
            {
                while (targetBitboard != 0)
                {
                    uint squareTo = Util.bitScanForward(targetBitboard);

                    ChessMove knightMove = new ChessMove((ChessPositionIndex)squareFrom, (ChessPositionIndex)squareTo, ChessPieceType.Pawn);
                    knightMove.PromotionPieceType = ChessPieceType.Knight;
                    moveList.Add(knightMove);

                    GenerateMove((ChessPositionIndex)squareFrom, (ChessPositionIndex)squareTo, ChessPieceType.Pawn, ChessPieceType.Knight, moveList);
                    GenerateMove((ChessPositionIndex)squareFrom, (ChessPositionIndex)squareTo, ChessPieceType.Pawn, ChessPieceType.Bishop, moveList);
                    GenerateMove((ChessPositionIndex)squareFrom, (ChessPositionIndex)squareTo, ChessPieceType.Pawn, ChessPieceType.Rook, moveList);
                    GenerateMove((ChessPositionIndex)squareFrom, (ChessPositionIndex)squareTo, ChessPieceType.Pawn, ChessPieceType.Queen, moveList);

                    targetBitboard ^= Precomputed.IndexToBitBoard[squareTo];  // Remove the possible square.
                }
            }
            else
            {
                while (targetBitboard != 0)
                {
                    uint squareTo = Util.bitScanForward(targetBitboard);

                    moveList.Add(new ChessMove((ChessPositionIndex)squareFrom, (ChessPositionIndex)squareTo, pieceType));

                    targetBitboard ^= Precomputed.IndexToBitBoard[squareTo];  // Remove the possible square.
                }
            }
        }
示例#8
0
        public static Piece InstantiateNew(ChessPieceType pieceType, PieceTeam team)
        {
            Piece newPiece = InstantiateNew(pieceType);

            newPiece.Team = team;
            return(newPiece);
        }
示例#9
0
        public static char GetPGNNameForPiece(ChessPieceType pieceType, bool useEmptyForPawn)
        {
            switch (pieceType)
            {
            case ChessPieceType.ChessPieceType_Pawn:
                if (useEmptyForPawn)
                {
                    return(PGN_PIECE_PAWN);
                }
                else
                {
                    return(PGN_PIECE_PAWN_EXPLICIT);
                }

            case ChessPieceType.ChessPieceType_Rook:
                return(PGN_PIECE_ROOK);

            case ChessPieceType.ChessPieceType_Knight:
                return(PGN_PIECE_KNIGHT);

            case ChessPieceType.ChessPieceType_Bishop:
                return(PGN_PIECE_BISHOP);

            case ChessPieceType.ChessPieceType_Queen:
                return(PGN_PIECE_QUEEN);

            case ChessPieceType.ChessPieceType_King:
                return(PGN_PIECE_KING);

            default:
                return(PGN_PIECE_UNKNOWN);
            }
        }
示例#10
0
        // ReSharper disable InvertIf
        private static bool PromotePawns(Board board, Piece piece, byte dstPosition, ChessPieceType promoteToPiece)
        {
            if (piece.PieceType == ChessPieceType.Pawn)
            {
                if (dstPosition < 8)
                {
                    board.Squares[dstPosition].Piece.PieceType        = promoteToPiece;
                    board.Squares[dstPosition].Piece.PieceValue       = Piece.CalculatePieceValue(promoteToPiece);
                    board.Squares[dstPosition].Piece.PieceActionValue =
                        Piece.CalculatePieceActionValue(promoteToPiece);
                    return(true);
                }

                if (dstPosition > 55)
                {
                    board.Squares[dstPosition].Piece.PieceType        = promoteToPiece;
                    board.Squares[dstPosition].Piece.PieceValue       = Piece.CalculatePieceValue(promoteToPiece);
                    board.Squares[dstPosition].Piece.PieceActionValue =
                        Piece.CalculatePieceActionValue(promoteToPiece);
                    return(true);
                }
            }

            return(false);
        }
示例#11
0
 protected ChessPiece(Tuple <int, int> position, Player player, ChessPieceType type)
 {
     _startingPosition = position;
     _position         = position;
     _player           = player;
     _type             = type;
 }
示例#12
0
    private ChessPiece SpawnSinglePiece(ChessPieceType type, int team)
    {
        ChessPiece cp = Instantiate(prefabs[(int)type - 1], transform).GetComponent <ChessPiece>();

        cp.type = type;
        cp.team = team;
        if (type == ChessPieceType.Pawn)
        {
            cp.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()[1].material = teamMaterials[team];
            return(cp);
        }
        if (type == ChessPieceType.Rook)
        {
            cp.setScale(0.022f);
            cp.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()[0].material = teamMaterials[team];
            return(cp);
        }

        if (type == ChessPieceType.Bishop)
        {
            cp.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()[0].material = teamMaterials[team];
            cp.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()[1].material = teamMaterials[team];
            cp.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()[2].material = teamMaterials[team];
            cp.gameObject.GetComponentsInChildren <SkinnedMeshRenderer>()[3].material = teamMaterials[team];
            return(cp);
        }

        cp.GetComponent <MeshRenderer>().material = teamMaterials[team];

        return(cp);
    }
示例#13
0
        //Nếu chơi với máy hì máy sẽ chon quân Hậu và không hieern thị form chọn
        //Nếu đóng Form thì mặc định sẽ chọn quân hậu
        public static bool Promotion(UcChessPiece UcPawn, ChessPieceType PromoteTo)
        {
            if ((UcPawn.PositionY == 8) || (UcPawn.PositionY == 1))
            {
                Bitmap queen  = clsImageProcess.GetChessPieceBitMap(UcPawn.Side, ChessPieceType.Queen, UcPawn.Style);
                Bitmap root   = clsImageProcess.GetChessPieceBitMap(UcPawn.Side, ChessPieceType.Rook, UcPawn.Style);
                Bitmap knight = clsImageProcess.GetChessPieceBitMap(UcPawn.Side, ChessPieceType.Knight, UcPawn.Style);
                Bitmap bishop = clsImageProcess.GetChessPieceBitMap(UcPawn.Side, ChessPieceType.Bishop, UcPawn.Style);

                if (PromoteTo == ChessPieceType.Null)
                {
                    Form f = new frmPromotion(queen, root, knight, bishop);
                    f.ShowDialog();
                    UcPawn.Type = frmPromotion.Type;
                }
                else
                {
                    UcPawn.Type = PromoteTo;
                }
                Bitmap image = clsImageProcess.GetChessPieceBitMap(UcPawn.Side, UcPawn.Type, UcPawn.Style);
                UcPawn.Image = image;
                return(true);
            }
            return(false);
        }
示例#14
0
 public ChessPieceData(string _playerId, int _id, ChessPieceType _type, Side _color)
 {
     PlayerId     = _playerId;
     ChessPieceId = _id;
     Type         = _type;
     Color        = _color;
 }
示例#15
0
 public PieceTaken(ChessPieceType pieceType)
 {
     PieceColor = ChessPieceColor.White;
     PieceType  = pieceType;
     Position   = 0;
     Moved      = false;
 }
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType piece)
 {
     StartPosition = start;
     EndPosition   = end;
     PromotePiece  = piece;
     MoveType      = ChessMoveType.PawnPromote;
 }
示例#17
0
 public PieceTaken(ChessPieceColor pieceColor, ChessPieceType pieceType, bool moved, byte position)
 {
     this.PieceColor = pieceColor;
     this.PieceType  = pieceType;
     this.Position   = position;
     this.Moved      = moved;
 }
示例#18
0
 public PieceTaken(ChessPieceType pieceType)
 {
     this.PieceColor = ChessPieceColor.White;
     this.PieceType  = pieceType;
     this.Position   = (byte)0;
     this.Moved      = false;
 }
示例#19
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            ChessPieceType type   = (ChessPieceType)values[0];
            int            player = (int)values[1];

            String color = player == 1 ? "White" : "Black";

            try {
                if (type == ChessPieceType.Queen)
                {
                    return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.View;component/Resources/" + color + "Queen.png", UriKind.Relative)));
                }
                else if (type == ChessPieceType.Knight)
                {
                    return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.View;component/Resources/" + color + "Knight.png", UriKind.Relative)));
                }
                else if (type == ChessPieceType.Bishop)
                {
                    return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.View;component/Resources/" + color + "Bishop.png", UriKind.Relative)));
                }
                else if (type == ChessPieceType.RookKing || type == ChessPieceType.RookQueen || type == ChessPieceType.RookPawn)
                {
                    return(new BitmapImage(new Uri("/Cecs475.BoardGames.Chess.View;component/Resources/" + color + "Rook.png", UriKind.Relative)));
                }
                else
                {
                    return(null);
                }
            } catch (Exception e) {
                return(null);
            }
        }
示例#20
0
 public ChessPiece(int x, int y, ChessPieceType p, ref BoardState[,] board)
 {
     xCoord      = x;
     yCoord      = y;
     piece       = p;
     board[x, y] = BoardState.Filled;
 }
示例#21
0
        ///// <summary>
        ///// Trả về độ di động của phe ta trừ phe địch
        ///// </summary>
        //static int Mobility(int[,] BoardState)
        //{

        //    int intSide = 0;
        //    if (Myside == ChessSide.White)
        //    {
        //        intSide = 2;
        //    }
        //    else
        //    {
        //        intSide = 1;
        //    }
        //    int intMobility = 0;
        //    for (int y = 1; y <= 8; y++)
        //        for (int x = 1; x <= 8; x++)
        //            if (BoardState[x, y] > 0)
        //            {
        //                int side = BoardState[x, y] % 10;

        //                int intType = BoardState[x, y] / 10;
        //                if (side == intSide)
        //                {
        //                    intMobility += FindAllLegalMove(BoardState, new Point(x, y), (ChessPieceType)intType).Count;
        //                }
        //                else
        //                {
        //                    intMobility -= FindAllLegalMove(BoardState, new Point(x, y), (ChessPieceType)intType).Count;
        //                }
        //            }
        //    return intMobility;
        //}

        public static ArrayList FindAllLegalMove(int[,] arrState, Point CurPos, ChessPieceType eType)
        {
            ArrayList arrPossibleMove = FindAllPossibleMove(arrState, CurPos, eType);

            if (arrPossibleMove.Count == 0)
            {
                return(arrPossibleMove);
            }

            ArrayList arrLegalMove = new ArrayList();

            //Những nước đi làm cho quân Vua phe mình bị chiếu được xem là không hợp lệ
            int[,] arrNewState = new int[10, 10];
            Array.Copy(arrState, arrNewState, arrState.Length);
            ChessSide eSide = (ChessSide)(arrState[CurPos.X, CurPos.Y] % 10);

            foreach (Point p in arrPossibleMove)
            {
                int tmp = arrNewState[p.X, p.Y];                                //Quân cờ tại vị trí mới
                arrNewState[p.X, p.Y]           = (int)eType * 10 + (int)eSide; //Thay quân cờ tại vị trí mới
                arrNewState[CurPos.X, CurPos.Y] = 0;                            //Xóa quân cờ tại vị trí cũ

                if (clsKing.IsChecked(arrNewState, eSide) == false)
                {
                    arrLegalMove.Add(p);
                }
                arrNewState[CurPos.X, CurPos.Y] = arrNewState[p.X, p.Y]; //Cho quân cờ quay lại vị trí cũ
                arrNewState[p.X, p.Y]           = tmp;                   //Trả lại quân cờ nằm ở vị trí mới
            }
            return(arrLegalMove);
        }
示例#22
0
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType promoType, ChessMoveType moveType = ChessMoveType.PawnPromote)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     PromoType     = promoType;
 }
示例#23
0
        public static Piece InstantiateNew(ChessPieceType pieceType)
        {
            switch (pieceType)
            {
            case ChessPieceType.Pawn:
                return(new PiecePawn());

            case ChessPieceType.Rook:
                return(new PieceRook());

            case ChessPieceType.Bishop:
                return(new PieceBishop());

            case ChessPieceType.Knight:
                return(new PieceKnight());

            case ChessPieceType.Queen:
                return(new PieceQueen());

            case ChessPieceType.King:
                return(new PieceKing());

            case ChessPieceType.None:
            default:
                throw new System.ArgumentException($"Invalid piece to instantiate ({pieceType}).", nameof(pieceType));
            }
        }
示例#24
0
        /// <summary>
        /// Applies a move for the current player at the given position.
        /// </summary>
        public async Task ApplyMove(BoardPosition start, BoardPosition end, ChessPieceType cpt)
        {
            foreach (var move in mBoard.GetPossibleMoves())
            {
                if (move.StartPosition.Equals(start) & move.EndPosition.Equals(end))
                {
                    if(move.PromotionPiece != ChessPieceType.Empty & move.PromotionPiece == cpt | move.PromotionPiece == ChessPieceType.Empty)
                    {
                        mBoard.ApplyMove(move);
                        break;
                    }
                }
            }

            if (Players == NumberOfPlayers.One && !mBoard.IsFinished)
            {
                var bestMove = await Task.Run(() => mGameAi.FindBestMove(mBoard));
                if (bestMove != null)
                {
                    mBoard.ApplyMove(bestMove as ChessMove);
                }
            }

            RebindState();

            if (mBoard.IsFinished)
                GameFinished?.Invoke(this, new EventArgs());
        }
示例#25
0
        private IEnumerable <Tuple <int, int> > findPiecePossibilities(ChessPieceType type, int tox, int toy, bool takePiece)
        {
            switch (type)
            {
            case ChessPieceType.King:
                return(findKingPossibilities(tox, toy, takePiece));

            case ChessPieceType.Queen:
                return(findQueenPossibilities(tox, toy, takePiece));

            case ChessPieceType.Bishop:
                return(findBishopPossibilities(tox, toy, takePiece));

            case ChessPieceType.Rook:
                return(findRookPossibilities(tox, toy, takePiece));

            case ChessPieceType.Knight:
                return(findKnightPossibilities(tox, toy, takePiece));

            case ChessPieceType.Pawn:
                return(findPawnPossibilities(tox, toy, takePiece));

            default:
                throw new ArgumentException(nameof(type));
            }
        }
示例#26
0
        /// <summary>
        /// Constructs a ChessMove that moves a piece from one position to another
        /// </summary>
        /// <param name="start">the starting position of the piece to move</param>
        /// <param name="end">the position where the piece will end up</param>
        /// <param name="moveType">the type of move represented</param>
        /// <param name="pieceType">the piece to replace pawn during promotion</param>

        public ChessMove(BoardPosition start, BoardPosition end, ChessMoveType moveType = ChessMoveType.Normal, ChessPieceType pieceType = ChessPieceType.Empty)
        {
            StartPosition  = start;
            EndPosition    = end;
            MoveType       = moveType;
            PromotionPiece = pieceType;
        }
 public string human_readble(ChessPieceType t)
 {
     if (t == ChessPieceType.King)
     {
         return("king");
     }
     else if (t == ChessPieceType.Bishop)
     {
         return("bishop");
     }
     else if (t == ChessPieceType.Knight)
     {
         return("knight");
     }
     else if (t == ChessPieceType.Queen)
     {
         return("queen");
     }
     else if (t == ChessPieceType.Pawn)
     {
         return("pawn");
     }
     else if (t == ChessPieceType.RookKing || t == ChessPieceType.RookKing || t == ChessPieceType.RookQueen)
     {
         return("rook");
     }
     else
     {
         return(null);
     }
 }
示例#28
0
        public static Piece ReplacePiece(Piece p, ChessPieceType newType)
        {
            var newPiece = Create(newType, p.Color);

            Object.Destroy(p.gameObject);
            return(newPiece);
        }
示例#29
0
 internal PieceTaken(ChessPieceType pieceType)
 {
     PieceColor = ChessPieceColor.White;
     PieceType = pieceType;
     Position = 0;
     Moved = false;
 }
示例#30
0
        /// <summary>
        /// Gets the value weight for a piece of the given type.
        /// </summary>

        /*
         * VALUES:
         * Pawn: 1
         * Knight: 3
         * Bishop: 3
         * Rook: 5
         * Queen: 9
         * King: infinity (maximum integer value)
         */
        public int GetPieceValue(ChessPieceType pieceType)
        {
            if (pieceType == ChessPieceType.Pawn)
            {
                return(1);
            }
            else if (pieceType == ChessPieceType.Knight || pieceType == ChessPieceType.Bishop)
            {
                return(3);
            }
            else if (pieceType == ChessPieceType.RookKing || pieceType == ChessPieceType.RookQueen || pieceType == ChessPieceType.RookPawn)
            {
                return(5);
            }
            else if (pieceType == ChessPieceType.Queen)
            {
                return(9);
            }
            else if (pieceType == ChessPieceType.King)
            {
                return(int.MaxValue);
            }
            else
            {
                return(0);
            }
        }
示例#31
0
        public static ChessPiece LuoZiMsgToChessPiece(string msg)
        {
            string[]       tmp    = msg.Split(new char[] { '|' });
            int            boardX = int.Parse(tmp[0].Trim());
            int            boardY = int.Parse(tmp[1].Trim());
            ChessPieceType color  = ChessPieceType.None;

            switch (msg)
            {
            case "White":
                color = ChessPieceType.White;
                break;

            case "Black":
                color = ChessPieceType.Black;
                break;

            default:
                color = ChessPieceType.None;
                break;
            }
            ChessPiece result = new ChessPiece(boardX, boardY, color);

            return(result);
        }
示例#32
0
 internal PieceTaken(ChessPieceColor pieceColor, ChessPieceType pieceType, bool moved,
                   byte position)
 {
     PieceColor = pieceColor;
     PieceType = pieceType;
     Position = position;
     Moved = moved;
 }
示例#33
0
 public PieceMoving(PieceMoving pieceMoving)
 {
     PieceColor = pieceMoving.PieceColor;
     PieceType = pieceMoving.PieceType;
     SrcPosition = pieceMoving.SrcPosition;
     DstPosition = pieceMoving.DstPosition;
     Moved = pieceMoving.Moved;
 }
示例#34
0
 public PieceMoving(ChessPieceType pieceType)
 {
     PieceType = pieceType;
     PieceColor = ChessPieceColor.White;
     SrcPosition = 0;
     DstPosition = 0;
     Moved = false;
 }
示例#35
0
 public PieceMoving(ChessPieceColor pieceColor, ChessPieceType pieceType, bool moved,
                    byte srcPosition, byte dstPosition)
 {
     PieceColor = pieceColor;
     PieceType = pieceType;
     SrcPosition = srcPosition;
     DstPosition = dstPosition;
     Moved = moved;
 }
示例#36
0
        internal Piece(Piece piece)
        {
            PieceColor = piece.PieceColor;
            PieceType = piece.PieceType;
            Moved = piece.Moved;
            PieceValue = piece.PieceValue;
            PieceActionValue = piece.PieceActionValue;

            if (piece.ValidMoves != null)
                LastValidMoveCount = piece.ValidMoves.Count;
        }
示例#37
0
        public ChessPiece(ChessPiece piece)
        {
            Identifier = piece.Identifier;
            PieceColor = piece.PieceColor;
            PieceValue = piece.PieceValue;
            PieceActionValue = piece.PieceActionValue;
            Moved = piece.Moved;

            if (piece.ValidMoves != null)
                LastValidMoveCount = piece.ValidMoves.Count;
        }
示例#38
0
        public ChessPiece(ChessPieceType id, byte number, bool isBlack)
        {
            this.Identifier = id;
            if (isBlack) this.PieceColor = ChessPieceColor.Black;
            else this.PieceColor = ChessPieceColor.White;
            this.Moved = false;
            this.LastValidMoveCount = 0;
            this.ValidMoves = new Stack<byte>();

            PieceValue = CalculatePieceValue(id);
            PieceActionValue = CalculatePieceActionValue(id);
        }
示例#39
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChessPiece"/> class.
        /// </summary>
        /// <param name="type">The chess piece type.</param>
        /// <param name="character">The chess piece character.</param>
        /// <param name="row">The row-position on the chessboard.</param>
        /// <param name="col">The col-position on the chessboard.</param>
        public ChessPiece(ChessPieceType type, char character, int row, int col)
        {
            if (char.IsWhiteSpace(character))
            {
                throw new ArgumentException("character cannot be whitespace.", "character");
            }

            this.Character = character;
            this.Type = type;
            this.Row = row;
            this.Col = col;
        }
示例#40
0
        internal Piece(ChessPieceType chessPiece, ChessPieceColor chessPieceColor)
        {
            PieceType = chessPiece;
            PieceColor = chessPieceColor;

            if (PieceType == ChessPieceType.Pawn || PieceType == ChessPieceType.Knight)
            {
                LastValidMoveCount = 2;
            }
            else
            {
                LastValidMoveCount = 0;
            }

            ValidMoves = new Stack<byte>(LastValidMoveCount);

            PieceValue = CalculatePieceValue(PieceType);
            PieceActionValue = CalculatePieceActionValue(PieceType);
        }
示例#41
0
        private static short CalculatePieceActionValue(ChessPieceType pieceType)
        {
            switch (pieceType)
            {
                case ChessPieceType.Pawn:
                    {
                        return 6;

                    }
                case ChessPieceType.Knight:
                    {
                        return 3;
                    }
                case ChessPieceType.Bishop:
                    {
                        return 3;
                    }
                case ChessPieceType.Rook:
                    {
                        return 2;
                    }

                case ChessPieceType.Queen:
                    {
                        return 1;
                    }

                case ChessPieceType.King:
                    {
                        return 1;
                    }
                default:
                    {
                        return 0;
                    }
            }
        }
示例#42
0
        internal static string GetPieceTypeShort(ChessPieceType pieceType)
        {
            switch (pieceType)
            {
                case ChessPieceType.Pawn:
                    {
                        return "P";
                    }
                case ChessPieceType.Knight:
                    {
                        return "N";
                    }
                case ChessPieceType.Bishop:
                    {
                        return "B";
                    }
                case ChessPieceType.Rook:
                    {
                        return "R";
                    }

                case ChessPieceType.Queen:
                    {
                        return "Q";
                    }

                case ChessPieceType.King:
                    {
                        return "K";
                    }
                default:
                    {
                        return "P";
                    }
            }
        }
示例#43
0
        private static string GetPgnMove(ChessPieceType pieceType)
        {
            switch (pieceType)
            {
                case ChessPieceType.Bishop:
                    return "B";

                case ChessPieceType.King:
                    return "K";

                case ChessPieceType.Knight:
                    return "N";

                case ChessPieceType.Queen:
                    return "Q";

                case ChessPieceType.Rook:
                    return "R";
                default:
                    return "";
            }
        }
示例#44
0
        private static short CalculatePieceValue(ChessPieceType pieceType)
        {
            switch (pieceType)
            {
                case ChessPieceType.Pawn:
                    {
                        return 100;

                    }
                case ChessPieceType.Knight:
                    {
                        return 320;
                    }
                case ChessPieceType.Bishop:
                    {
                        return 325;
                    }
                case ChessPieceType.Rook:
                    {
                        return 500;
                    }

                case ChessPieceType.Queen:
                    {
                        return 975;
                    }

                case ChessPieceType.King:
                    {
                        return 32767;
                    }
                default:
                    {
                        return 0;
                    }
            }
        }
 public ChessPiece(ChessPieceColor color, ChessPieceType type)
 {
     this.color = color;
     this.type = type;
 }
 public ChessMove(Coordinate from, Coordinate to, ChessPieceType pieceType, bool isCapture, bool isPromotionToQueen, bool drawOfferExtended, bool isCheck, bool isCheckMate, bool kingsideCastle, bool queensideCastle)
 {
     this.from = from;
     this.to = to;
     this.pieceType = pieceType;
     this.isCapture = isCapture;
     this.isPromotionToQueen = isPromotionToQueen;
     this.drawOfferExtended = drawOfferExtended;
     this.isCheck = isCheck;
     this.isCheckMate = isCheckMate;
     this.kingsideCastle = kingsideCastle;
     this.queensideCastle = queensideCastle;
 }
示例#47
0
 internal static bool PromotePawns(ChessBoard board, ChessPiece piece, byte dstPosition, ChessPieceType promoteToPiece)
 {
     if (piece.Identifier == ChessPieceType.Pawn)
     {
         if (dstPosition < 8)
         {
             board.pieces[dstPosition].Identifier = promoteToPiece;
             return true;
         }
         if (dstPosition > 55)
         {
             board.pieces[dstPosition].Identifier = promoteToPiece;
             return true;
         }
     }
     return false;
 }
示例#48
0
        internal static MoveContent MovePiece(Board board, byte srcPosition, byte dstPosition, ChessPieceType promoteToPiece)
        {
            Piece piece = board.Squares[srcPosition].Piece;

            //Record my last move
            board.LastMove = new MoveContent();

            //Add One to FiftyMoveCount to check for tie.
            board.FiftyMove++;

            if (piece.PieceColor == ChessPieceColor.Black)
            {
                board.MoveCount++;
            }

            //En Passant
            if (board.EnPassantPosition > 0)
            {
                board.LastMove.EnPassantOccured = SetEnpassantMove(board, dstPosition, piece.PieceColor);
            }

            if (!board.LastMove.EnPassantOccured)
            {
                Square sqr = board.Squares[dstPosition];

                if (sqr.Piece != null)
                {
                    board.LastMove.TakenPiece = new PieceTaken(sqr.Piece.PieceColor, sqr.Piece.PieceType,
                                                               sqr.Piece.Moved, dstPosition);
                    board.FiftyMove = 0;
                }
                else
                {
                    board.LastMove.TakenPiece = new PieceTaken(ChessPieceColor.White, ChessPieceType.None, false,
                                                               dstPosition);

                }
            }

            board.LastMove.MovingPiecePrimary = new PieceMoving(piece.PieceColor, piece.PieceType, piece.Moved, srcPosition, dstPosition);

            //Delete the piece in its source position
            board.Squares[srcPosition].Piece = null;

            //Add the piece to its new position
            piece.Moved = true;
            piece.Selected = false;
            board.Squares[dstPosition].Piece = piece;

            //Reset EnPassantPosition
            board.EnPassantPosition = 0;

            //Record En Passant if Pawn Moving
            if (piece.PieceType == ChessPieceType.Pawn)
            {
               board.FiftyMove = 0;
               RecordEnPassant(piece.PieceColor, piece.PieceType, board, srcPosition, dstPosition);
            }

            board.WhoseMove = board.WhoseMove == ChessPieceColor.White ? ChessPieceColor.Black : ChessPieceColor.White;

            KingCastle(board, piece, srcPosition, dstPosition);

            //Promote Pawns
            if (PromotePawns(board, piece, dstPosition, promoteToPiece))
            {
                board.LastMove.PawnPromoted = true;
            }
            else
            {
                board.LastMove.PawnPromoted = false;
            }

            if ( board.FiftyMove >= 50)
            {
                board.StaleMate = true;
            }

            return board.LastMove;
        }
示例#49
0
        private static bool PromotePawns(Board board, Piece piece, byte dstPosition, ChessPieceType promoteToPiece)
        {
            if (piece.PieceType == ChessPieceType.Pawn)
            {
                if (dstPosition < 8)
                {
                    board.Squares[dstPosition].Piece.PieceType = promoteToPiece;
                    return true;
                }
                if (dstPosition > 55)
                {
                    board.Squares[dstPosition].Piece.PieceType = promoteToPiece;
                    return true;
                }
            }

            return false;
        }
示例#50
0
        private static void RecordEnPassant(ChessPieceColor pcColor, ChessPieceType pcType, Board board, byte srcPosition, byte dstPosition)
        {
            //Record En Passant if Pawn Moving
            if (pcType == ChessPieceType.Pawn)
            {
                //Reset FiftyMoveCount if pawn moved
                board.FiftyMove = 0;

                int difference = srcPosition - dstPosition;

                if (difference == 16 || difference == -16)
                {
                    board.EnPassantPosition = (byte)(dstPosition + (difference / 2));
                    board.EnPassantColor = pcColor;
                }
            }
        }
        private void SetChessPieceCount(ChessPieceColor color, ChessPieceType type, int count)
        {
            string canvasPropertyName = string.Format("{0}Player{1}", color, type);
            string textCountPropertyName = string.Format("{0}Player{1}Count", color, type);
            var canvasProperty = GetType().GetTypeInfo().GetDeclaredProperty(canvasPropertyName);
            var textCountcanvasProperty = GetType().GetTypeInfo().GetDeclaredProperty(textCountPropertyName);

            if (canvasProperty != null && textCountcanvasProperty != null)
                SetChessPieceCount((Canvas)canvasProperty.GetValue(this), (TextBlock)textCountcanvasProperty.GetValue(this), count);
        }
示例#52
0
        internal static MoveContent MoveContent(ChessBoard board, byte srcPosition, byte dstPosition, ChessPieceType promoteToPiece)
        {
            ChessPiece piece = board.pieces[srcPosition];

            //Record my last move
            board.LastMove = new MoveContent();

            //Add One to FiftyMoveCount to check for tie.
            ++board.FiftyMove;

            if (piece.PieceColor == ChessPieceColor.Black)
            {
                ++board.MoveCount;
            }

            //En Passant
            if (board.EnPassantPosition > 0)
            {
                board.LastMove.EnPassantOccured = ChessEngine.SetEnpassantMove(board, dstPosition, piece.PieceColor);
            }

            if (!board.LastMove.EnPassantOccured)
            {
                ChessPiece dstPiece = board.pieces[dstPosition];
                if (dstPiece != null)
                {
                    board.LastMove.TakenPiece = new PieceTaken(dstPiece.PieceColor, dstPiece.Identifier,
                                                               dstPiece.Moved, dstPosition);
                    board.FiftyMove = 0;
                }
                else
                {
                    board.LastMove.TakenPiece = new PieceTaken(ChessPieceColor.White, ChessPieceType.None, false,
                                                               dstPosition);
                }
            }

            board.LastMove.MovingPiecePrimary = new PieceMoving(piece.PieceColor, piece.Identifier, piece.Moved, srcPosition, dstPosition);

            //Delete the piece in its source position
            board.pieces[srcPosition] = null;

            //Add the piece to its new position
            piece.Moved = true;
            board.pieces[dstPosition] = piece;

            //Reset EnPassantPosition
            board.EnPassantPosition = 0;

            //Record En Passant if Pawn Moving
            if (piece.Identifier == ChessPieceType.Pawn)
            {
                board.FiftyMove = 0;
                ChessEngine.RecordEnPassant(board, piece.PieceColor, piece.Identifier, srcPosition, dstPosition);
            }

            board.WhoseMove = board.WhoseMove == ChessPieceColor.White ? ChessPieceColor.Black : ChessPieceColor.White;

            ChessEngine.KingCastle(board, piece, srcPosition, dstPosition);

            //Promote Pawns
            if (ChessEngine.PromotePawns(board, piece, dstPosition, promoteToPiece))
            {
                board.LastMove.PawnPromoted = true;
            }
            else
            {
                board.LastMove.PawnPromoted = false;
            }

            if (board.FiftyMove >= 50)
            {
                board.staleMate = true;
            }

            return board.LastMove;
        }