*Author

Active members:
rosutosefi(1)

Offline rosutosefiTopic starter

  • Sr. Member
  • ****
  • Posts: 727
  • Reputation Power: 10
  • rosutosefi is taking their first peeks out of the Antlion's burrow.rosutosefi is taking their first peeks out of the Antlion's burrow.
  • Dead.
  • Awards: Slice of Elements 2nd Birthday Cake
I hate RNG https://elementscommunity.org/forum/index.php?topic=40967.msg507078#msg507078
« on: June 03, 2012, 04:20:53 am »
I've been randomizing games in BL. I've made a randomizer who weighs decks based their winrates and on how many times they were used. ds.txt contains the deck stats in a matrix with [W1 L1; W2 L2; ...], dn.txt contains deck names as a matrix and dc.txt contains the deck codes. Now there's a problem: I keep getting ghostmare and vader sader. Both are at 3 Wins 1 Loss. I'm kinda confuzzled, both say they have only less than 5% chance for selection.

Here's how decks are selected:
I add 1 win to every deck and take their "projected winrates" to ensure that a first time loser will not get kicked out of the decklist immediately. Next, I will compare this to the average winrates of the decks. If the deck has 50% lower winrate than the average, poof you go silly deck, you automatically get a 0% chance for selection and become marked to meet manual deletion.

Next, they enter a "weight equation"
pw = (projected winrate)^weight / sqrt(number of games +1)
weight is 1.5 at default, though I can set this to 0 for a complete "poker face" match against someone so he can't base my deck on the decks I won with or to over 9000 to select a high winrate deck to stomp someone.

Why the ghostmare? D:
MATLAB uses Mersenne Twister for RNG by default, if that matters.

Code: [Select]
clear
ds = dlmread('ds.txt');
dn = dlmread('dn.txt');
dn = ntt(dn);
dc = dlmread('dc.txt');
dc = ntt(dc);
l = size(ds,1);
md = input('Choose mode (G = Start a Game, A = Add a Deck, V = View Deck Stats, M = Modify a Deck, D = Delete a Deck): ', 's');
if strcmp(md,'A')+strcmp(md,'a') == 1
    ds(l+1,:) = [0 0];
    in = '                               ';
    while size(in,2) > 30  || size(in,2) == 0
    in = input('Input name (1 to 30 characters): ', 's');
    end
    while size(in,2) < 30
        in(1,size(in,2)+1) = ' ';
    end
    dn(l+1,:) = in;
    ic = '';
    while size(ic,2) > 243 || size(ic,2) == 0
    ic = input('Input code (Up to 60 cards + mark): ', 's');
    end
    while size(ic,2) < 243
        ic(1,size(ic,2)+1) = ' ';
    end
    dc(l+1,:) = ic;
    dlmwrite('ds.txt', ds)
    dn = ttn(dn);
    dlmwrite('dn.txt', dn)
    dc = ttn(dc);
    dlmwrite('dc.txt', dc)
elseif strcmp(md,'D')+strcmp(md,'d') == 1
    dl = input('Delete deck number: ');
    if isempty(dl) == 0 && dl <= l
    ds = dld(ds,dl);
    dn = dld(dn,dl);
    dc = dld(dc,dl);
    dlmwrite('ds.txt', ds)
    dn = ttn(dn);
    dlmwrite('dn.txt', dn)
    dc = ttn(dc);
    dlmwrite('dc.txt', dc)
    end
elseif strcmp(md,'V')+strcmp(md,'v') == 1
        pw = zeros(l,1);
    for g = 1:l
        pw(g) = (ds(g,1)+1)/(ds(g,1)+ds(g,2)+1);
    end
    ap = mean(pw);
    for gb = 1:l
        if pw(gb) < ap/2
            pw(gb) = 0;
        else
            %weight for viewing selection percentage next line
            pw(gb) = (pw(gb)^1.5)/sqrt((ds(gb,1)+ds(gb,2)+1));
        end
    end
    fprintf('\nBL Deck Winrates:\nAverage winrate: %5.2f%%\n', sum(ds(:,1))*100/sum(sum(ds)))
    for v = 1:l
        fprintf('%2d. %s    %d Win(s)   %d Loss(es)   ', v, dn(v,:), ds(v,1), ds(v,2))
        if isnan(ds(v,1)*100/sum(ds(v,:))) == 1
            fprintf('NO GAMES PLAYED   ')
        else
            fprintf('%6.2f%% winrate   ', ds(v,1)*100/sum(ds(v,:)))
        end
        if pw(v)*100/sum(pw)==0
            fprintf('     REMOVED    ')
        else
            fprintf('%8.4f%% chance', pw(v)*100/sum(pw))
        end
        fprintf('    Deckcode: %s\n', dc(v,:))
    end
elseif strcmp(md,'M')+strcmp(md,'m') == 1
    mn = 0;
    while mn == 0 || mn > l
        mn = input('Enter deck number: ');
    end
    mp = 'none';
    while strcmp(mp,'S')+strcmp(mp,'s')+strcmp(mp,'N')+strcmp(mp,'n')+strcmp(mp,'D')+strcmp(mp,'d')<1
        mp = input('Select parameter to modify (S = Stats, N = Name, D = Deckcode): ', 's');
    end
    if strcmp(mp,'S')+strcmp(mp,'s') == 1
        ds(mn,:) = input('Enter new stats (enclose in brackets): ');
        dlmwrite('ds.txt', ds)
    elseif strcmp(mp,'N')+strcmp(mp,'n') == 1
        in = '                               ';
        while size(in,2) > 30  || size(in,2) == 0
        in = input('Input name (1 to 30 characters): ', 's');
        end
        while size(in,2) < 30
            in(1,size(in,2)+1) = ' ';
        end
        dn(mn,:) = in;
        dn = ttn(dn);
        dlmwrite('dn.txt', dn);
    elseif strcmp(mp,'D')+strcmp(mp,'d') == 1
        ic = '';
        while size(ic,2) > 243  || size(ic,2) == 0
        ic = input('Input code (Up to 60 cards + mark): ', 's');
        end
        while size(ic,2) < 243
            ic(1,size(ic,2)+1) = ' ';
        end
        dc(mn,:) = ic;
        dc = ttn(dc);
        dlmwrite('dc.txt', dc);
    end
elseif strcmp(md,'G')+strcmp(md,'g') == 1
    wt = input('Enter weight factor for deck winrates (default is 1.5): ');
    if isempty(wt)
        wt = 1.5;
    end
    pw = zeros(l,1);
    for g = 1:l
        pw(g) = (ds(g,1)+1)/(ds(g,1)+ds(g,2)+1);
    end
    ap = mean(pw);
    for gb = 1:l
        if pw(gb) < ap/2
            pw(gb) = 0;
        else
            pw(gb) = (pw(gb)^wt)/sqrt((ds(g,1)+ds(g,2)+1));
        end
    end
    pw = cumsum(pw);
    sel = pw(l)*rand(1);
    gc = 1;
    while sel > pw(gc)
        gc = gc + 1;
    end
    fprintf('\nUse the following deck:\n%s\n%s\n', dn(gc,:), dc(gc,:))
    rs = input('Enter result (W/L): ', 's');
    if isempty(rs)
        rs = 'none';
    end
    if strcmp(rs,'W')+strcmp(rs,'w') == 1
        ds(gc,1) = ds(gc,1) + 1;
        dlmwrite('ds.txt', ds)
    elseif strcmp(rs,'L')+strcmp(rs,'l') == 1
        ds(gc,2) = ds(gc,2) + 1;
        dlmwrite('ds.txt', ds)
    end
end
fprintf('\n\n')
Not so active.

 

blarg: