// Return the operator's category that is the lowest among the applicable
    // operators for state.
    public static int LowestOperatorCategory(GoBangBoard board)
    {
        // A maximum, not important, just must be larger than any real
        // category
        int max = 99;

        // Search category 0 and 1 in G_5
        foreach (GoBangBoard.StoneSet ss in board.G5)
        {
            // There is no category below zero, so we can return early.
            if (GBOperatorFive.Present(ss))
            {
                return(0);
            }

            if (GBOperatorFour.Present(ss))
            {
                max = 1;
            }
        }

        if (max < 99)
        {
            return(max);
        }

        // Search category 1 and 2 in G_6
        foreach (GoBangBoard.StoneSet ss in board.G6)
        {
            // If there was no 0/1 before, this is certainly the minimum.
            if (GBOperatorStraightFour.Present(ss))
            {
                return(1);
            }

            if (max > 2 && GBOperatorBrokenThree.Present(ss))
            {
                max = 2;
            }
            else if (max > 2 && GBOperatorThree3.Present(ss))
            {
                max = 2;
            }
        }

        if (max < 99)
        {
            return(max);
        }

        foreach (GoBangBoard.StoneSet ss in board.G7)
        {
            if (GBOperatorThree2.Present(ss))
            {
                return(2);
            }
        }

        return(99);
    }
Ejemplo n.º 2
0
    public static GBOperatorStraightFour[] GetOperatorsIfValid
        (GoBangBoard.StoneSet ss)
    {
        if (Present(ss) == false)
        {
            return(null);
        }

        // Operator is valid, lets produce it (only one variant)
        GBOperatorStraightFour sfour = new GBOperatorStraightFour();

        sfour.fAdd = new int[1, 3];
        for (int n = 1; n < (ss.stones.Length - 1); ++n)
        {
            if (ss.stones[n] != 0)
            {
                continue;
            }

            sfour.fAdd[0, 0] = ss.x + n * ss.ax;
            sfour.fAdd[0, 1] = ss.y + n * ss.ay;
            sfour.fAdd[0, 2] = 1;
        }

        return(new GBOperatorStraightFour[] { sfour });
    }
    public static GBOperator[] LegalOperators(GBSpaceState state, int maxCat)
    {
        ArrayList opersGoal   = new ArrayList();
        ArrayList opersFours  = new ArrayList();
        ArrayList opersThrees = new ArrayList();

        // Check G_5 for operators
        foreach (GoBangBoard.StoneSet ss in state.GB.G5)
        {
            if (IsLastOperatorDependent(ss, state.LastOperator) == false)
            {
                continue;
            }

            GBOperatorFive[] fives = null;
            if (maxCat >= 0)
            {
                fives = GBOperatorFive.GetOperatorsIfValid(ss);
            }

            GBOperatorFour[] fours = null;
            if (maxCat >= 1)
            {
                fours = GBOperatorFour.GetOperatorsIfValid(ss);
            }

            if (fives != null)
            {
                opersGoal.AddRange(fives);
            }
            if (fours != null)
            {
                opersFours.AddRange(fours);
            }
        }

        bool Three2Applicable = false;

        if (maxCat >= 2)
        {
            // Check G_7 for operators
            foreach (GoBangBoard.StoneSet ss in state.GB.G7)
            {
                if (IsLastOperatorDependent(ss, state.LastOperator) == false)
                {
                    continue;
                }

                /*
                 * Console.Write ("7ss: ");
                 * for (int n = 0 ; n < ss.stones.Length ; ++n)
                 *      Console.Write ("{0} ", ss.stones[n] == 1 ? "O" :
                 *              (ss.stones[n] == -1 ? "X" : "."));
                 * Console.WriteLine ();
                 */

                GBOperatorThree2[] three2 =
                    GBOperatorThree2.GetOperatorsIfValid(ss);

                if (three2 != null)
                {
                    Three2Applicable = true;
                    opersThrees.AddRange(three2);
                }
            }
        }

        // Check G_6 for operators
        if (maxCat >= 1)
        {
            foreach (GoBangBoard.StoneSet ss in state.GB.G6)
            {
                if (IsLastOperatorDependent(ss, state.LastOperator) == false)
                {
                    continue;
                }

                GBOperatorStraightFour[] sfours = null;
                if (maxCat >= 1)
                {
                    sfours = GBOperatorStraightFour.GetOperatorsIfValid(ss);
                }

                GBOperatorBrokenThree[] bthrees = null;
                GBOperatorThree3[]      three3s = null;
                if (maxCat >= 2)
                {
                    bthrees = GBOperatorBrokenThree.GetOperatorsIfValid(ss);
                }

                // Heuristic "restricted trees", page 141.
                // HEURISTIC
                // FIXME: re-enable this after testing.
                if (maxCat >= 2 /*&& Three2Applicable == false*/)
                {
                    three3s = GBOperatorThree3.GetOperatorsIfValid(ss);
                }

                if (sfours != null)
                {
                    opersGoal.AddRange(sfours);
                }
                if (bthrees != null)
                {
                    opersThrees.AddRange(bthrees);
                }
                if (three3s != null)
                {
                    opersThrees.AddRange(three3s);
                }
            }
        }

        // Order: goal, fours, threes
        opersGoal.AddRange(opersFours);
        opersGoal.AddRange(opersThrees);

        if (opersGoal.Count > 0)
        {
            return((GBOperator[])opersGoal.ToArray(typeof(GBOperator)));
        }

        return(null);
    }
    public static GBOperatorStraightFour[] GetOperatorsIfValid(GoBangBoard.StoneSet ss)
    {
        if (Present (ss) == false)
            return (null);

        // Operator is valid, lets produce it (only one variant)
        GBOperatorStraightFour sfour = new GBOperatorStraightFour ();

        sfour.fAdd = new int[1,3];
        for (int n = 1 ; n < (ss.stones.Length - 1) ; ++n) {
            if (ss.stones[n] != 0)
                continue;

            sfour.fAdd[0,0] = ss.x + n*ss.ax;
            sfour.fAdd[0,1] = ss.y + n*ss.ay;
            sfour.fAdd[0,2] = 1;
        }

        return (new GBOperatorStraightFour[] { sfour });
    }