Ejemplo n.º 1
0
    static public MinMaxNode CalculateBestMove(GameManager.CELL_DATA[,] currentTable)
    {
        // Treating the special situations
        MinMaxNode aiFirstMoveNode = new MinMaxNode();

        aiFirstMoveNode.StartMinMaxNode(currentTable);

        MinMaxNode bestMove = aiFirstMoveNode.CalculateInternalBestMove();

        return(bestMove);
    }
Ejemplo n.º 2
0
    MinMaxNode CalculateInternalBestMove()
    {
        if (GetTreeChildrenCount() == 0)
        {
            return(this);
        }

        int   ChoosedChild = 0;
        float resultValue  = (MoveType == TYPE.MAX) ? -20.0f : 20.0f;
        int   resultIIndex = 0;

        for (int i = 0; i < GetTreeChildrenCount(); i++)
        {
            MinMaxNode node = (MinMaxNode)GetTreeChild(i);

            if (node.MoveResult == 0.0f)
            {
                node.CalculateInternalBestMove();
            }

            if (MoveType == TYPE.MAX && node.MoveResult > resultValue)
            {
                ChoosedChild = i;
                resultValue  = node.MoveResult;
                resultIIndex = node.IndexI;
            }
            else if (MoveType == TYPE.MIN && node.MoveResult < resultValue)
            {
                ChoosedChild = i;
                resultValue  = node.MoveResult;
                resultIIndex = node.IndexI;
            }
            else if (node.MoveResult == resultValue && node.IndexI > resultIIndex)
            {
                ChoosedChild = i;
                resultValue  = node.MoveResult;
                resultIIndex = node.IndexI;
            }
            else if (node.MoveResult == resultValue && Random.value > 0.5f)
            {
                ChoosedChild = i;
                resultValue  = node.MoveResult;
                resultIIndex = node.IndexI;
            }
        }

        MoveResult = resultValue;
        return((MinMaxNode)GetTreeChild(ChoosedChild));
    }