Problem 42685. Cody meets Xiangqi: foresee the unseen (Part 2)
This is the second part of the Xiangqi series. The first part in this series is: Cody meets Xiangqi: foresee the unseen (Part 1)
Being increasingly interested in Xiangqi (a.k.a., Chinese Chess), Mr. Cody has designed a new Xiangqi match for Xiang Yu and Liu Bang by taking into account the likelihood of tie games. The new rule is described as follows:
Once
1) Xiang Yu wins Na games consecutively, 2) Liu Bang wins Nb games consecutively, 3) No ties occur consecutively,
whichever comes first, Mr. Cody announces the outcome accordingly as follows:
1) Xiang Yu is the final winner, 2) Liu Bang is the final winner, 3) They end up with a final draw.
Again, Cody asks us --- active Cody players --- to foresee the outcome of this unseen match using Monte Carlo simulations. Our task is to write the following function
[Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc)
where
- a: the probability that Xiang Yu wins one individual game
- b: the probability that Liu Bang wins one individual game
- Na: # of consecutive wins required for Xiang Yu to become the final winner
- Nb: # of consecutive wins required for Liu Bang to become the final winner
- Nc: # of consecutive ties required to result in a final draw
- Pa: the probability that Xiang Yu wins the match
- Pb: the probability that Liu Bang wins the match
- Pc: the probability of a final draw
The main focus of this problem is on Monte Carlo simulations, rather than analytical approaches. Your provided solution Xiangqi2.m will be checked by a P-file EvaluateSolution.p, which mainly does 3 things as follows:
1) Call your function [Pa, Pb, Pc] = Xiangqi2(a, b, Na, Nb, Nc) and then Check if the result P = [Pa, Pb, Pc] is within tolerance of its expected value Q. That is, If norm(P - Q) < tol holds, it means that your solution is accurate enough. If this does not hold, your solution will be rejected.
2) Check if your solution is based on pure Monte Carlo simulations or analytical approaches. If it is based on analytical approaches (i.e., using analytical expressions to directly compute the probabilities), then your solution will be rejected. EvaluateSolution.p accomplishes this goal by exploiting a combination of distinct features possessed by analytical solutions, but are generally not shared by Monte Carlo simulations.
3) If your solution passes the above two checks, then the score of your solution will be determined based on the speed of your code. The faster your solution is, the smaller score you get.
If you have any concerns or suggestions on this problem, please feel free to leave me a comment. Thanks.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1099 Solvers
-
Back to basics 11 - Max Integer
785 Solvers
-
Make an awesome ramp for a tiny motorcycle stuntman
652 Solvers
-
Cell Counting: How Many Draws?
1901 Solvers
-
153 Solvers
More from this Author29
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!