Advertisement
Guest User

BlizzconSimulationCode

a guest
Oct 27th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 9.67 KB | None | 0 0
  1. clear all; close all; clc
  2. %This script determines which players are most likely to win in the 2016
  3. %Blizzcon tournament
  4.  
  5. %Deck lineups is a binary list with players as the columns
  6. deck_lineups=[1,1,1,1,0,1,1,0,1,1,1,1,0,1,1,1;0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0;1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,0;0,0,0,0,0,1,0,0,1,1,1,0,0,0,0,1;0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0;0,1,0,0,1,1,0,0,1,0,1,1,1,1,1,1;0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0;1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1;0,0,1,1,1,0,1,0,0,0,0,1,1,0,0,0;1,0,1,0,0,1,0,0,1,1,1,0,0,1,1,1;0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0;0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0];
  7.  
  8. players={'Handsomeguy','Cydonia','Jasonzhou','ThijsNL','BBgungun','Naiman','Che0nsu','Hamster','DrHippi','Breath','Amnesiacsc','Yulsic','OmegaZero','DdaHyoni','Pavel','HotMEOWTH'};
  9. decks={'Malygos Druid';'Ramp Druid';'Midrange Hunter';'Face Secret Hunter';'Freeze Mage';'Tempo Mage';'Anyfin Paladin';'Nzoth Priest';'Miracle Rogue';'Midrange Shaman';'Warlock Zoo';'Control Warrior';'Cthun Warrior';'Dragon Warrior'};
  10.  
  11. %Deck matchups from vS Data Reaper Report
  12. deck_matchups=[0.500000000000,0.491071428571,0.509314794620,0.489650446956,0.700251874550,0.536059259259,0.534085769500,0.553534956795,0.558823059725,0.421712057563,0.372612470403,0.530384528476,0.488961488961,0.477513355998;0.508928571429,0.500000000000,0.458193979933,0.506591337100,0.726666666667,0.584750566893,0.440098661029,0.657575757576,0.487476434150,0.430501316865,0.477370689655,0.543793793794,0.375000000000,0.446428571429;0.490685205380,0.541806020067,0.500000000000,0.419484702093,0.693760459001,0.536483253589,0.688164893617,0.600775193798,0.478070175439,0.369210561173,0.407144902635,0.749700956938,0.694444444444,0.517850637523;0.510349553044,0.493408662900,0.580515297907,0.500000000000,0.688616251006,0.537187063635,0.528293010753,0.603772785078,0.633607701175,0.455229962477,0.431682721869,0.579533217511,0.541832219614,0.473299039227;0.299748125450,0.273333333333,0.306239540999,0.311383748994,0.500000000000,0.332898608882,0.602373231132,0.536637931034,0.595478723404,0.576345242854,0.534060113328,0.199220338983,0.083139534884,0.311940298507;0.463940740741,0.415249433107,0.463516746411,0.462812936365,0.667101391118,0.500000000000,0.546376811594,0.600411522634,0.497895231319,0.471326528819,0.442114188807,0.540508580493,0.480357142857,0.470456972841;0.465914230500,0.559901338971,0.311835106383,0.471706989247,0.397626768868,0.453623188406,0.500000000000,0.579623287671,0.379508556384,0.427387133412,0.548300536673,0.615283459965,0.665526315789,0.437500000000;0.446465043205,0.342424242424,0.399224806202,0.396227214922,0.463362068966,0.399588477366,0.420376712329,0.500000000000,0.355827236555,0.394338526976,0.497181113460,0.593264982440,0.515625000000,0.422669349430;0.441176940275,0.512523565850,0.521929824561,0.366392298825,0.404521276596,0.502104768681,0.620491443616,0.644172763445,0.500000000000,0.434904131758,0.480406955682,0.561468502295,0.567521729913,0.479344490934;0.578287942437,0.569498683135,0.630789438827,0.544770037523,0.423654757146,0.528673471181,0.572612866588,0.605661473024,0.565095868242,0.500000000000,0.551901714562,0.521635993652,0.598542873155,0.589920087657;0.627387529597,0.522629310345,0.592855097365,0.568317278131,0.465939886672,0.557885811193,0.451699463327,0.502818886540,0.519593044318,0.448098285438,0.500000000000,0.417985281548,0.488011988012,0.436013986014;0.469615471524,0.456206206206,0.250299043062,0.420466782489,0.800779661017,0.459491419507,0.384716540035,0.406735017560,0.438531497705,0.478364006348,0.582014718452,0.500000000000,0.351976450799,0.446584315927;0.511038511039,0.625000000000,0.305555555556,0.458167780386,0.916860465116,0.519642857143,0.334473684211,0.484375000000,0.432478270087,0.401457126845,0.511988011988,0.648023549201,0.500000000000,0.525869291998;0.522486644002,0.553571428571,0.482149362477,0.526700960773,0.688059701493,0.529543027159,0.562500000000,0.577330650570,0.520655509066,0.410079912343,0.563986013986,0.553415684073,0.474130708002,0.500000000000];
  13. gosu=[1111,1099,1081,1218,1052,1153,1058,1042,1198,1054,1079,983,1055,1040,1282,1121];
  14.  
  15. player_count=size(players,2);
  16. %Track bans for post-ban deck populations
  17. bans=zeros(size(decks));
  18.  
  19. %%Generate a player vs player matchup chart
  20. player_matchups=zeros(player_count);
  21.  
  22. for player1=1:player_count
  23.   for player2=1:player_count
  24.     %Simulate the match
  25.     %Determine the best ban
  26.     %Find the best deck in player's lineup against opponent's lineup
  27.     [junk,first_ban_1]=max((deck_matchups*deck_lineups(:,player2)).*deck_lineups(:,player1));
  28.     [junk,first_ban_2]=max((deck_matchups*deck_lineups(:,player1)).*deck_lineups(:,player2));
  29.    
  30.     temp_lineup_1=deck_lineups(:,player1);
  31.     temp_lineup_1(first_ban_1)=0;
  32.     temp_lineup_2=deck_lineups(:,player2);
  33.     temp_lineup_2(first_ban_2)=0;
  34.    
  35.     %Find best deck in opponent's lineup after their ban, ban that
  36.     [junk,ban_1]=max((deck_matchups*temp_lineup_1).*deck_lineups(:,player2));
  37.     [junk,ban_2]=max((deck_matchups*temp_lineup_2).*deck_lineups(:,player1));
  38.    
  39.     lineup_1=deck_lineups(:,player1);
  40.     lineup_1(ban_2)=0;
  41.     lineup_2=deck_lineups(:,player2);
  42.     lineup_2(ban_1)=0;
  43.    
  44.     %keep track of bans
  45.     if player1>player2
  46.       bans(ban_1)=bans(ban_1)+1;
  47.       bans(ban_2)=bans(ban_2)+1;
  48.     end
  49.    
  50.     %Playout each match configuration
  51.     %Find the probability that player 1 wins
  52.     %For player 1 to win, he must win with each deck, assume both players choose decks randomly
  53.     %from their remaining decks
  54.     player_matchups(player1,player2)=match_round(lineup_1,lineup_2,deck_matchups,[0,0],4);%
  55.    
  56.     %Uncomment this line for Gosu-gamers skill correction
  57.     %player_matchups(player1,player2)=player_matchups(player1,player2)*(gosu(player1)/gosu(player2))^(1/3);
  58.  
  59.   end
  60. end
  61.  
  62. %%Double Elimination rounds
  63. %Go through each group
  64. advance_first=zeros(player_count,1);
  65. advance_second=zeros(player_count,1);
  66. for group=1:4
  67.   group_set=((group-1)*4+1):(group*4);
  68.  
  69.   %Commenting first match, all others the same
  70.   %Consider making this a function
  71.  
  72.   %Round 1
  73.   %top and bottom represent the probability that each player fills that slot
  74.   top=zeros(player_count,1);
  75.   top(group_set(1))=1;
  76.   bottom=zeros(player_count,1);
  77.   bottom(group_set(2))=1;
  78.  
  79.   %Probabiity that each player wins, alternate matrix product with matchup matrix
  80.   %and Hadamard product with opposing deck.
  81.   round_1=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  82.   %This is probability to lose (needed for double elimination)
  83.   round_1_l=(player_matchups'*bottom).*top+(player_matchups'*top).*bottom;
  84.  
  85.   %Round 2
  86.   top=zeros(player_count,1);
  87.   top(group_set(3))=1;
  88.   bottom=zeros(player_count,1);
  89.   bottom(group_set(4))=1;
  90.  
  91.   round_2=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  92.   round_2_l=(player_matchups'*bottom).*top+(player_matchups'*top).*bottom;
  93.  
  94.   %Winners
  95.   top=round_1;
  96.   bottom=round_2;
  97.  
  98.   advance_first=advance_first+(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  99.   winners_l=(player_matchups'*bottom).*top+(player_matchups'*top).*bottom;
  100.  
  101.   %Elimination
  102.   top=round_1_l;
  103.   bottom=round_2_l;
  104.  
  105.   elim=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  106.  
  107.  
  108.   %Decider
  109.   top=elim;
  110.   bottom=winners_l;
  111.  
  112.   advance_second=advance_second+(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  113.  
  114.  
  115. end
  116.  
  117.  
  118. %%Single Elimination rounds
  119. %From here I have to take a guess on how they split it up
  120. %Assume they put players from the same bracket on opposite sides
  121. %Assume they match up first and second advancers
  122. A_window=[1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0]';
  123. B_window=[0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0]';
  124. C_window=[0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0]';
  125. D_window=[0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1]';
  126.  
  127. %Round 1
  128. %A1 B2
  129. top=A_window.*advance_first;
  130. bottom=B_window.*advance_second;
  131.  
  132. round_1_1=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  133.  
  134. %C1 D2
  135. top=C_window.*advance_first;
  136. bottom=D_window.*advance_second;
  137.  
  138. round_1_2=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  139.  
  140. %B1 A2
  141. top=B_window.*advance_first;
  142. bottom=A_window.*advance_second;
  143.  
  144. round_1_3=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  145.  
  146. %D1 C2
  147. top=D_window.*advance_first;
  148. bottom=C_window.*advance_second;
  149.  
  150. round_1_4=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  151.  
  152. %Semifinals
  153. top=round_1_1;
  154. bottom=round_1_2;
  155.  
  156. round_2_1=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  157.  
  158. top=round_1_3;
  159. bottom=round_1_4;
  160.  
  161. round_2_2=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  162.  
  163. %Finals
  164. top=round_2_1;
  165. bottom=round_2_2;
  166.  
  167. final_odds=(player_matchups*bottom).*top+(player_matchups*top).*bottom;
  168.  
  169.  
  170. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  171. %%%%%%%LOCAL FUNCTIONS%%%%%%%%
  172. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  173. %This recursive function determines the probability of a game, then calls the
  174. %next game.
  175. %Output is the winrate for lineup_1 in a Last-Hero-Standing match.
  176. function [win_prob] = match_round (lineup_1, lineup_2, deck_matchups, wins_losses, max_wins)
  177.   %check if match is over
  178.   if wins_losses(1)==max_wins
  179.     win_prob=1;
  180.     return
  181.     elseif wins_losses(2)==max_wins
  182.     win_prob=0;
  183.     return
  184.   end
  185.  
  186.  
  187.   %Find chances of winning with each deck
  188.   win_1=(deck_matchups*lineup_2).*lineup_1/(sum(lineup_2)*sum(lineup_1));
  189.   win_2=(deck_matchups*lineup_1).*lineup_2/(sum(lineup_2)*sum(lineup_1));
  190.  
  191.   %If you win
  192.   win_prob=sum(win_1)*match_round(lineup_1-win_1/sum(win_1),lineup_2, deck_matchups,[wins_losses(1)+1 wins_losses(2)],max_wins);
  193.  
  194.   %if you lose
  195.   win_prob=win_prob+sum(win_2)*match_round(lineup_1,lineup_2-win_2/sum(win_2),deck_matchups,[wins_losses(1) wins_losses(2)+1],max_wins);
  196.  
  197.  
  198. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement