battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionnew code snippet feature test Emptynew code snippet feature test

more_horiz

Code:


class DrawRnd {
    // draw a random element, than take said element out
    private var strings:Array<String> = [String]()
    private var stringsSource:Array<String> = [String]()
    init(_ values:String...) {
        for temp in values {
            strings.append(temp)
            stringsSource.append(temp)
        }
    }
    func draw() -> String {
        if strings.isEmpty {return ""}
        let x:Int = Int.random(in: 0..<strings.count)
        let element:String = strings[x]
        strings.remove(at: x)
        return element
    }
    func reset(){
        let dc:DeepCopier = DeepCopier()
        strings = dc.copyList(original: stringsSource)
    }
    func getSimpleRNDNum(bound:Int)->Int{
        // return 0->bound-1
        return Int.random(in: 0...bound-1)
    }
    private let tc:LGTypeConverter = LGTypeConverter()
    func drawAsInt()->Int{
        return tc.convertToInt(v1: draw())
    }
}
class LGTypeConverter{
    func convertToInt(v1:String)->Int{
        return Int(v1) ?? 0
    }
    func convertToDouble(v1:String)->Double{
        return Double(v1) ?? 0
    }
}

descriptionnew code snippet feature test EmptyRe: new code snippet feature test

more_horiz
test

descriptionnew code snippet feature test EmptyRe: new code snippet feature test

more_horiz

Code:


public class PerChanceTest extends PerChance{
    public PerChanceTest() {
        super();
        sentences.add("here is a  salad vegi1 #, vegi2 # and herb #.");
        sentences.add("how about this salad vegi1 #, vegi2 # and herb #. it goes well with tuna fish");
        UniqueItemSizeLimitedPriorityQueue temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("vegi1", temp);
        temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("vegi2", temp);
        temp = new UniqueItemSizeLimitedPriorityQueue();
        temp.setLimit(3);
        wordToList.put("herb", temp);
    }
}

descriptionnew code snippet feature test EmptyRe: new code snippet feature test

more_horiz

Code:


public class Strategy {
    private UniqueItemSizeLimitedPriorityQueue activeStrategy;
    private DrawRnd allStrategies;

    public Strategy(DrawRnd allStrategies) {
        this.allStrategies = allStrategies;
        this.activeStrategy = new UniqueItemSizeLimitedPriorityQueue();
    }
    public void evolveStrategies(int strategiesLimit){
        activeStrategy.setLimit(strategiesLimit);
        String temp = allStrategies.draw();
        for (int i = 0; i < strategiesLimit; i++) {
            if(temp.isEmpty()){
                break;
            }
            activeStrategy.add(temp);
            temp = allStrategies.draw();
        }
        allStrategies.reset();
    }
    public String getStrategy(){
        return this.activeStrategy.getRNDElement();
    }
}
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply