Advertisement
Guest User

MTG bears vs doomblade

a guest
Mar 8th, 2024
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. var starting_life = 20;
  2. var bear_bears = 37;
  3. var bear_lands = 23;
  4. var doomblade_doomblades = 37;
  5. var doomblade_lands = 23;
  6.  
  7. //funcions
  8. function shuffle(array) {
  9. let currentIndex = array.length, randomIndex;
  10.  
  11. // While there remain elements to shuffle.
  12. while (currentIndex > 0) {
  13.  
  14. // Pick a remaining element.
  15. randomIndex = Math.floor(Math.random() * currentIndex);
  16. currentIndex--;
  17.  
  18. // And swap it with the current element.
  19. [array[currentIndex], array[randomIndex]] = [
  20. array[randomIndex], array[currentIndex]];
  21. }
  22. return array;
  23. }
  24.  
  25. var game_state = {};
  26.  
  27. function initialize_game_state(){
  28. //initialize decks
  29. var bear_deck = [];
  30. for(var i = 0; i < bear_bears; i++){
  31. bear_deck.push(1);
  32. }
  33. for(var i = 0; i < bear_lands; i++){
  34. bear_deck.push(0);
  35. }
  36. bear_deck = shuffle(bear_deck);
  37.  
  38. var doomblade_deck = [];
  39. for(var i = 0; i < doomblade_doomblades; i++){
  40. doomblade_deck.push(2);
  41. }
  42. for(var i = 0; i < doomblade_lands; i++){
  43. doomblade_deck.push(0);
  44. }
  45. doomblade_deck = shuffle(doomblade_deck);
  46.  
  47. game_state = {
  48. doomblade_life:starting_life,
  49. bear_deck:bear_deck,
  50. doomblade_deck:doomblade_deck,
  51. bear_hand:[],
  52. doomblade_hand:[],
  53. bear_lands:0,
  54. doomblade_lands:0,
  55. bears_on_board:0,
  56. bears_killed:0,
  57. turn_count:1
  58. };
  59. //starting hand
  60. for(var i = 0; i < 7; i++){
  61. game_state.bear_hand.push(game_state.bear_deck.pop());
  62. }
  63. for(var i = 0; i < 7; i++){
  64. game_state.doomblade_hand.push(game_state.doomblade_deck.pop());
  65. }
  66. }
  67.  
  68. //bear turn
  69. function bear_turn(){
  70. //draw
  71. game_state.bear_hand.push(game_state.bear_deck.pop());
  72. //play land
  73. if( game_state.bear_hand.includes(0) ){
  74. game_state.bear_hand.splice( game_state.bear_hand.indexOf(0) ,1 );
  75. game_state.bear_lands++;
  76. }
  77. //play bears
  78. var available_mana = game_state.bear_lands;
  79. while( game_state.bear_hand.includes(1) && available_mana > 1 ){
  80. game_state.bear_hand.splice( game_state.bear_hand.indexOf(1) ,1 );
  81. game_state.bears_on_board++;
  82. available_mana -= 2;
  83. }
  84. }
  85.  
  86. //doomblade turn
  87. function doomblade_turn(){
  88. //draw unless first turn
  89. if(game_state.turn_count != 1){
  90. game_state.doomblade_hand.push(game_state.doomblade_deck.pop());
  91. }
  92. //play land
  93. if( game_state.doomblade_hand.includes(0) ){
  94. game_state.doomblade_hand.splice( game_state.doomblade_hand.indexOf(0) ,1 );
  95. game_state.doomblade_lands++;
  96. }
  97. //kill bears
  98. var available_mana = game_state.doomblade_lands;
  99. while( game_state.doomblade_hand.includes(2) && game_state.bears_on_board > 0 && available_mana > 1 ){
  100. game_state.doomblade_hand.splice( game_state.doomblade_hand.indexOf(2) ,1 );
  101. game_state.bears_on_board--;
  102. game_state.bears_killed++;
  103. available_mana -= 2;
  104. }
  105. //discard cards
  106. while( game_state.doomblade_hand.length > 7 ){
  107. if( game_state.doomblade_hand.includes(0) ){
  108. game_state.doomblade_hand.splice( game_state.doomblade_hand.indexOf(0) ,1 );
  109. }else{
  110. game_state.doomblade_hand.splice( game_state.doomblade_hand.indexOf(2) ,1 );
  111. }
  112. }
  113. }
  114.  
  115. var game_over = 0;
  116.  
  117. //show game_state
  118. function show_game_state(){
  119. console.log("TURN #:" + game_state.turn_count);
  120. console.log("---BEAR HAND:" + game_state.bear_hand.toString());
  121. console.log("---BEAR LANDS:" + game_state.bear_lands);
  122. console.log("---BOARD STATE:" + game_state.bears_on_board + " BEARS");
  123. console.log("-----BEARS KILLED:" + game_state.bears_killed + " BEARS");
  124. console.log("---DOOMBLADE HAND:" + game_state.doomblade_hand.toString());
  125. console.log("---DOOMBLADE LANDS:" + game_state.doomblade_lands);
  126. console.log("---DOOMBLADE LIFE:" + game_state.doomblade_life);
  127. }
  128.  
  129.  
  130. //turn cycle
  131. function turn_cycle(){
  132. doomblade_turn();
  133. //console.log("DB TURN: " + game_state.turn_count);
  134. //show_game_state();
  135. //gg if bear deck has no cards
  136. if(game_state.bear_deck.length == 0){
  137. game_over = 1;
  138. console.log("BEAR LOSS");
  139. bear_loss++;
  140. show_game_state();
  141. return;
  142. }
  143. //gg if bear deck has lethal
  144. if(game_state.bears_on_board > 0){
  145. game_state.doomblade_life -= game_state.bears_on_board * 2;
  146. if( game_state.doomblade_life <= 0 ){
  147. game_over = 1;
  148. console.log("BEAR WIN");
  149. bear_wins++;
  150. show_game_state();
  151. return;
  152. }
  153. }
  154. bear_turn();
  155. //console.log("BEAR TURN: " + game_state.turn_count);
  156. //show_game_state();
  157. game_state.turn_count++;
  158. }
  159.  
  160. var bear_wins = 0;
  161. var bear_loss = 0;
  162.  
  163. for(var j = 0; j < 100; j++){
  164. initialize_game_state();
  165. game_over = 0;
  166. while( game_state.turn_count < 60 && game_over == 0){
  167. turn_cycle();
  168. }
  169. }
  170.  
  171. console.log(bear_wins);
  172. console.log(bear_loss);
  173.  
  174.  
  175.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement