Advertisement
Guest User

Untitled

a guest
Dec 8th, 2021
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let states = Array(800).fill(0).map((_, n) => [Math.floor(n / 200) % 4, Math.floor(n / 20) % 10, Math.floor(n / 4) % 5 + 1, n % 4 + 1]);
  2. states = states.map(function(n) {
  3.     return {
  4.         state: n.join(","),
  5.         val: 0
  6.     };
  7. });
  8.  
  9. // states[i] looks like
  10. // {
  11. //   state: "(player health),(opponent health),(player combo),(opponent combo)",
  12. //   val: 0
  13. // }
  14.  
  15. states[780].val = 2 ** 11 * 3 ** 7; // initialize this many starting games
  16.                                     // the number doesn't really matter, this just makes the results integers
  17.  
  18. for (let a = 0; a < 50; a++) { // do 50 rounds to make sure all the possible games finish
  19.     for (let i = 0; i < 800; i++) { // one round of simulations; 800 possible states
  20.       let state = states[i].state.split(",").map(n => parseInt(n));
  21.       if (state[0] === 0 || state[1] === 0) continue;
  22.       let newStates = [
  23.         [state[0], Math.max(state[1] - state[2], 0), state[2] + 1, 1], // win
  24.         [Math.max(state[0] - state[3], 0), state[1], 1, state[3] + 1], // loss
  25.         [state[0], state[1], 1, 1]                                     // draw
  26.       ];
  27.       if (state[2] === 1 && state[3] === 1) {newStates = newStates.slice(0, 2)} // remove draws if both combos are 1
  28.       let val = states[i].val;
  29.       states[i].val = 0;
  30.       newStates.map(n => states[n[0] * 200 + n[1] * 20 + n[2] * 4 + n[3] - 5].val += val / newStates.length);
  31.     }
  32. }
  33. console.log(states.filter(n => n.val > 0).filter(n => n.state[0] === "0").reduce((a,b) => a + b.val, 0)); // number of times othermart lady wins
  34. console.log(states.filter(n => n.val > 0).filter(n => n.state[0] !== "0").reduce((a,b) => a + b.val, 0)); // number of times player wins
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement