示例#1
0
 void setFox(Fox fox, int x, int y)
 {
     fox.x = x;
     fox.y = y;
     // заменяется по последним координатам лисы в самом длинном ходу
     area[x, y] = 'f';
 }
示例#2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            g      = Graphics.FromImage(bitmap);
            drawArea();

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    if (i == 0 || j == 0 || i == 8 || j == 8 ||
                        ((i < 3 || i > 5) && (j < 3 || j > 5)))
                    {
                        area[i, j] = 'N';
                    }
                    else
                    {
                        area[i, j] = '0';
                    }
                }
            }

            area[3, 3] = 'f';
            foxes[0]   = new Fox(3, 3);
            g.DrawImage(Images.fox, areaCellWidth * 2, areaCellHeight * 2, areaCellWidth, areaCellHeight);
            area[5, 3] = 'f';
            g.DrawImage(Images.fox, areaCellWidth * 4, areaCellHeight * 2, areaCellWidth, areaCellHeight);
            foxes[1] = new Fox(5, 3);

            for (int i = 1; i < 8; i++)
            {
                for (int j = 4; j < 6; j++)
                {
                    area[i, j] = 'c';
                    g.DrawImage(Images.chicken, (i - 1) * areaCellWidth, (j - 1) * areaCellHeight, areaCellWidth, areaCellHeight);
                }
            }

            for (int i = 3; i < 6; i++)
            {
                for (int j = 6; j < 8; j++)
                {
                    area[i, j] = 'c';
                    g.DrawImage(Images.chicken, (i - 1) * areaCellWidth, (j - 1) * areaCellHeight, areaCellWidth, areaCellHeight);
                }
            }

            pictureBox1.Image = bitmap;
        }
示例#3
0
        private void perebor(Fox fox, ref int count, int k, int prevX, int prevY, List <coords> moveList)
        {
            count++;
            List <coords> move = new List <coords>();

            //копирование предыдущего массива ходов
            for (int i = 0; i < moveList.Count; i++)
            {
                move.Add(moveList[i]);
            }
            //перебор ходов
            int fx1 = 0, fy1 = 0;
            int error = 0;

            for (int d = 0; d < 4; d++)
            {
                switch (d)
                {
                case 0:
                    fx1 = fox.x - 1;
                    fy1 = fox.y;
                    break;

                case 1:
                    fx1 = fox.x;
                    fy1 = fox.y - 1;
                    break;

                case 2:
                    fx1 = fox.x + 1;
                    fy1 = fox.y;
                    break;

                case 3:
                    fx1 = fox.x;
                    fy1 = fox.y + 1;
                    break;
                }
                if (area[fx1, fy1] == 'c')
                {
                    if (area[fx1 - fox.x + fx1, fy1 - fox.y + fy1] == '0')
                    {
                        prevX = fox.x;
                        prevY = fox.y;
                        setFox(fox, fx1 - fox.x + fx1, fy1 - fox.y + fy1);
                        move.Add(new coords(fx1, fy1, fox.x, fox.y));
                        moves[k].Add(new List <coords>());
                        for (int i = 0; i < move.Count; i++)
                        {
                            moves[k][count].Add(move[i]);
                        }
                        //стирать убитых куриц и передвинутую лису
                        area[fx1, fy1] = '0';
                        perebor(fox, ref count, k, prevX, prevY, move);
                        move.Clear();
                    }
                    else
                    {
                        error++;
                    }
                }
                else
                {
                    error++;
                }
                if (error == 4)
                {
                    setFox(fox, prevX, prevY);
                    for (int i = 0; i < moves[k].Count; i++)
                    {
                        for (int j = 0; j < moves[k][i].Count; j++)
                        {
                            area[moves[k][i][j].x, moves[k][i][j].y]   = 'c';
                            area[moves[k][i][j].fx, moves[k][i][j].fy] = '0';
                        }
                    }
                }
            }
        }