示例#1
0
        private void Computer()
        {
            base.Play();
            AbstractStone DownStone;                                                            //落子

            if (game.Count == 0)
            {
                DownStone = new RealStone(game.Board, this, 7, 7);                              //占住天元
            }
            else
            {
                Board = (Tag[, ])(game.Board.Clone());                                           //拷贝棋盘
                int       i, j;
                double    dMax   = Constants.MINIMUM;
                ArrayList stones = new ArrayList();

                for (i = 0; i < Constants.SIZE; ++i)
                {
                    for (j = 0; j < Constants.SIZE; ++j)
                    {
                        if (Available(i, j))
                        {
                            stones.Add(new VirtualStone(Board, tag, i, j));                     //枚举所有可下子
                        }
                    }
                }
                stones.Sort(VirtualStone.stoneComparerWithDefence);                             //按综合值排序

                if (((VirtualStone)stones[0]).Value < Constants.WIN - Constants.DELTA)          //没有立即获胜,搜索
                {
                    i = 0;
                    foreach (VirtualStone stone in stones)                                      //搜索(同上,不过无剪枝)
                    {
                        stone.Down();
                        stone.Value -= Search(Game.Divert(tag), 1, dMax, stone.Value) * Constants.DEC_RATE;
                        stone.Up();
                        if (dMax < stone.Value)
                        {
                            dMax = stone.Value;
                        }
                        if (++i == Constants.MAX_DOT)
                        {
                            break;
                        }
                    }
                    stones.Sort(0, i, VirtualStone.stoneComparer);                              //按进攻值排序
                }

                DownStone = new RealStone(game.Board, this, ((VirtualStone)stones[0]).X, ((VirtualStone)stones[0]).Y);//创建真实最优子
            }

            game.Down(DownStone);                                                               //落子
        }
示例#2
0
        }                                                               //添加棋子

        public override void Play()
        {
            base.Play();
            if (lstStone.Count == 0)
            {
                game.GiveUp();                                          //队列空
            }
            else
            {
                RealStone stone = (RealStone)(lstStone.Dequeue());      //队列有子,落子
                game.Down(stone);
            }
        }
示例#3
0
        public void Down(int x, int y)                                                          //按坐标落子
        {
            if (x == Constants.NET_GIVE_UP)
            {
                GiveUp(); return;
            }                                                                                   //放弃
            if (Board[x, y] != Tag.No)
            {
                return;                                                                         //落子失败,位置已有子
            }
            RealStone stone = new RealStone(Board, CurrentPlayer, x, y);                        //创建真实棋子

            Down(stone);                                                                        //落子
        }
示例#4
0
        }                                                           //是否在游戏属性

        #endregion

        #region 窗体构造函数及关闭事件

        public frmMain()                                            //构造函数
        {
            InitializeComponent();                                  //初始化各控件
            Control.CheckForIllegalCrossThreadCalls = false;        //控件可以多线程调用修改

            szBtnGame    = new string[2];                           //按钮文本数组
            szBtnFile    = new string[2];
            szBtnGame[0] = "开始新局";
            szBtnGame[1] = "投子认输";
            szBtnFile[0] = "读取游戏";
            szBtnFile[1] = "存储游戏";

            InGame = false;                                         //不在游戏
            RealStone.Init(picBlack.Image, picWhite.Image);         //设置棋子图片
            game = new Game(this);                                  //创建游戏
            SetControls();                                          //设置各控件属性
        }
示例#5
0
        public void Load(BinaryReader reader)                                                   //读档
        {
            int nTag, nCount, x, y;

            nCount = reader.ReadInt32();                                                        //棋子个数
            for (int i = 0; i < nCount; ++i)
            {
                nTag = reader.ReadInt32();                                                      //棋子颜色
                x    = reader.ReadInt32();                                                      //棋子坐标
                y    = reader.ReadInt32();

                if (Winner == null)                                                             //不是录像
                {
                    AbstractStone stone = new RealStone(Board, player[nTag], x, y);             //添加棋子
                    MainForm.lstHistory.Items.Add(stone);
                    stone.Down();                                                               //落在棋盘上
                }
                else
                {
                    ((VideoPlayer)player[nTag]).Add(new RealStone(Board, player[nTag], x, y));  //棋子加入录像玩家播放队列
                    bIsVideo = true;                                                            //本次游戏是录像播放
                }
            }
        }
示例#6
0
 public void Add(RealStone stone)
 {
     lstStone.Enqueue(stone);
 }                                                               //添加棋子