Skip to main content
Jump to: navigation, search

AMP/UserGuide/AMF/ExampleAscapeCode

< AMP‎ | UserGuide‎ | AMF
Revision as of 22:28, 14 October 2009 by Milesparker.gmail.com (Talk | contribs) (New page: <source lang="java"> public void findPartner() { org.ascape.util.Conditional partnerCondition = new org.ascape.util.Conditional() { private static final long serial...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
    public void findPartner() {
        org.ascape.util.Conditional partnerCondition = new org.ascape.util.Conditional() {
            private static final long serialVersionUID = 6846144446402098985L;
 
            public boolean meetsCondition(Object partnerCell) {
                partnerCell = ((org.ascape.model.HostCell) partnerCell).getOccupant();
                if (partnerCell instanceof Individual) {
                    Individual partner = (Individual) partnerCell;
                    return partner.getAge() == getAge();
                } else {
                    return false;
                }
            }
        };
 
        Individual partner = null;
        org.ascape.model.space.Location partnerLocation = ((org.ascape.model.space.Discrete) getWikiExample().getCity()
                .getSpace()).findRandomWithin(((org.ascape.model.CellOccupant) this).getHostCell(), partnerCondition,
                                              false, partner.getVision());
        if (partnerLocation != null) {
            partner = (Individual) ((org.ascape.model.HostCell) partnerLocation).getOccupant();
        }
        if (partner != null) {
            Block partnerNeighbor = (Block) ((org.ascape.model.space.Discrete) getWikiExample().getCity().getSpace())
            .findRandomAvailableNeighbor(((org.ascape.model.CellOccupant) partner).getHostCell());
            if (partnerNeighbor != null) {
                moveTo(partnerNeighbor);
            }
        }
    }

Copyright © Eclipse Foundation, Inc. All Rights Reserved.