Ejemplo n.º 1
0
 public virtual void InitData(ChessData data, UChessBoard board)
 {
     this.name      = data.name;
     this.campType  = data.campType;
     this.point     = data.point;
     this.prefab    = data.prefab;
     this.chessType = data.chessType;
     _chessboard    = board;
 }
Ejemplo n.º 2
0
    //-------------------------------------------------------------------------
    //public static byte[] Compress(byte[] inputBytes)
    //{
    //    MemoryStream ms = new MemoryStream();
    //    GZipOutputStream gzip = new GZipOutputStream(ms);
    //    gzip.Write(inputBytes, 0, inputBytes.Length);
    //    gzip.Close();
    //    return ms.ToArray();
    //}

    //-------------------------------------------------------------------------
    ///// <summary>
    ///// 解压缩字节数组
    ///// </summary>
    ///// <param name="str"></param>
    //public static byte[] Decompress(byte[] inputBytes)
    //{
    //    GZipInputStream gzi = new GZipInputStream(new MemoryStream(inputBytes));
    //    MemoryStream re = new MemoryStream();
    //    int count = 0;
    //    byte[] data = new byte[4096];
    //    while ((count = gzi.Read(data, 0, data.Length)) != 0)
    //    {
    //        re.Write(data, 0, count);
    //    }
    //    return re.ToArray();
    //}

    //-------------------------------------------------------------------------
    void Start()
    {
        //UI
        //UIEventListener.Get(BtnStart.gameObject).onClick = OnClickStart;
        //UIEventListener.Get(BtnStop.gameObject).onClick = OnClickStop;

        if (LoadWeights)
        {
            try
            {
                LoadGenFromFile();
            }
            catch (System.Exception E)
            {
                Debug.Log("Load Gen Failed " + E.Message);
                LoadWeights = false;
            }
        }

        if (!LoadWeights)
        {
            UGenAlg.ConfigData Config = new UGenAlg.ConfigData();
            Config.PopSize    = 3000;
            Config.NumWeights = new UControllerBotAI().Net.GetWeightCount();
            Gen = new UGenAlg();
            Gen.Init(Config);
        }

        // 更新适应性分数代理
        Gen.onUpdateFitnessScores = UpdateFitnessScores;

        BoardList = new List <UChessBoard>();
        ChessBoardPrefab.learn = true;
        ChessBoardPrefab.gameObject.SetActive(showFirstChessboard);
        ChessBoardPrefab.InitStart();

        BoardList.Add(ChessBoardPrefab);

        // 创建其他棋盘
        for (int i = 1; i < Gen.Config.PopSize / 2; i++)
        {
            UChessBoard board = UnityEngine.Object.Instantiate <GameObject>(ChessBoardPrefab.gameObject).GetComponent <UChessBoard>();
            board.learn = true;
            //board.show = false;
            board.gameObject.SetActive(false);
            board.InitStart();
            BoardList.Add(board);
        }

        //将加载的适应性分数保存
        if (LoadWeights)
        {
            PutFitnessScores();
        }
    }