コード例 #1
0
        private void ButtonClicked(object sender, EventArgs e)
        {
            MyButton btn = (MyButton)sender;

            if (Data.top[btn.y] <= 0)
            {
                MessageBox.Show("This column has been full, chose another column");
                return;
            }
            else
            {
                Data.lastX = Data.top[btn.y] - 1;
                Data.lastY = btn.y;
                Data.board[Data.lastX * Data.N + Data.lastY] = 1;
                Data.top[Data.lastY]--;
                //对不可落子点进行处理
                if (Data.lastX == Data.noX + 1 && Data.lastY == Data.noY)
                {
                    Data.top[y]--;
                }
                Data.mainFrame.buttons[Data.lastX][Data.lastY].setImage(true);
                Data.mainFrame.updataBoard();

                //判断胜负

                /*
                 * bool over = Judge.judgeUM(true);
                 * if(!over)
                 * {
                 *  Data.mainFrame.computerGo();
                 * }
                 */
                Data.over = Judge.judgeUM(true);

                //保存历史,要在判断胜负的后面,因为ctrlPanel的修改与游戏是否结束有关
                Data.history.Push(new Step(true, Data.lastX, Data.lastY));
                Data.mainFrame.updateCtrlPanel();

                if (!Data.over)
                {
                    Data.mainFrame.computerGo();
                }
            }
        }
コード例 #2
0
ファイル: MainFrame.cs プロジェクト: EvenQAQ/4chess
        //人机对抗中计算机在某一个点上落子
        public void computerGo()
        {
            int x, y;

            unsafe
            {
                fixed(int *_top = Data.top, _board = Data.board)
                {
                    try
                    {
                        //---
                        Stopwatch s = new Stopwatch();
                        Stopwatch e = Stopwatch.StartNew();
                        s.Start();
                        //---

                        Point *p = Data.strategy.getPoint(Data.M, Data.N, _top, _board, Data.lastX, Data.lastY, Data.noX, Data.noY);

                        //---
                        e.Stop();
                        long milisecs = s.ElapsedMilliseconds;
                        if (milisecs > Data.maxMiliSecs)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append("Warning : \nYour last step used ");
                            sb.Append(milisecs.ToString());
                            sb.Append(" ms,\nwhich is more than the limited ");
                            sb.Append(Data.maxMiliSecs.ToString());
                            sb.Append(" ms.");
                            MessageBox.Show(sb.ToString());
                        }
                        //---

                        x = p->x;
                        y = p->y;
                        Data.strategy.clearPoint(p);
                    }
                    catch
                    {
                        MessageBox.Show("A bug occurred in your strategy file!\nYou have lost.");
                        gameOver();
                        thread.Abort();
                        return;
                    }
                }
            }

            if (!isLegal(x, y, true, true))
            {
                gameOver();
                thread.Abort();
                return;
            }

            buttons[x][y].setImage(false);
            updataBoard();
            Data.lastX = x;
            Data.lastY = y;
            Data.board[x * Data.N + y] = 2;
            Data.top[y]--;
            //对不可落子点进行处理
            if (x == Data.noX + 1 && y == Data.noY)
            {
                Data.top[y]--;
            }
            //将该步落子放到栈中
            Data.history.Push(new Step(false, x, y));
            //更新控制面板
            updateCtrlPanel();
            //判断胜负
            //Judge.judgeUM(false);
            Data.over = Judge.judgeUM(false);
        }