コード例 #1
0
ファイル: Board.cs プロジェクト: tranglq/CoToanVietNam
        //kiem tra quan co mau color thuc hien nuoc di move co the de doa quan 0 ben kia hay khong
        public bool MoveToCheck(int color, Move move)
        {
            int x1, y1, x2, y2;

            x1 = move.x1;
            y1 = move.y1;
            x2 = move.x2;
            y2 = move.y2;

            //gia thiet move la nuoc di hop le
            Board b = new Board();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 11; j++)
                {
                    b.setSquare(this.square[i, j], i, j);
                }
            }

            b.setSquare(b.getInfo(x1, y1), x2, y2);
            b.setSquare(-1, x1, y1);

            quan19 quan_co = new quan19(color, b.getInfo(x2, y2), x2, y2);

            if (color == 1)
            {
                return(quan_co.capture(b, 4, 9));
            }
            else
            {
                return(quan_co.capture(b, 4, 1));
            }
        }
コード例 #2
0
        public int Attack(Board brd, int color)
        {
            int result = 0;

            if (color == 1)
            {
                for (int i = 2; i <= 8; i++)
                {
                    if (brd.getColor(4, i) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(4, i), 4, i);
                        if (i == 8 || quan_minh.move(brd, 4, 8))
                        {
                            result += 10;
                        }
                    }
                }
                for (int i = 0; i <= 3; i++)
                {
                    if (brd.getColor(i, i + 5) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, i + 5), i, i + 5);
                        if (i == 3 || quan_minh.move(brd, 3, 8))
                        {
                            result += 8;
                        }
                    }
                    if (brd.getColor(i, 9) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, 9), i, 9);
                        if (i == 3 || quan_minh.move(brd, 3, 9))
                        {
                            result += 8;
                        }
                    }
                }
                for (int i = 5; i <= 8; i++)
                {
                    if (brd.getColor(i, 13 - i) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, 13 - i), i, 13 - i);
                        if (i == 5 || quan_minh.move(brd, 5, 8))
                        {
                            result += 8;
                        }
                    }
                    if (brd.getColor(i, 9) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, 9), i, 9);
                        if (i == 5 || quan_minh.move(brd, 5, 9))
                        {
                            result += 8;
                        }
                    }
                }
            }
            else
            {
                for (int i = 2; i <= 8; i++)
                {
                    if (brd.getColor(4, i) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(4, i), 4, i);
                        if (i == 2 || quan_minh.move(brd, 4, 2))
                        {
                            result += 10;
                        }
                    }
                }
                for (int i = 0; i <= 3; i++)
                {
                    if (brd.getColor(i, 5 - i) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, 5 - i), i, 5 - i);
                        if (i == 3 || quan_minh.move(brd, 3, 2))
                        {
                            result += 8;
                        }
                    }
                    if (brd.getColor(i, 1) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, 1), i, 1);
                        if (i == 3 || quan_minh.move(brd, 3, 1))
                        {
                            result += 8;
                        }
                    }
                }
                for (int i = 5; i <= 8; i++)
                {
                    if (brd.getColor(i, i - 3) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, i - 3), i, i - 3);
                        if (i == 5 || quan_minh.move(brd, 5, 2))
                        {
                            result += 8;
                        }
                    }
                    if (brd.getColor(i, 1) == color)
                    {
                        quan19 quan_minh = new quan19(color, brd.getInfo(i, 1), i, 1);
                        if (i == 5 || quan_minh.move(brd, 5, 1))
                        {
                            result += 8;
                        }
                    }
                }
            }
            return(result);
        }
