Advertisement
Guest User

Untitled

a guest
May 25th, 2014
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. stars_in_rank = [5 5 5 5 5 5 5 5 5 5 ...
  2. 4 4 4 4 4 ...
  3. 3 3 3 3 3 ...
  4. 2 2 2 2 2];
  5.  
  6. win_rate = 0.50:0.025:1.0;
  7.  
  8. win_streak_limit = 5;
  9. no_lose_limit = 20;
  10.  
  11.  
  12. start_rank = 25;
  13. start_stars = 0;
  14.  
  15.  
  16. iters = 5000;
  17. game_recorder = zeros(length(win_rate), iters);
  18. % Loop over the different win rates
  19. wr_iter = 0;
  20.  
  21. for wr = 1:length(win_rate)
  22.  
  23. for i = 1:iters
  24. win_streak = 0;
  25. rank = start_rank;
  26. stars = start_stars;
  27. games_played = 0;
  28. while rank > 0
  29.  
  30. % Play a game
  31. games_played = games_played + 1;
  32. % Win
  33. if rand() < win_rate(wr)
  34. win_streak = win_streak + 1;
  35.  
  36. % Check win streak
  37. if win_streak >= 3 && rank > win_streak_limit
  38. stars = stars + 2;
  39. else
  40. stars = stars + 1;
  41. end
  42.  
  43. % Check rank up
  44. if stars > stars_in_rank(rank)
  45. stars = stars - stars_in_rank(rank);
  46. rank = rank - 1;
  47. end
  48. %disp('win')
  49. %disp(['rank ' num2str(rank) ' stars ' num2str(stars)])
  50. % Lose
  51. else
  52. win_streak = 0;
  53.  
  54. % Only lose stars if low enough rank
  55. if rank < no_lose_limit
  56. stars = stars - 1;
  57. end
  58.  
  59. if stars < 0
  60. stars = stars_in_rank(rank) - 1;
  61. rank = rank + 1;
  62. end
  63. %disp('lose')
  64. %disp(['rank ' num2str(rank) ' stars ' num2str(stars) ' iter ' num2str(i)])
  65. end
  66. end
  67. game_recorder(wr, i) = games_played;
  68. end
  69. end
  70.  
  71. plot(win_rate,mean(game_recorder,2),'o-')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement