コード例 #1
0
ファイル: Chess_Engine.cs プロジェクト: Tubbz-alt/ChessGame-1
        /// <summary>
        /// Find all possible Moves of a Chesspiece in position of a State
        /// </summary>
        /// <param name="arrState"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static ArrayList FindAllPosibleMoves(ChessState[,] arrState, Point pos, eChessSide ownside)
        {
            ArrayList arrMove = new ArrayList();

            switch (arrState[pos.X, pos.Y].Type)
            {
            case eChessPieceType.Bishop:
                arrMove = ChessPiece_Bishop.FindAllPosibleMoves(arrState, pos);
                break;

            case eChessPieceType.King:
                arrMove = ChessPiece_King.FindAllPosibleMoves(arrState, pos, ownside);
                break;

            case eChessPieceType.Knight:
                arrMove = ChessPiece_Knight.FindAllPosibleMoves(arrState, pos);
                break;

            case eChessPieceType.Pawn:
                arrMove = ChessPiece_Pawn.FindAllPosibleMoves(arrState, pos, ownside);
                break;

            case eChessPieceType.Queen:
                arrMove = ChessPiece_Queen.FindAllPosibleMoves(arrState, pos);
                break;

            case eChessPieceType.Rook:
                arrMove = ChessPiece_Rook.FindAllPosibleMoves(arrState, pos);
                break;
            }

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

            ArrayList arr_CanMoves = new ArrayList();

            ChessState[,] NewState = new ChessState[10, 10];
            for (int i = 0; i <= 9; i++)
            {
                for (int j = 0; j <= 9; j++)
                {
                    NewState[i, j] = new ChessState(arrState[i, j].Type, arrState[i, j].Side, arrState[i, j].Moves);
                }
            }

            foreach (ChessMove m in arrMove)
            {
                //If one move that makes king will be checked -> remove
                PredictMove(NewState, m);
                if (Checked(NewState, arrState[pos.X, pos.Y].Side, ownside) == false)
                {
                    arr_CanMoves.Add(m);
                }
                UnPredictMove(NewState, m);
            }

            return(arr_CanMoves);
        }
コード例 #2
0
ファイル: Chess_Engine.cs プロジェクト: Tubbz-alt/ChessGame-1
        /// <summary>
        /// Find all possible Moves of a Chesspiece in position of a State but not check the Chess Rule
        /// </summary>
        /// <param name="arrState"></param>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static ArrayList FindAllPosibleMovesNotRule(ChessState[,] arrState, Point pos, eChessSide ownside)
        {
            ArrayList arrMove = new ArrayList();

            switch (arrState[pos.X, pos.Y].Type)
            {
            case eChessPieceType.Bishop:
                arrMove = ChessPiece_Bishop.FindAllPosibleMoves(arrState, pos);
                break;

            case eChessPieceType.King:
                arrMove = ChessPiece_King.FindAllPosibleMoves(arrState, pos, ownside);
                break;

            case eChessPieceType.Knight:
                arrMove = ChessPiece_Knight.FindAllPosibleMoves(arrState, pos);
                break;

            case eChessPieceType.Pawn:
                arrMove = ChessPiece_Pawn.FindAllPosibleMoves(arrState, pos, ownside);
                break;

            case eChessPieceType.Queen:
                arrMove = ChessPiece_Queen.FindAllPosibleMoves(arrState, pos);
                break;

            case eChessPieceType.Rook:
                arrMove = ChessPiece_Rook.FindAllPosibleMoves(arrState, pos);
                break;
            }


            return(arrMove);
        }
コード例 #3
0
ファイル: Chess_Engine.cs プロジェクト: Tubbz-alt/ChessGame-1
        public static ArrayList FindWhoCheckAndKingPosition(ChessState[,] arrState, eChessSide side, eChessSide ownside)
        {
            ArrayList WhoCheck = new ArrayList();
            ArrayList cantMoves = new ArrayList();
            int       i, j;

            for (i = 1; i < 9; i++)
            {
                for (j = 1; j < 9; j++)
                {
                    if (arrState[i, j].Side != side)
                    {
                        if (arrState[i, j].Type == eChessPieceType.Bishop)
                        {
                            cantMoves = ChessPiece_Bishop.FindAllPosibleMoves(arrState, new Point(i, j));
                        }
                        else if (arrState[i, j].Type == eChessPieceType.King)
                        {
                            cantMoves = ChessPiece_King.FindAllPosibleMoves(arrState, new Point(i, j), ownside);
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Knight)
                        {
                            cantMoves = ChessPiece_Knight.FindAllPosibleMoves(arrState, new Point(i, j));
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Pawn)
                        {
                            cantMoves = ChessPiece_Pawn.FindAllPosibleMoves(arrState, new Point(i, j), ownside);
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Queen)
                        {
                            cantMoves = ChessPiece_Queen.FindAllPosibleMoves(arrState, new Point(i, j));
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Rook)
                        {
                            cantMoves = ChessPiece_Rook.FindAllPosibleMoves(arrState, new Point(i, j));
                        }

                        foreach (ChessMove p in cantMoves)
                        {
                            if (arrState[p.MoveTo.X, p.MoveTo.Y].Side == side && arrState[p.MoveTo.X, p.MoveTo.Y].Type == eChessPieceType.King)
                            {
                                WhoCheck.Add(p);
                                break;
                            }
                        }
                    }
                }
            }

            return(WhoCheck);
        }
コード例 #4
0
ファイル: Chess_Engine.cs プロジェクト: Tubbz-alt/ChessGame-1
        /// <summary>
        /// Check Is that one side is checked?
        /// </summary>
        /// <param name="arrState"></param>
        /// <param name="side"></param>
        /// <returns></returns>
        public static bool Checked(ChessState[,] arrState, eChessSide side, eChessSide ownside)
        {
            int       i, j;
            ArrayList cantMoves = new ArrayList();

            for (i = 1; i < 9; i++)
            {
                for (j = 1; j < 9; j++)
                {
                    if (arrState[i, j].Side != side)
                    {
                        if (arrState[i, j].Type == eChessPieceType.Bishop)
                        {
                            cantMoves = ChessPiece_Bishop.FindAllPosibleMoves(arrState, new Point(i, j));
                        }
                        else if (arrState[i, j].Type == eChessPieceType.King)
                        {
                            cantMoves = ChessPiece_King.FindAllPosibleMoves(arrState, new Point(i, j), ownside);
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Knight)
                        {
                            cantMoves = ChessPiece_Knight.FindAllPosibleMoves(arrState, new Point(i, j));
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Pawn)
                        {
                            cantMoves = ChessPiece_Pawn.FindAllPosibleMoves(arrState, new Point(i, j), ownside);
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Queen)
                        {
                            cantMoves = ChessPiece_Queen.FindAllPosibleMoves(arrState, new Point(i, j));
                        }
                        else if (arrState[i, j].Type == eChessPieceType.Rook)
                        {
                            cantMoves = ChessPiece_Rook.FindAllPosibleMoves(arrState, new Point(i, j));
                        }

                        foreach (ChessMove p in cantMoves)
                        {
                            if (arrState[p.MoveTo.X, p.MoveTo.Y].Side == side && arrState[p.MoveTo.X, p.MoveTo.Y].Type == eChessPieceType.King)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }