All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.sahits.game.openpatrician.engine.land.city.internal.ElectionTask Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package ch.sahits.game.openpatrician.engine.land.city.internal;

import ch.sahits.game.openpatrician.annotation.ClassCategory;
import ch.sahits.game.openpatrician.annotation.EClassCategory;
import ch.sahits.game.openpatrician.annotation.Prototype;
import ch.sahits.game.openpatrician.collections.SortedMapRandomizedSameElements;
import ch.sahits.game.openpatrician.model.ICitizen;
import ch.sahits.game.openpatrician.model.city.cityhall.impl.Election;
import ch.sahits.game.openpatrician.model.event.TimedTask;
import ch.sahits.game.openpatrician.util.OpenPatricianRandom;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Andi Hotz, (c) Sahits GmbH, 2015
 *         Created on May 17, 2015
 */
@Prototype
@ClassCategory({EClassCategory.SERIALIZABLE_BEAN, EClassCategory.PROTOTYPE_BEAN})
public class ElectionTask extends TimedTask {
    @Autowired
    @XStreamOmitField
    private OpenPatricianRandom oprnd;

    private final SortedMapRandomizedSameElements candidateMap;
    private final Election result;

    public ElectionTask(SortedMapRandomizedSameElements candidateMap, Election result, DateTime electionTime) {
        this.candidateMap = candidateMap;
        this.result = result;
        setExecutionTime(electionTime);
    }

    @Override
    public void run() {
        int index = oprnd.nextSlidingRandomDecreasing(candidateMap.size() - 1, 0.5); // todo: andi 5/17/15: this should probably be dependent on the popularity of the top candidate
        List citizens = candidateMap.getAtIndex(index);
        result.vote(citizens.get(0));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy