예제 #1
0
        public override List<Point> GetNextMoves(ChessBoard board)
        {
            var list = new List<Point>();

            //nước lên bên phải
            if (_point == new Point(3, 0) || _point == new Point(3, 7) || _point.X == 4)
            {
                if (board.CheckPoint(_point.X + 1, _point.Y + 1) * _id <= 0) list.Add(new Point(_point.X + 1, _point.Y + 1));
            }

            //nước lên bên trái
            if (_point == new Point(5, 0) || _point.X == 4 || _point == new Point(5, 7))
            {
                if (board.CheckPoint(_point.X - 1, _point.Y + 1) * _id <= 0) list.Add(new Point(_point.X - 1, _point.Y + 1));
            }

            //nước xuống bên phải
            if (_point.X == 4 || _point == new Point(3, 2) || _point == new Point(3, 9))
            {
                if (board.CheckPoint(_point.X + 1, _point.Y - 1) * _id <= 0) list.Add(new Point(_point.X + 1, _point.Y - 1));
            }

            //nước xuống bên trái
            if (_point.X == 4 || _point == new Point(5, 2) || _point == new Point(5, 9))
            {
                if (board.CheckPoint(_point.X - 1, _point.Y - 1) * _id <= 0) list.Add(new Point(_point.X - 1, _point.Y - 1));
            }

            return list;
        }
예제 #2
0
        public override List<Point> GetNextMoves(ChessBoard board)
        {
            var list = new List<Point>();

            if (_point.Y == 2 || _point.Y == 7)
            {
                if (_point.X != 8)
                {
                    if (board.CheckPoint(_point.X + 1, _point.Y + 1) == 0 && (board.CheckPoint(_point.X + 2, _point.Y + 2) * _id) <= 0)
                        list.Add(new Point(_point.X + 2, _point.Y + 2));
                    if (board.MatrixPosition[_point.X + 1, _point.Y - 1] == 0 && (board.MatrixPosition[_point.X + 2, _point.Y - 2] * _id) <= 0)
                        list.Add(new Point(_point.X + 2, _point.Y - 2));
                }

                if (_point.X != 0)
                {
                    if (board.MatrixPosition[_point.X - 1, _point.Y + 1] == 0 && (board.MatrixPosition[_point.X - 2, _point.Y + 2]*_id) <= 0)
                        list.Add(new Point(_point.X - 2, _point.Y + 2));
                    if (board.MatrixPosition[_point.X - 1, _point.Y - 1] == 0 && (board.MatrixPosition[_point.X - 2, _point.Y - 2] * _id) <= 0)
                        list.Add(new Point(_point.X - 2, _point.Y - 2));
                }
            }
            else if (_point.Y == 0 || _point.Y == 5)
            {
                if (board.MatrixPosition[_point.X - 1, _point.Y + 1] == 0 && (board.MatrixPosition[_point.X - 2, _point.Y + 2] * _id) <= 0)
                    list.Add(new Point(_point.X - 2, _point.Y + 2));
                if (board.MatrixPosition[_point.X + 1, _point.Y + 1] == 0 && (board.MatrixPosition[_point.X + 2, _point.Y + 2] * _id) <= 0)
                    list.Add(new Point(_point.X + 2, _point.Y + 2));
            }
            else if (_point.Y == 4 || _point.Y == 9)
            {
                if (board.MatrixPosition[_point.X + 1, _point.Y - 1] == 0 && (board.MatrixPosition[_point.X + 2, _point.Y - 2] * _id) <= 0)
                    list.Add(new Point(_point.X + 2, _point.Y - 2));
                if (board.MatrixPosition[_point.X - 1, _point.Y - 1] == 0 && (board.MatrixPosition[_point.X - 2, _point.Y - 2] * _id) <= 0)
                    list.Add(new Point(_point.X - 2, _point.Y - 2));
            }
            return list;
        }
예제 #3
0
        /// <summary>
        /// Lấy nước đi kế tiếp
        /// </summary>
        /// <param name="board">bàn cờ</param>
        /// <returns>danh sách vị trí</returns>
        public override List<Point> GetNextMoves(ChessBoard board)
        {
            List<Point> list = new List<Point>();

            //id dương âm xác định hướng tấn công, khởi tạo những quân id > 0 ở trên, < 0 ở dưới
            //xác định tốt không được đi lùi
            if (_id > 0)
            {
                //con tốt nào cũng có nước đi tiến 1 nước trừ _point.Y = 9
                if (_point.Y < 9)
                {
                    if (board.CheckPoint(_point.X, _point.Y + 1) <= 0)
                    {
                        list.Add(new Point(_point.X, _point.Y + 1));
                    }
                }

                //xác định nước đi ngang khi qua sông
                if (_point.Y >= 5)
                {
                    //vị trí trừ x = 8(sát mép phải) thì có thể đi ngang sang phải
                    if (_point.X < 8)
                    {
                        if (board.MatrixPosition[_point.X + 1, _point.Y] <= 0)
                        {
                            list.Add(new Point(_point.X + 1, _point.Y));
                        }
                    }

                    //các vị trí trừ sát mép trái đều có thể đi ngang sang trái
                    if (_point.X > 0)
                    {
                        if (board.MatrixPosition[_point.X - 1, _point.Y] <= 0)
                        {
                            list.Add(new Point(_point.X - 1, _point.Y));
                        }
                    }
                }
            }

            //tương tự với id < 0
            else
            {
                //nước đi tiến với quân có id < 0 là 1 nước giảm tọa độ Y đi 1
                if (_point.Y > 0)
                {

                    if (board.CheckPoint(_point.X, _point.Y - 1) >= 0)
                    {
                        list.Add(new Point(_point.X, _point.Y - 1));
                    }

                }

                //sang sông
                if (_point.Y < 5)
                {
                    //nước đi ngang bên phải
                    if (_point.X < 8)
                    {
                        if (board.MatrixPosition[_point.X + 1, _point.Y] >= 0)
                        {
                            list.Add(new Point(_point.X + 1, _point.Y));
                        }

                    }
                    //nước đi ngang bên trái
                    if (_point.X > 0)
                    {
                        if (board.MatrixPosition[_point.X - 1, _point.Y] >= 0)
                        {
                            list.Add(new Point(_point.X - 1, _point.Y));
                        }

                    }
                }
            }

            return list;
        }
예제 #4
0
        public override List<Point> GetNextMoves(ChessBoard board)
        {
            var list = new List<Point>();

            //quân có id dương
            if (_id > 0)
            {
                //nước tiến 2
                if (_point.Y <= 7)
                {
                    if (_point.X > 0)
                    {
                        if (board.MatrixPosition[_point.X - 1, _point.Y + 2] <= 0 && board.MatrixPosition[_point.X, _point.Y + 1] == 0)
                            list.Add(new Point(_point.X - 1, _point.Y + 2));
                    }

                    if (_point.X < 8)
                    {
                        if (board.MatrixPosition[_point.X + 1, _point.Y + 2] <= 0 && board.MatrixPosition[_point.X, _point.Y + 1] == 0)
                            list.Add(new Point(_point.X + 1, _point.Y + 2));
                    }
                }

                //nước tiến 1
                if (_point.Y <= 8)
                {
                    if (_point.X > 1)
                    {
                        if (board.MatrixPosition[_point.X - 2, _point.Y + 1] <= 0 && board.MatrixPosition[_point.X - 1, _point.Y] == 0)
                            list.Add(new Point(_point.X - 2, _point.Y + 1));
                    }

                    if (_point.X < 7)
                    {
                        if (board.MatrixPosition[_point.X + 2, _point.Y + 1] <= 0 && board.MatrixPosition[_point.X + 1, _point.Y] == 0)
                            list.Add(new Point(_point.X + 2, _point.Y + 1));
                    }
                }

                //nước lùi 1
                if (_point.Y >= 1)
                {
                    if (_point.X > 1)
                    {
                        if (board.MatrixPosition[_point.X - 2, _point.Y - 1] <= 0 && board.MatrixPosition[_point.X - 1, _point.Y] == 0)
                            list.Add(new Point(_point.X - 2, _point.Y - 1));
                    }

                    if (_point.X < 7)
                    {
                        if (board.MatrixPosition[_point.X + 2, _point.Y - 1] <= 0 && board.MatrixPosition[_point.X + 1, _point.Y] == 0)
                            list.Add(new Point(_point.X + 2, _point.Y - 1));
                    }
                }

                //nước lùi 2
                if (_point.Y >= 2)
                {
                    if (_point.X > 0)
                    {
                        if (board.MatrixPosition[_point.X - 1, _point.Y - 2] <= 0 && board.MatrixPosition[_point.X, _point.Y - 1] == 0)
                            list.Add(new Point(_point.X - 1, _point.Y - 2));
                    }

                    if (_point.X < 8)
                    {
                        if (board.MatrixPosition[_point.X + 1, _point.Y - 2] <= 0 && board.MatrixPosition[_point.X, _point.Y - 1] == 0)
                            list.Add(new Point(_point.X + 1, _point.Y - 2));
                    }
                }

            }
            //tương tự
            else
            {
                if (_point.Y <= 7)
                {
                    if (_point.X > 0)
                    {
                        if (board.CheckPoint(_point.X - 1, _point.Y + 2) >= 0 && board.CheckPoint(_point.X, _point.Y + 1) == 0)
                            list.Add(new Point(_point.X - 1, _point.Y + 2));
                    }

                    if (_point.X < 8)
                    {
                        if (board.CheckPoint(_point.X + 1, _point.Y + 2) >= 0 && board.CheckPoint(_point.X, _point.Y + 1) == 0)
                            list.Add(new Point(_point.X + 1, _point.Y + 2));
                    }
                }

                if (_point.Y <= 8)
                {
                    if (_point.X > 1)
                    {
                        if (board.CheckPoint(_point.X - 2, _point.Y + 1) >= 0 && board.CheckPoint(_point.X - 1, _point.Y) == 0)
                            list.Add(new Point(_point.X - 2, _point.Y + 1));
                    }

                    if (_point.X < 7)
                    {
                        if (board.CheckPoint(_point.X + 2, _point.Y + 1) >= 0 && board.CheckPoint(_point.X + 1, _point.Y) == 0)
                            list.Add(new Point(_point.X + 2, _point.Y + 1));
                    }
                }

                if (_point.Y >= 1)
                {
                    if (_point.X > 1)
                    {
                        if (board.CheckPoint(_point.X - 2, _point.Y - 1) >= 0 && board.CheckPoint(_point.X - 1, _point.Y) == 0)
                            list.Add(new Point(_point.X - 2, _point.Y - 1));
                    }

                    if (_point.X <= 6)
                    {
                        if (board.CheckPoint(_point.X + 2, _point.Y - 1) >= 0 && board.CheckPoint(_point.X + 1, _point.Y) == 0)
                            list.Add(new Point(_point.X + 2, _point.Y - 1));
                    }
                }

                if (_point.Y >= 2)
                {
                    if (_point.X > 0)
                    {
                        if (board.CheckPoint(_point.X - 1, _point.Y - 2) >= 0 && board.CheckPoint(_point.X, _point.Y - 1) == 0)
                            list.Add(new Point(_point.X - 1, _point.Y - 2));
                    }

                    if (_point.X < 8)
                    {
                        if (board.CheckPoint(_point.X + 1, _point.Y - 2) >= 0 && board.CheckPoint(_point.X, _point.Y - 1) == 0)
                            list.Add(new Point(_point.X + 1, _point.Y - 2));
                    }
                }
            }
            return list;
        }
예제 #5
0
        public override List<Point> GetNextMoves(ChessBoard board)
        {
            var list = new List<Point>();

            if (_id > 0)
            {
                //có thêm 1 nước đi bên phải nếu x < 5
                if (_point.X < 5)
                {
                    if (board.CheckPoint(_point.X + 1, _point.Y) <= 0) list.Add(new Point(_point.X + 1, _point.Y));
                }

                //có thêm 1 nước đi bên trái nếu x > 3
                if (_point.X > 3)
                {
                    if (board.CheckPoint(_point.X - 1, _point.Y) <= 0)
                        list.Add(new Point(_point.X - 1, _point.Y));
                }

                if (_point.Y > 0)
                {
                    if (board.CheckPoint(_point.X, _point.Y - 1) <= 0)
                        list.Add(new Point(_point.X, _point.Y - 1));
                }

                if (_point.Y < 2)
                {
                    if (board.CheckPoint(_point.X, _point.Y + 1) <= 0)
                        list.Add(new Point(_point.X, _point.Y + 1));
                }
            }
            else
            {
                //có thêm 1 nước đi bên phải nếu x < 5
                if (_point.X < 5)
                {
                    if (board.CheckPoint(_point.X + 1, _point.Y) >= 0) list.Add(new Point(_point.X + 1, _point.Y));
                }

                //có thêm 1 nước đi bên trái nếu x > 3
                if (_point.X > 3)
                {
                    if (board.CheckPoint(_point.X - 1, _point.Y) >= 0)
                        list.Add(new Point(_point.X - 1, _point.Y));
                }

                //nước lùi
                if (_point.Y > 0 || _point.Y > 7 )
                {
                    if (board.CheckPoint(_point.X, _point.Y - 1) >= 0)
                        list.Add(new Point(_point.X, _point.Y - 1));
                }

                //nước tiến
                if (_point.Y < 2 || _point.Y < 9)
                {
                    if (board.CheckPoint(_point.X, _point.Y + 1) >= 0)
                        list.Add(new Point(_point.X, _point.Y + 1));
                }
            }
            return list;
        }