コード例 #3
0
ファイル: Board.cs プロジェクト: tranglq/CoToanVietNam
        //tra lai true neu nhu co the phong ngu duoc, false neu nhu het co
        public bool canDefend(int color)
        {
            if (this.isChecked(3 - color))
            {
                return(true);
            }

            int   x1, y1;
            quan0 quan_0 = new quan0(color);

            if (!quan_0.isChecked(this, out x1, out y1))
            {
                return(true);
            }

            if (color == 1)
            {
                if (x1 == 4)
                {
                    //co the phong ngu duoc neu nhu an duoc quan (4, y1) hoac (4, y1-1)
                    //hoac co the di duoc quan vao o nam giua (4,1) va (4,y1-1)
                    for (int i = 0; i < 9; i++)
                    {
                        for (int j = 0; j < 11; j++)
                        {
                            if (this.getInfo(i, j) != -1 && this.getInfo(i, j) < 10 && this.getInfo(i, j) > 0)
                            {
                                quan19 quan_minh = new quan19(1, this.getInfo(i, j), i, j);
                                if (quan_minh.capture(this, 4, y1) || quan_minh.capture(this, 4, y1 - 1))
                                {
                                    return(true);
                                }
                                for (int t = 2; t <= y1 - 2; t++)
                                {
                                    if (quan_minh.move(this, 4, t))
                                    {
                                        return(true);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (y1 == 1)
                    {
                        if (x1 < 3)
                        {
                        }
                        if (x1 > 5)
                        {
                        }
                    }
                    else
                    {
                        if (y1 - x1 == 3)
                        {
                            //chan duoc neu an duoc quan(x1,y1) hoac (x1-1,y1-1)
                            //hoac co the di duoc vao o nam giua (4,1) va (x1-1,y1-1)
                        }
                        else
                        {
                            if (x1 + y1 == 5)
                            {
                                //chan duoc neu an duoc quan (x1,y1) hoac (x1+1,y1-1)
                                //hoac co the di duoc vao o nam giua (x1+1,y1-1) va (4,1)
                            }
                        }
                    }
                }
            }
            if (color == 2)
            {
                if (x1 == 4)
                {
                    //chan duoc neu an duoc quan (4,y1) hoac (4,y1+1)
                    //hoac co the di duoc vao o nam giua (4,y1+1) va (4,9)
                }
                else
                {
                    if (y1 == 9)
                    {
                        if (x1 < 3)
                        {
                        }
                        if (x1 > 5)
                        {
                        }
                    }
                    else
                    {
                        if (y1 - x1 == 5)
                        {
                            //chan duoc neu co the an duoc quan (x1,y1) hoac (x1+1,y1+1)
                            //hoac co the di duoc vao o nam giua (x1+1,y1+1) va (4,9)
                        }
                        else
                        {
                            if (x1 + y1 == 13)
                            {
                                //chan duoc neu co the an duoc quan (x1,y1) hoac (x1-1,y1+1)
                                //hoac co the di duoc vao o nam giua (4,9) va (x1-1, y1+1)
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #4
0
        public bool isChecked(Board b, out int x1, out int y1)
        {
            //cai dat kiem tra quan 0 co dang bi chieu hay khong
            //kiem tra cac quan doi phuong co the an duoc hay khong
            //quan 0 xanh o toa do (4,1) tren Board b
            if (color == 1)
            {
                //kiem tra cot 4, x=4, y=0->10, y!=1, y!=2, y!=0
                for (int i = 3; i < 11; i++)
                {
                    if (b.getInfo(4, i) > 9 && b.getInfo(4, i) != 10)
                    {
                        quan19 quan_doi_phuong = new quan19(2, b.getInfo(4, i) % 10, 4, i);
                        if (quan_doi_phuong.capture(b, 4, 1))
                        {
                            x1 = 4;
                            y1 = i;
                            return(true);
                        }
                    }
                }
                //kiem tra hang 1, y=1, x=0->8, x!=4, x!=3, x!=5
                for (int i = 0; i < 9; i++)
                {
                    if (i != 3 && i != 4 && i != 5 && b.getInfo(i, 1) > 9)
                    {
                        quan19 quan_doi_phuong = new quan19(2, b.getInfo(i, 1) % 10, i, 1);
                        if (quan_doi_phuong.capture(b, 4, 1))
                        {
                            x1 = i;
                            y1 = 1;
                            return(true);
                        }
                    }
                }
                //kiem tra duong cheo chinh va phu, tu o (6,3) den o (8,5), tu o (2,3) den o (0,5)
                for (int i = 3; i <= 5; i++)
                {
                    if (b.getInfo(3 + i, i) > 9)
                    {
                        quan19 quan_doi_phuong = new quan19(2, b.getInfo(3 + i, i) % 10, 3 + i, i);
                        if (quan_doi_phuong.capture(b, 4, 1))
                        {
                            x1 = 3 + i;
                            y1 = i;
                            return(true);
                        }
                    }
                    if (b.getInfo(5 - i, i) > 9)
                    {
                        quan19 quan_doi_phuong = new quan19(2, b.getInfo(5 - i, i) % 10, 5 - i, i);
                        if (quan_doi_phuong.capture(b, 4, 1))
                        {
                            x1 = 5 - i;
                            y1 = i;
                            return(true);
                        }
                    }
                }
            }

            //quan 0 do o vi tri (4,9)
            if (color == 2)
            {
                //kiem tra cot 4, x=4, y=0->10, y!=8, y!=9, y!=10
                for (int i = 0; i <= 7; i++)
                {
                    if (b.getInfo(4, i) < 10 && b.getInfo(4, i) != -1 && b.getInfo(4, i) != 0)
                    {
                        quan19 quan_doi_phuong = new quan19(1, b.getInfo(4, i), 4, i);
                        if (quan_doi_phuong.capture(b, 4, 9))
                        {
                            x1 = 4;
                            y1 = i;
                            return(true);
                        }
                    }
                }
                //kiem tra hang 9, y=1, x=0->8, x!=3, x!=4, x!=5
                for (int i = 0; i < 9; i++)
                {
                    if (i != 3 && i != 4 && i != 5 && b.getInfo(i, 9) < 10 && b.getInfo(i, 9) != -1)
                    {
                        quan19 quan_doi_phuong = new quan19(1, b.getInfo(i, 9), i, 9);
                        if (quan_doi_phuong.capture(b, 4, 9))
                        {
                            x1 = i;
                            y1 = 9;
                            return(true);
                        }
                    }
                }
                //kiem tra duong cheo chinh va phu, tu o (0,5) den o (2,7), tu o (6,7) den o (8,5)
                for (int i = 0; i <= 2; i++)
                {
                    if (b.getInfo(i, i + 5) < 10 && b.getInfo(i, i + 5) != -1)
                    {
                        quan19 quan_doi_phuong = new quan19(1, b.getInfo(i, i + 5), i, i + 5);
                        if (quan_doi_phuong.capture(b, 4, 9))
                        {
                            x1 = i;
                            y1 = i + 5;
                            return(true);
                        }
                    }
                    if (b.getInfo(6 + i, 7 - i) < 10 && b.getInfo(6 + i, 7 - i) != -1)
                    {
                        quan19 quan_doi_phuong = new quan19(1, b.getInfo(6 + i, 7 - i), 6 + i, 7 - i);
                        if (quan_doi_phuong.capture(b, 4, 9))
                        {
                            x1 = 6 + i;
                            y1 = 7 - i;
                            return(true);
                        }
                    }
                }
            }
            x1 = -1;
            y1 = -1;
            return(false);
        }