Beispiel #1
0
        /// <summary>
        /// gnugo智能计算指定颜色最优的落子点落子
        /// </summary>
        /// <param name="color">AI棋手的颜色</param>
        /// <returns>AI想到的落子位置</returns>
        public Point GetGenComputerMove(int color)
        {
            int   genm = SDGGoRuntime.SDGGenComputerMove(color);
            Point p    = POS2XY(genm);

            return(p);
        }
Beispiel #2
0
 // 重新开始游戏
 public void ReStartGame()
 {
     // 初始化
     InitialData();
     // 在线对战和非在线游戏
     if (GameType == 2)
     {
         OnlineInit();
     }
     // 显示游戏界面UI
     gameui.object_gameui.SetActive(true);
     // 隐藏游戏结束界面
     gameendui.object_gameendui.SetActive(false);
     // 开始按钮
     if (CurrentPlayer.Ins.isRoomOwner)
     {
         gameui.object_startgame.SetActive(true);
     }
     else
     {
         gameui.object_startgame.SetActive(false);
     }
     // 清空棋盘
     GoUIManager.Ins.ClearAllMoves();
     gameui.text_GameResult.text = "白棋领先" + game.komi + "目";
     gameui.text_komi.text       = "黑子贴" + game.komi + "目";
     gameui.text_level.text      = "AI等级:" + SDGGoRuntime.SDGGetLevel() + "级";
 }
Beispiel #3
0
 /// <summary>
 /// 获得指定位置的棋子状态
 /// </summary>
 /// <param name="index">坐标</param>
 /// <returns>返回棋子位置状态:黑子、白子、空</returns>
 public int GetPanelColor(Point index)
 {
     if (IsPointAllowed(index))
     {
         Point pointij = XY2IJ(index);
         return(SDGGoRuntime.SDGBoardStat(pointij.x, pointij.y));
     }
     else
     {
         Debug.Log("坐标不合法,无法获取棋子状态");
         throw new Exception("坐标不合法,无法获取棋子状态");
     }
 }
Beispiel #4
0
        public float komi;            // 黑子贴目

        #region 对外接口函数
        /// <summary>
        /// 构造函数,初始化游戏实例
        /// </summary>
        /// <param name="_gametype">游戏类型(人-人,人-机,在线对战)</param>
        /// <param name="_scale">棋盘规模(19x19)</param>
        public SDGGoGame(int _gametype, int _scale)
        {
            color      = 1;          // 默认黑子先手
            komi       = 0;
            gameType   = _gametype;  // 初始化游戏类型
            gameState  = 0;          // 初始化游戏状态
            panelScale = _scale;     // 棋盘规模


            // 初始化gnugo
            SDGGoRuntime.SDGGoInit(_scale);
            SDGGoRuntime.SDGSetMaxLevel(15);
            SDGGoRuntime.SDGSetMinLevel(-5);
        }
Beispiel #5
0
        /// <summary>
        /// GNUGo逻辑落子
        /// </summary>
        /// <param name="index"></param>
        /// <param name="color"></param>
        /// <returns></returns>
        public bool SetMove(Point index, int color)
        {
            Point gnup = XY2IJ(index);

            Debug.Log("落点:i=" + gnup.x + " j=" + gnup.y);
            if (SDGGoRuntime.SDGIsAllowedMove(gnup.x, gnup.y, color) == 1)
            {
                SDGGoRuntime.SDGPlayMove(gnup.x, gnup.y, color);
                return(true);
            }
            else
            {
                Debug.Log("GNUGO逻辑拒绝落子!");
                return(false);
            }
        }
Beispiel #6
0
 /// <summary>
 /// 获取当前得分
 /// </summary>
 /// <returns>分值,大于0说明白棋领先,反之黑棋领先</returns>
 public float GetCurrentScore()
 {
     return(SDGGoRuntime.SDGGetScore());
 }
Beispiel #7
0
 /// <summary>
 /// 悔棋n步
 /// </summary>
 /// <param name="n"></param>
 /// <returns>是否悔棋成功</returns>
 public bool UndoMove(int n)
 {
     return(SDGGoRuntime.SDGUndoMove(n) == 1 ? true : false);
 }
Beispiel #8
0
    // 初始化
    void InitialData()
    {
        // 初始化游戏
        int scale = GoUIManager.Ins.panelScale;

        game = new SDGGoGame(GameType, scale);
        // 初始化当前棋子颜色
        game.color = 1;
        // 黑子贴目
        if (CurrentPlayer.Ins.isKomi)
        {
            game.komi = 6.5f;
        }
        // AI难度等级
        if (GameType == 1)
        {
            SDGGoRuntime.SDGSetLevel(CurrentPlayer.Ins.curLevel);
        }

        // 背景音乐
        audiosource = GetComponent <AudioSource>();
        if (CurrentPlayer.Ins.isBGMOn)
        {
            audiosource.Play();
        }

        // 注册计时事件
        //timer = new Timer(game.moveTime);
        //timer.tickEvent += OnTimeEnd;
        //timer.tickSeceondEvent += OnSecond;
        //timerLabel.text = timer._currentTime.ToString();

        // 离线游戏直接开始
        if (GameType != 2)
        {
            StartGame();
        }

        // H-H
        if (GameType == 0)
        {
            CurrentPlayer.Ins.opponent.username = "******";
        }

        // H-C
        if (GameType == 1)
        {
            CurrentPlayer.Ins.opponent.username = "******";
            if (CurrentPlayer.Ins.isAIPlayerFisrt)
            {
                // 玩家先手
                CurrentPlayer.Ins.user.color     = 1;
                CurrentPlayer.Ins.opponent.color = 0;
            }
            else
            {
                CurrentPlayer.Ins.user.color     = 0;
                CurrentPlayer.Ins.opponent.color = 1;
            }
        }

        // Online
        if (GameType == 2)
        {
            // 客人执黑
            if (CurrentPlayer.Ins.isRoomOwner)
            {
                CurrentPlayer.Ins.user.color     = 0;
                CurrentPlayer.Ins.opponent.color = 1;
                if (CurrentPlayer.Ins.player_num < 2)
                {
                    CurrentPlayer.Ins.opponent.username = "";
                }
            }
            else
            {
                CurrentPlayer.Ins.user.color     = 1;
                CurrentPlayer.Ins.opponent.color = 0;
                if (CurrentPlayer.Ins.player_num < 2)
                {
                    CurrentPlayer.Ins.opponent.username = "";
                }
            }
        }

        // 基本参数
        param        = new ParamBase();
        param.userid = int.Parse(CurrentPlayer.Ins.user.userid);
        param.token  = CurrentPlayer.Ins.user.token;
    }