/** Apply the operator to the given state, returning a new state.
     *
     * @param state The source state.
     *
     * @returns The newly created destination state.
     */
    public IDBSpaceState Apply(DBSearchModule module, IDBSpaceState stateDB)
    {
        GBSearchModule gmod  = (GBSearchModule)module;
        GBSpaceState   state = (GBSpaceState)stateDB;

        // TODO: remove later, we already checked this previously
        if (Valid(state) == false)
        {
            throw (new ArgumentException("Operator not applicable!"));
        }

        GoBangBoard newBoard = (GoBangBoard)state.GB.Clone();

        // Apply all the f_{add} stones
        for (int n = 0; n < fAdd.GetLength(0); ++n)
        {
            newBoard.board[fAdd[n, 1], fAdd[n, 0]] = fAdd[n, 2];
        }

        GBSpaceState newState = new GBSpaceState(newBoard, this, state,
                                                 gmod.maximumCategory);

        newState.UpdateIsGoal(gmod);

        return(newState);
    }
 public DBSearch(DBSearchModule module, bool breadthFirst)
 {
     this.module       = module;
     this.breadthFirst = breadthFirst;
 }
    /** Apply the operator to the given state, returning a new state.
     *
     * @param state The source state.
     *
     * @returns The newly created destination state.
     */
    public IDBSpaceState Apply(DBSearchModule module, IDBSpaceState stateDB)
    {
        GBSearchModule gmod = (GBSearchModule) module;
        GBSpaceState state = (GBSpaceState) stateDB;

        // TODO: remove later, we already checked this previously
        if (Valid (state) == false)
            throw (new ArgumentException ("Operator not applicable!"));

        GoBangBoard newBoard = (GoBangBoard) state.GB.Clone ();

        // Apply all the f_{add} stones
        for (int n = 0 ; n < fAdd.GetLength (0) ; ++n)
            newBoard.board[fAdd[n,1], fAdd[n,0]] = fAdd[n,2];

        GBSpaceState newState = new GBSpaceState (newBoard, this, state,
            gmod.maximumCategory);
        newState.UpdateIsGoal (gmod);

        return (newState);
    }
    public bool UpdateIsGoal(DBSearchModule dbS)
    {
        GBSearchModule gbS = (GBSearchModule)dbS;
        int            white, hole;

        // 1. Five
        foreach (GoBangBoard.StoneSet ss in GB.G5)
        {
            GBOperator.CountStones(ss, out white, out hole);

            if (white == 5 && hole == 0)
            {
                /*Console.WriteLine (GB);
                 * Console.WriteLine ("=> goal because of five");*/

                isGoal = true;
                return(true);
            }
        }

        // 2. Straight four
        // FIXME/TODO: check if this is right, i mean the check here
        if (gbS.maximumCategory >= 1)
        {
            foreach (GoBangBoard.StoneSet ss in GB.G6)
            {
                if (ss.stones[0] != 0 || ss.stones[5] != 0)
                {
                    continue;
                }

                GBOperator.CountStones(ss, out white, out hole);

                if (white == 4 && hole == 2)
                {
                    /*Console.WriteLine (GB);
                     * Console.WriteLine ("goal because of four");*/
                    isGoal = true;
                    return(true);
                }
            }
        }

        // Check if there are extra fixed goal squares.
        if (gbS.goalIfOccupied == null)
        {
            isGoal = false;

            return(false);
        }
// There extra squares, check if they are occupied by the defender
        // (-1, but in the flipped field its 1) in this state.
        for (int n = 0; n < gbS.goalIfOccupied.GetLength(0); ++n)
        {
            if (gb.board[gbS.goalIfOccupied[n, 1], gbS.goalIfOccupied[n, 0]] == 1)
            {
                /*Console.WriteLine (GB);
                 * Console.WriteLine ("goal because occupation of ({0},{1})",
                 *      gbS.goalIfOccupied[n,0], gbS.goalIfOccupied[n,1]);*/
                isGoal = true;

                return(true);
            }
        }

        // Neither a necessary field has been occupied, nor a five/four been
        isGoal = false;
        return(false);
    }
    public bool UpdateIsGoal(DBSearchModule dbS)
    {
        GBSearchModule gbS = (GBSearchModule) dbS;
        int white, hole;

        // 1. Five
        foreach (GoBangBoard.StoneSet ss in GB.G5) {
            GBOperator.CountStones (ss, out white, out hole);

            if (white == 5 && hole == 0) {
                /*Console.WriteLine (GB);
                Console.WriteLine ("=> goal because of five");*/

                isGoal = true;
                return (true);
            }
        }

        // 2. Straight four
        // FIXME/TODO: check if this is right, i mean the check here
        if (gbS.maximumCategory >= 1) {
            foreach (GoBangBoard.StoneSet ss in GB.G6) {
                if (ss.stones[0] != 0 || ss.stones[5] != 0)
                    continue;

                GBOperator.CountStones (ss, out white, out hole);

                if (white == 4 && hole == 2) {
                    /*Console.WriteLine (GB);
                    Console.WriteLine ("goal because of four");*/
                    isGoal = true;
                    return (true);
                }
            }
        }

        // Check if there are extra fixed goal squares.
        if (gbS.goalIfOccupied == null) {
            isGoal = false;

            return (false);
        }
        // There extra squares, check if they are occupied by the defender
        // (-1, but in the flipped field its 1) in this state.
        for (int n = 0 ; n < gbS.goalIfOccupied.GetLength (0) ; ++n) {
            if (gb.board[gbS.goalIfOccupied[n,1], gbS.goalIfOccupied[n,0]] == 1) {
                /*Console.WriteLine (GB);
                Console.WriteLine ("goal because occupation of ({0},{1})",
                    gbS.goalIfOccupied[n,0], gbS.goalIfOccupied[n,1]);*/
                isGoal = true;

                return (true);
            }
        }

        // Neither a necessary field has been occupied, nor a five/four been
        isGoal = false;
        return (false);
    }