Logo Search packages:      
Sourcecode: filler version File versions  Download package

static void friendless::games::filler::FillerModel::allocate ( FillerModel  model,
int  origin,
FillerPlayerSpace  space,
int  mine,
int  myBorder 
) [inline, static, protected]

Assuming that I am the player who started at origin, fill in details in space to mark where my pieces and my border are. As this filling may have already been done for the other player, it's possible that locations on my border may already be marked as being on his border. In those cases, change them to SHARED_BORDER.

Definition at line 214 of file FillerModel.java.

References friendless::games::filler::FillerPlayerSpace::border, BORDER, friendless::games::filler::FillerPlayerSpace::counted, HIS, HIS_BORDER, friendless::games::filler::FillerPlayerSpace::listed, MAX_NEIGHBOURS, MINE, NO_NEIGHBOUR, pieces, friendless::games::filler::FillerPlayerSpace::resetListed(), SHARED_BORDER, and VACANT.

Referenced by allocateTypes().

                                    {
        int hisBorder = BORDER + HIS_BORDER - myBorder;
        int his = MINE + HIS - mine;
        space.resetListed();
        int[] counted = space.counted;
        boolean[] listed = space.listed;
        int[] border = space.border;
        int colour = model.pieces[origin];
        // origin is mine, its neighbours are the original border
        counted[origin] = mine;
        listed[origin] = true;
        int idx = 0;
        int[] ns = neighs[origin];
        for (int i=0; i<ns.length; i++) {
            int q = ns[i];
            if (q == NO_NEIGHBOUR) break;
            listed[q] = true;
            border[idx++] = q;
        }
        // process the positions on the border
        while (idx > 0) {
            // take a point which is currently on the border
            int p = border[--idx];
            int thisPiece = counted[p];
            if ((thisPiece == VACANT) || (thisPiece == hisBorder)) {
                if (model.pieces[p] == colour) {
                    // on the border and my colour must be mine
                    counted[p] = mine;
                    ns = neighs[p];
                    for (int i=0; i<ns.length; i++) {
                        int q = ns[i];
                        if (q == NO_NEIGHBOUR) break;
                        if (!listed[q]) {
                            listed[q] = true;
                            border[idx++] = q;
                        }
                    }
                } else if (thisPiece == hisBorder) {
                    // on my border and his border must be shared border
                    counted[p] = SHARED_BORDER;
                } else {
                    // on the border and another colour but not his border must be my border
                    counted[p] = myBorder;
                    ns = neighs[p];
                    for (int i=0; i<MAX_NEIGHBOURS; i++) {
                        int q = ns[i];
                        if (q == NO_NEIGHBOUR) break;
                        if (!listed[q] && (model.pieces[p] == model.pieces[q]) && (counted[q] != his)) {
                            listed[q] = true;
                            border[idx++] = q;
                        }
                    }
                }
            }
        }
    }


Generated by  Doxygen 1.6.0   Back to index