Beispiel #1
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);
        }
Beispiel #2
0
        //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);
        }