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:
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)
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.