Exemplo n.º 1
0
        /// <summary>
        /// AI 走决定点下当前点之后的影响
        /// </summary>
        /// <param name="u"></param>
        public void AI_think(point u)
        {
            if (u.x == -1)
            {
                return;
            }
            if (gameStat == 1)
            {
                return;
            }
            Pane         now = (Pane)this.Controls[Map[u.x, u.y]];
            Queue <Pane> q   = new Queue <Pane>();

            q.Clear();
            if (now._Has_mine)
            {
                //this._ShowAll();
                gameStat = 1;
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                now._Open();
                switch (Form1.status)
                {
                case 20:
                    MessageBox.Show("You win, AI hit a bomb just now.");
                    Form1.status = 22;
                    break;

                case 21:
                    MessageBox.Show("Draw.");
                    Form1.status = 23;
                    break;

                case 22:
                    MessageBox.Show("You win.");
                    break;
                }
                //MessageBox.Show("Lose");
                return;
            }
            q.Enqueue(now);
            vis[now._x, now._y] = 1;
            int flag = 1;

            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (vis[i, j] == 0)
                    {
                        flag = 0;
                    }
                }
            }
            if (flag == 1)
            {
                gameStat = 1;
                now._Open();
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                switch (Form1.status)
                {
                case 20:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 21:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 22:
                    MessageBox.Show("You win.");
                    break;
                }
                //MessageBox.Show("win");
                return;
            }
            int cnt = 0;

            while (q.Count != 0)
            {
                Pane fr = q.Dequeue();
                if (fr._Around != 0)
                {
                    fr._Open();
                    point pos = new point();
                    pos.set_val(fr._x, fr._y);
                    continue;
                }
                fr._Open();
                for (int i = 0; i < 8; i++)
                {
                    int xx = nx[i] + fr._x;
                    int yy = ny[i] + fr._y;
                    if (Canset(xx, yy) && vis[xx, yy] == 0)
                    {
                        Pane t = (Pane)this.Controls[Map[xx, yy]];
                        vis[xx, yy] = 1;
                        q.Enqueue(t);
                    }
                }
            }
            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    Pane pane = (Pane)this.Controls[Map[i, j]];
                    if ((pane._Stat == 1) && (pane._Around != 0))
                    {
                        point pos = new point();
                        pos.x     = i;
                        pos.y     = j;
                        mp[cnt++] = pos;
                    }
                }
            }
            flag = 1;
            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (vis[i, j] == 0)
                    {
                        flag = 0;
                    }
                }
            }
            if (flag == 1)
            {
                gameStat = 1;
                now._Open();
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                switch (Form1.status)
                {
                case 20:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 21:
                    MessageBox.Show("Defeat.");
                    Form1.status = 23;
                    break;

                case 22:
                    MessageBox.Show("You win.");
                    break;
                }
                //MessageBox.Show("win");
                return;
            }
            _Think(cnt);
        }
Exemplo n.º 2
0
        public void  _Displayround(Pane now)
        {
            if (gameStat == 1)
            {
                return;
            }
            Queue <Pane> q = new Queue <Pane>();

            q.Clear();
            if (now._Has_mine)
            {
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                Form1._instance.mineFild1.Enabled = false;
                this._ShowAll();
                if (Form1.status == 30)
                {
                    Form1.duration = System.Environment.TickCount - Form1.beginTime;
                    Form1.status   = 31;
                    return;
                }
                if (Form1.status == 20)
                {
                    Form1.status = 21;
                    MessageBox.Show("Defeat. You hit a bomb just now.");
                    t.Abort();
                    return;
                }
                MessageBox.Show("Lose.");
                return;
            }
            q.Enqueue(now);
            vis[now._x, now._y] = 1;
            int flag = 1;

            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    if (vis[i, j] == 0)
                    {
                        flag = 0;
                    }
                }
            }
            if (flag == 1)
            {
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                Form1._instance.mineFild1.Enabled = false;
                now._Open();
                if (Form1.status == 30)
                {
                    Form1.duration = System.Environment.TickCount - Form1.beginTime;
                    Form1.status   = 32;
                    return;
                }
                if (Form1.status == 20)
                {
                    t.Abort();
                }
                MessageBox.Show("Win.");
                return;
            }
            while (q.Count != 0)
            {
                Pane fr = q.Dequeue();
                if (fr._Stat == 2)
                {
                    continue;
                }
                if (this._Count_Round(fr._x, fr._y) != 0)
                {
                    fr._Open();
                    continue;
                }
                fr._Open();
                for (int i = 0; i < 8; i++)
                {
                    int xx = nx[i] + fr._x;
                    int yy = ny[i] + fr._y;
                    if (Canset(xx, yy) && vis[xx, yy] == 0)
                    {
                        Pane t = (Pane)this.Controls[Map[xx, yy]];
                        vis[xx, yy] = 1;
                        q.Enqueue(t);
                    }
                }
            }
            int unopen = 0;

            for (int i = 0; i < this.row; i++)
            {
                for (int j = 0; j < this.col; j++)
                {
                    Pane pane = (Pane)this.Controls[Map[i, j]];
                    if (pane._Stat == 0)
                    {
                        unopen++;
                    }
                }
            }
            if (pnum == unopen)
            {
                Form1._instance.led2.timer.Close();
                Form1._instance.led2.t.Abort();
                Form1._instance.mineFild1.Enabled = false;
                gameStat = 1;
                if (Form1.status == 30)
                {
                    Form1.duration = System.Environment.TickCount - Form1.beginTime;
                    Form1.status   = 32;
                    return;
                }
                if (Form1.status == 20)
                {
                    t.Abort();
                }
                MessageBox.Show("Win.");
            }
        }