Beispiel #1
0
    private IEnumerator randomChoose()
    {
        PlaceMethod pm = PlaceMethodGenerator.getRandomPlaceMethod();

        _PM = pm;
        //Debug.Log(pm);
        _HasEnded = true;
        yield return(new WaitForEndOfFrame());
    }
Beispiel #2
0
    public static int getBestResultPurge(LiuheChessBoard lcb, PlaceMethod pm, int layer, bool isAI, float purgeRate)
    {
        if (layer <= 0)
        {
            LiuheChessBoard lcbTemp = PlaceMethodGenerator.getPlacedChessBoard(pm, lcb);
            return(GameBoardEvaluator.evaluateGameBoard_MK0(lcbTemp));
        }
        else
        {
            LiuheChessBoard lcbTemp = PlaceMethodGenerator.getPlacedChessBoard(pm, lcb);

            List <PlaceMethod> pms     = PlaceMethodGenerator.getPurchedMethods(lcb, purgeRate, isAI);
            List <int>         results = new List <int>();
            foreach (PlaceMethod p in pms)
            {
                results.Add(getBestResult(lcbTemp.getCopy(), p, layer - 1, !isAI));
            }

            if (isAI)
            {
                int minvalue = results[0];
                for (int i = 1; i < results.Count; i++)
                {
                    if (results[i] < minvalue)
                    {
                        minvalue = results[i];
                    }
                }
                return(minvalue);
            }
            else
            {
                int maxvalue = results[0];
                for (int i = 1; i < results.Count; i++)
                {
                    if (results[i] > maxvalue)
                    {
                        maxvalue = results[i];
                    }
                }
                return(maxvalue);
            }
        }
    }
Beispiel #3
0
    public static PlaceMethod getBestMethodMultiLayerPurge(int layer, float purge)
    {
        LiuheChessBoard    lcb     = GameManager._Main._GameBoard;
        List <PlaceMethod> pms     = PlaceMethodGenerator.getPurchedMethods(lcb, purge, true);
        List <int>         results = new List <int>();

        foreach (PlaceMethod p in pms)
        {
            results.Add(getBestResultPurge(lcb.getCopy(), p, layer - 1, false, purge));
        }
        int min      = 0;
        int minvalue = results[0];

        for (int i = 1; i < results.Count; i++)
        {
            if (results[i] < minvalue)
            {
                minvalue = results[i];
                min      = i;
            }
        }
        return(pms[min]);
    }
Beispiel #4
0
    public static PlaceMethod getMinPlaceMethod_OL()
    {
        List <PlaceMethod> pms  = PlaceMethodGenerator.getAllValidPlaceMethod(GameManager._Main._GameBoard.getCopy());
        LiuheChessBoard    lcb2 = GameManager._Main._GameBoard.getCopy();

        LiuheChessBoard lcbTemp = PlaceMethodGenerator.getPlacedChessBoard(pms[0], lcb2.getCopy());

        int minNum              = 0;
        int minValue            = GameBoardEvaluator.evaluateGameBoard_MK0(lcbTemp);
        List <PlaceMethod> _NPM = new List <PlaceMethod>();

        _NPM.Add(pms[0]);
        for (int i = 1; i < pms.Count; i++)
        {
            int temp;
            lcbTemp = PlaceMethodGenerator.getPlacedChessBoard(pms[i], lcb2.getCopy());
            temp    = GameBoardEvaluator.evaluateGameBoard_MK0(lcbTemp);

            //Debug.Log("评分为"+temp);

            if (temp < minValue)
            {
                minNum   = i;
                minValue = temp;
                _NPM     = new List <PlaceMethod>();
                _NPM.Add(pms[i]);
            }
            else if (temp == minValue)
            {
                _NPM.Add(pms[i]);
            }
        }

        int iend = (int)Random.Range(0, _NPM.Count);

        return(_NPM[iend]);
    }
Beispiel #5
0
    public static List <PlaceMethod> getPurchedMethods(LiuheChessBoard lcb, float purchRate, bool isAI)
    {
        List <PlaceMethod> pms = getAllValidPlaceMethod(lcb);
        int purchNum           = (int)(pms.Count * purchRate);

        if (purchNum == pms.Count)
        {
            purchNum--;
        }

        List <int> results = new List <int>();

        foreach (PlaceMethod p in pms)
        {
            LiuheChessBoard lcb2 = PlaceMethodGenerator.getPlacedChessBoard(p, lcb.getCopy());
            results.Add(GameBoardEvaluator.evaluateGameBoard_MK0(lcb2));
        }

        if (isAI)
        {
            //是ai,从小到大
            for (int i = 0; i < pms.Count; i++)
            {
                for (int j = i; j < pms.Count; j++)
                {
                    if (results[i] > results[j])
                    {
                        int temp = results[i];
                        results[i] = results[j];
                        results[j] = temp;
                        PlaceMethod pm = pms[i];
                        pms[i] = pms[j];
                        pms[j] = pm;
                    }
                }
            }
        }
        else
        {
            //是人,从大到小
            for (int i = 0; i < pms.Count; i++)
            {
                for (int j = i; j < pms.Count; j++)
                {
                    if (results[i] < results[j])
                    {
                        int temp = results[i];
                        results[i] = results[j];
                        results[j] = temp;
                        PlaceMethod pm = pms[i];
                        pms[i] = pms[j];
                        pms[j] = pm;
                    }
                }
            }
        }

        for (int i = 0; i < purchNum; i++)
        {
            pms.RemoveAt(pms.Count - 1);
        }

        return(pms);
    }