/* **********************************
 *   DeliverAgent.java
 *     Delivers Raw Materials
 * **********************************/
package player.playeragent;

import player.*;
import edu.neu.ccs.demeterf.demfgen.lib.List;
import gen.*;
import hidden.Tools;

/** Class for delivering raw material for a derivative */
public class DeliverAgent implements PlayerI.DeliverAgentI{
    final int VARS = 10;
    final int RANK = 3;
    final int SECRET_ATTEMPTS = 20;
    
    /** Adds raw materials to the given derivatives */
    public Derivative deliverRawMaterial(Derivative needRM){
        Util.display(Util.color("Delivering","green")+" "+Util.tag(needRM.type.print(),"b"));
        return needRM.deliver(rawMaterialInst(needRM));    
    }
    
    /** Compute a RawMaterial Instance for the given Derivative */
    private RawMaterialInstance rawMaterialInst(Derivative d){
        List<RelationNr> types = d.type.instances.map(new List.Map<TypeInstance, RelationNr>(){
            public RelationNr map(TypeInstance i){ return i.r; }
        });
        
        RawMaterialInstance rmi = new RawMaterialInstance(Tools.symmetric(types, VARS, RANK));
        if(d.isClassic())return rmi;
        
        // Else... create a Secret
        return rmi.addSecret(FinishAgent.bestAssign(rmi, SECRET_ATTEMPTS).assign);
    }
}