예제 #1
0
        private void CheckLoop(ref List <Point> arrPossibleMove, int v1, int v2)
        {
            BoardData board = BoardData.GetInstance();
            int       x     = Position.X;
            int       y     = Position.Y;

            while (true)
            {
                x += v1;
                y += v2;
                if (!board.CheckPositionInBoard(x, y))
                {
                    return;
                }
                if (board[x, y] == null)
                {
                    arrPossibleMove.Add(new Point(x, y));
                }
                else
                {
                    if (board[x, y].Side != Side)
                    {
                        arrPossibleMove.Add(new Point(x, y));
                    }
                    return;
                }
            }
        }
예제 #2
0
        public override List <Point> GetPossibleMove()
        {
            List <Point> ArrPossibleMove = new List <Point>();
            BoardData    board           = BoardData.GetInstance();

            int[] dx = new int[8] {
                2, 2, 1, 1, -1, -1, -2, -2
            };
            int[] dy = new int[8] {
                -1, 1, -2, 2, 2, -2, 1, -1
            };
            for (int i = 0; i < 8; i++)
            {
                Point newPos = new Point(this.Position.X + dx[i], this.Position.Y + dy[i]);
                if (board.CheckPositionInBoard(newPos.X, newPos.Y))
                {
                    Piece piece = board[newPos];
                    if (piece == null || piece.Side != this.Side)
                    {
                        ArrPossibleMove.Add(newPos);
                    }
                }
            }

            return(ArrPossibleMove);
        }
예제 #3
0
        public void Config(bool firstCall, BoardData board, PieceSide turn)
        {
            if (firstCall)
            {
                AI.GetInstance().UpdateFirstCall(false);
                Grid = new piece_t[Const.RowCount][];
                for (int i = 0; i < Const.RowCount; i++)
                {
                    Grid[i] = new piece_t[Const.ColCount];
                    for (int j = 0; j < Const.ColCount; j++)
                    {
                        if (board.ArrPiece[j, i] != null)
                        {
                            Grid[i][j] = new piece_t(board.ArrPiece[j, i].Type, board.ArrPiece[j, i].Side);
                        }
                        else
                        {
                            Grid[i][j] = new piece_t(PieceType.None, PieceSide.White);
                        }
                    }
                }

                LastMove = new Dictionary <PieceSide, Position>();
                LastMove[PieceSide.Black] = new Position();
                LastMove[PieceSide.White] = new Position();
                Kings  = new Dictionary <PieceSide, Position>();
                Pieces = new Dictionary <PieceSide, List <Position> >();
                List <Position> blackPos = new List <Position>();
                List <Position> whitePos = new List <Position>();

                for (int i = 0; i < Const.RowCount; i++)
                {
                    for (int j = 0; j < Const.ColCount; j++)
                    {
                        Piece temp = BoardData.GetInstance().ArrPiece[j, i];
                        if (temp != null)
                        {
                            if (temp.Side == PieceSide.Black)
                            {
                                if (temp.Type == PieceType.King)
                                {
                                    Kings[PieceSide.Black] = new Position(temp.Position.X, temp.Position.Y);
                                }
                                blackPos.Add(new Position(temp.Position.X, temp.Position.Y));
                            }
                            else
                            {
                                if (temp.Type == PieceType.King)
                                {
                                    Kings[PieceSide.White] = new Position(temp.Position.X, temp.Position.Y);
                                }
                                whitePos.Add(new Position(temp.Position.X, temp.Position.Y));
                            }
                        }
                    }
                }
                Pieces.Add(PieceSide.Black, blackPos);
                Pieces.Add(PieceSide.White, whitePos);
            }
        }
예제 #4
0
        public override bool IsAvailableMove(Point des)
        {
            int dx = des.X - Position.X;
            int dy = des.Y - Position.Y;

            if (Math.Abs(dx) != Math.Abs(dy))
            {
                return(false);
            }
            dx = dx / Math.Abs(dx);
            dy = dy / Math.Abs(dy);

            BoardData board = BoardData.GetInstance();
            int       x     = Position.X;
            int       y     = Position.Y;

            while (true)
            {
                x += dx;
                y += dy;
                if (x == des.X && y == des.Y)
                {
                    break;
                }
                if (board[x, y] != null)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #5
0
        public override bool IsAvailableMove(Point des)
        {
            BoardData board = BoardData.GetInstance();

            if (!board.CheckPositionInBoard(des.X, des.Y))
            {
                return(false);
            }

            //Nếu là nước tấn công: ô tấn công phải có quân và là quân khác phe
            if (des.Y - this.Position.Y == signDirection && Math.Abs(des.X - this.Position.X) == 1)
            {
                Piece piece = board[des];
                if (piece != null && piece.Side != this.Side)
                {
                    return(true);
                }
                return(false);
            }

            //Nếu là nước di chuyển: ô đó phải trống và nằm trong vùng đi được
            if (des.X == this.Position.X && board[des] == null)
            {
                if (this.IsMoved)
                {
                    return(des.Y - Position.Y == signDirection);
                }
                else
                {
                    return((des.Y - Position.Y) / signDirection <= 2 && (des.Y - Position.Y) / signDirection >= 1);
                }
            }

            return(false);
        }
예제 #6
0
        public override bool IsAvailableMove(Point des)
        {
            BoardData board = BoardData.GetInstance();

            if (!board.CheckPositionInBoard(des.X, des.Y))
            {
                return(false);
            }
            return(Math.Abs(des.X - Position.X) + Math.Abs(des.Y - Position.Y) == 3);
        }
예제 #7
0
        public override bool IsAvailableMove(Point des)
        {
            BoardData board = BoardData.GetInstance();

            if (!board.CheckPositionInBoard(des.X, des.Y))
            {
                return(false);
            }
            int dx  = Math.Abs(des.X - Position.X);
            int dy  = Math.Abs(des.Y - Position.Y);
            int sum = dx * dx + dy * dy;

            return(dx + dy <= 2 && sum != 0);
        }
예제 #8
0
        public override List <Point> GetPossibleMove()
        {
            List <Point> ArrPossibleMove = new List <Point>();
            BoardData    board           = BoardData.GetInstance();

            int          dy         = signDirection * 1;
            List <Point> listMoveBy = new List <Point>()
            {
                new Point(0, 1 * signDirection),
            };

            if (!this.IsMoved && board[this.Position.X, this.Position.Y + signDirection] == null)
            {
                listMoveBy.Add(new Point(0, 2 * signDirection));
            }

            List <Point> listAttackBy = new List <Point>()
            {
                new Point(-1, 1 * signDirection),
                new Point(1, 1 * signDirection),
            };

            foreach (Point p in listMoveBy)
            {
                Point newPos = new Point(Position.X + p.X, Position.Y + p.Y);
                if (board.CheckPositionInBoard(newPos.X, newPos.Y))
                {
                    Piece piece = board[newPos];
                    if (piece == null)
                    {
                        ArrPossibleMove.Add(newPos);
                    }
                }
            }

            foreach (Point p in listAttackBy)
            {
                Point newPos = new Point(Position.X + p.X, Position.Y + p.Y);
                if (board.CheckPositionInBoard(newPos.X, newPos.Y))
                {
                    Piece piece = board[newPos];
                    if (piece != null && piece.Side != this.Side)
                    {
                        ArrPossibleMove.Add(newPos);
                    }
                }
            }

            return(ArrPossibleMove);
        }