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

static final int [] friendless::games::filler::FillerModel::calcNeighbours ( int  i,
int[]  ps 
) [inline, static, private]

Calculate what the neighbours of cell i are. Put them into the first elements of the array ps. Fill the remaining spaces with the value NO_NEIGHBOUR.

Definition at line 111 of file FillerModel.java.

References NO_NEIGHBOUR.

                                                               {
        final int columns = FillerSettings.COLUMNS;
        final int rows = FillerSettings.ROWS;
        int xi = x[i];
        int yi = y[i];
        int idx = 0;
        // to the right
        if (xi < columns-2) ps[idx++] = makeIndex(xi+2, yi);
        // to the left
        if (xi > 1) ps[idx++] = makeIndex(xi-2, yi);
        if (xi % 2 == 0) {
            if (xi > 0) {
                // above and below to the left
                ps[idx++] = makeIndex(xi-1, yi-1);
                ps[idx++] = makeIndex(xi-1, yi);
            }
            if (xi < columns-1) {
                // above and below to the right
                ps[idx++] = makeIndex(xi+1, yi-1);
                ps[idx++] = makeIndex(xi+1, yi);
            }
        } else {
            if (yi > 0) {
                // two above
                ps[idx++] = makeIndex(xi-1, yi);
                ps[idx++] = makeIndex(xi+1, yi);
            }
            if (yi < rows-1) {
                // two below
                ps[idx++] = makeIndex(xi-1, yi+1);
                ps[idx++] = makeIndex(xi+1, yi+1);
            }
        }
        while (idx < ps.length) ps[idx++] = NO_NEIGHBOUR;
        return ps;
    }


Generated by  Doxygen 1.6.0   Back to index