Simulate the probability of winning the game commonly known as the Piso Game in a Peryahan (see image below) here in the Philippines.

2 ビュー (過去 30 日間)

You toss a 1-peso coin onto a board with various prizes written on it. For example, if your coin lands on the section labeled "PLATE" or "CUP," the corresponding item becomes your prize.

Consider a board size of 1200 x 1200 mm and assume that the likelihood of winning in all squares is the same. Using the Monte Carlo method, determine the probabilities of wining the game using a 20-mm dia coin when the grid size is 20mm, 60mm, 100mm until 300 mm with the interval of 40 mm. Neglect the region between squares (white areas in the image above). Consider 10,000 trials for every grid size.

回答 (1 件)

Ayush Aniket
Ayush Aniket 2024 年 12 月 17 日
Hi Norberto,
You can write a MATLAB script to simulate the Piso game by following the steps below:
  • Define Parameters: Start by defining the size of the board, the diameter of the coin, and the number of trials for your simulation.
boardSize = 1200; % mm
coinDiameter = 20; % mm
numTrials = 10000; % number of Monte Carlo trials
  • Specify Grid Sizes: Create an array of grid sizes ranging from 20 mm to 300 mm with an interval of 40 mm.
gridSizes = 20:40:300; % mm
  • Initialize Storage for Results: Prepare an array to store the probabilities for each grid size.
probabilities = zeros(size(gridSizes));
  • Loop Over Each Grid Size: Use a for loop to iterate over each grid size and perform the simulation
for g = 1:length(gridSizes)
gridSize = gridSizes(g);
successfulTrials = 0;
  • Simulate Coin Tosses: Within the grid size loop, use another for loop to simulate the coin tosses using rand function for randomly placing the center of the coin.
for trial = 1:numTrials
% Randomly place the center of the coin on the board
xCenter = rand * boardSize;
yCenter = rand * boardSize;
  • Calculate Coin Boundaries: Determine the minimum and maximum x and y coordinates of the coin.
xMin = xCenter - coinDiameter / 2;
xMax = xCenter + coinDiameter / 2;
yMin = yCenter - coinDiameter / 2;
yMax = yCenter + coinDiameter / 2;
  • Check Coin Position: Use modulus operations to check if the coin is entirely within a single square.
if (mod(xMin, gridSize) >= 0 && mod(xMax, gridSize) <= gridSize) && ...
(mod(yMin, gridSize) >= 0 && mod(yMax, gridSize) <= gridSize)
successfulTrials = successfulTrials + 1;
end
  • Calculate and Store Probability: After the trials, calculate the probability for the current grid size.
probabilities(g) = successfulTrials / numTrials;
By following these steps, you can simulate the coin tosses and calculate the probability of winning for different grid sizes using the Monte Carlo method.
  8 件のコメント
Walter Roberson
Walter Roberson 2024 年 12 月 18 日
N = 5e8;
M = 30;
matches = 0;
tic
for K = 1 : M
x = rand(1,N) * 1200;
p = find(mod(x,20) == 10);
if ~isempty(p)
fprintf('iteration %d match at position ', K); disp(p)
end
matches = matches + length(p);
end
toc
Elapsed time is 232.675331 seconds.
fprintf('Overall matches: %d out of %d\n', matches, M*N );
Overall matches: 0 out of 15000000000
Walter Roberson
Walter Roberson 2024 年 12 月 19 日
More correctly for ensuring that the coin does not overlap the grid edges:
R = coinDiameter/2;
%...
xMinmod = mod(xMin, gridSize);
yMinmod = mod(yMin, gridSize);
if xMinmod >= R & xMinmod <= gridSize-R & yMinmod >= R & yMinmod <= gridSize-R

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStrategy & Logic についてさらに検索

タグ

製品


リリース

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by