parent
37e1fd6e3d
commit
ad0a9750ed
14 changed files with 204 additions and 8 deletions
@ -0,0 +1,21 @@ |
|||||||
|
% compute distributation |
||||||
|
function [score, totalTimes, prs, d_rx, d_bo] = getDisProb(R, N, Radius, Length, Width, isPlot, disMethod, goalkeepMethod) |
||||||
|
score = 0; |
||||||
|
totalTimes = 0; |
||||||
|
for m = 1 : R |
||||||
|
for n = 1 : N |
||||||
|
[x, y] = disMethod(Radius); |
||||||
|
totalTimes = totalTimes + 1; |
||||||
|
if isInRect(Length/2, Width/2, x, y) && (nargin<8 || isGoalKept()) |
||||||
|
score = score + 1; |
||||||
|
if isPlot |
||||||
|
d_rx = plot(x, y, 'rx'); |
||||||
|
end |
||||||
|
else |
||||||
|
if isPlot |
||||||
|
d_bo = plot(x, y, 'bo'); |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
prs = score / totalTimes; |
||||||
|
end |
@ -0,0 +1,10 @@ |
|||||||
|
function res = getDivByPos(Length, Width, x, y) |
||||||
|
res = 0; |
||||||
|
ux=Length/4; |
||||||
|
uy=Width/2; |
||||||
|
|
||||||
|
x = x + Length/2; |
||||||
|
y = y + Width/2; |
||||||
|
|
||||||
|
px = ceil(x/ux); |
||||||
|
end |
@ -0,0 +1,13 @@ |
|||||||
|
function res = getDivByPos(Length, Width, x, y) |
||||||
|
|
||||||
|
ux=Length/4; |
||||||
|
uy=Width/2; |
||||||
|
|
||||||
|
x = x + Length/2; |
||||||
|
y = y + Width/2; |
||||||
|
|
||||||
|
px = ceil(x/ux); |
||||||
|
py = floor(y/uy); |
||||||
|
|
||||||
|
res = px + py*4; |
||||||
|
end |
@ -0,0 +1,13 @@ |
|||||||
|
function res = isGoalKept(Length, Width, x, y, goalkeepMethod) |
||||||
|
div = getDivByPos(Length, Width, x, y); |
||||||
|
act = goalkeepMethod(); |
||||||
|
|
||||||
|
pattern = [2, 3, 6, 7; ]; |
||||||
|
|
||||||
|
res = false; |
||||||
|
|
||||||
|
% case 1 |
||||||
|
if act == 1 && |
||||||
|
|
||||||
|
|
||||||
|
end |
@ -0,0 +1,13 @@ |
|||||||
|
function res = isGoalKept(Length, Width, x, y, goalkeepMethod) |
||||||
|
div = getDivByPos(Length, Width, x, y); |
||||||
|
act = goalkeepMethod(); |
||||||
|
|
||||||
|
pattern = [2, 3, 6, 7; 2, 5, 0, 0; 3, 8, 0, 0; 1, 2, 0, 0; 3, 4, 0, 0]; |
||||||
|
|
||||||
|
if ismember(div, pattern(act, :)) |
||||||
|
res = true; |
||||||
|
else |
||||||
|
res = false; |
||||||
|
end |
||||||
|
|
||||||
|
end |
@ -1,9 +1,13 @@ |
|||||||
% get random position in circle |
% get random position in circle |
||||||
function [res_x, res_y] = normrnd_circle(r) |
function [res_x, res_y] = normrnd_circle(r) |
||||||
|
|
||||||
ang = 2*pi*rand(1); |
while true |
||||||
t_r = normrnd(0, r); |
ang = 2*pi*rand(1); |
||||||
res_x = t_r*cos(ang); |
t_r = normrnd(0, r); |
||||||
res_y = t_r*sin(ang); |
res_x = t_r*cos(ang); |
||||||
|
res_y = t_r*sin(ang); |
||||||
|
if sqrt(res_x^2 + res_y^2) < r |
||||||
|
break; |
||||||
|
end |
||||||
|
|
||||||
end |
end |
||||||
|
@ -0,0 +1,4 @@ |
|||||||
|
function res = uniform_5case() |
||||||
|
|
||||||
|
|
||||||
|
end |
@ -0,0 +1,5 @@ |
|||||||
|
function res = uniform_5case() |
||||||
|
|
||||||
|
res = randi(5, 1, 1); |
||||||
|
|
||||||
|
end |
@ -0,0 +1,9 @@ |
|||||||
|
function res = uniform_5case_plus() |
||||||
|
|
||||||
|
if rand(1) <= 0.9 |
||||||
|
res = randi([4, 5], 1, 1); |
||||||
|
else |
||||||
|
res = randi(3, 1, 1); |
||||||
|
end |
||||||
|
|
||||||
|
end |
@ -0,0 +1,26 @@ |
|||||||
|
|
||||||
|
% init |
||||||
|
clear |
||||||
|
addpath(genpath('./func/')); |
||||||
|
|
||||||
|
% declear const |
||||||
|
Radius = sqrt(5); |
||||||
|
Width = 2; |
||||||
|
Length = 4; |
||||||
|
|
||||||
|
% params input |
||||||
|
N = input("Shots Times: "); |
||||||
|
R = input("Repeating Times: "); |
||||||
|
|
||||||
|
% draw background |
||||||
|
drawBackGround(Radius, Width, Length); |
||||||
|
|
||||||
|
% calculate prs |
||||||
|
[score, totalTimes, prs, d_rx, d_bo] = getDisProb(R, N, Radius, Length, Width, true, @unifrnd_circle, @uniform_5case_plus); |
||||||
|
|
||||||
|
% add legend |
||||||
|
legend([d_rx, d_bo], {'scored shot', 'missed shot'}); |
||||||
|
t_s = sprintf('Scatter plot for N=%d and R=%d. prs=%d%%', N, R, round(prs*100)); |
||||||
|
title(t_s); |
||||||
|
|
||||||
|
display(prs); |
@ -0,0 +1,26 @@ |
|||||||
|
|
||||||
|
% init |
||||||
|
clear |
||||||
|
addpath(genpath('./func/')); |
||||||
|
|
||||||
|
% declear const |
||||||
|
Radius = sqrt(5); |
||||||
|
Width = 2; |
||||||
|
Length = 4; |
||||||
|
|
||||||
|
% params input |
||||||
|
N = input("Shots Times: "); |
||||||
|
R = input("Repeating Times: "); |
||||||
|
|
||||||
|
% draw background |
||||||
|
drawBackGround(Radius, Width, Length); |
||||||
|
|
||||||
|
% calculate prs |
||||||
|
[score, totalTimes, prs, d_rx, d_bo] = getDisProb(R, N, Radius, Length, Width, true, @normrnd_circle, @uniform_5case_plus); |
||||||
|
|
||||||
|
% add legend |
||||||
|
legend([d_rx, d_bo], {'scored shot', 'missed shot'}); |
||||||
|
t_s = sprintf('Scatter plot for N=%d and R=%d. prs=%d%%', N, R, round(prs*100)); |
||||||
|
title(t_s); |
||||||
|
|
||||||
|
display(prs); |
@ -0,0 +1,26 @@ |
|||||||
|
|
||||||
|
% init |
||||||
|
clear |
||||||
|
addpath(genpath('./func/')); |
||||||
|
|
||||||
|
% declear const |
||||||
|
Radius = sqrt(5); |
||||||
|
Width = 2; |
||||||
|
Length = 4; |
||||||
|
|
||||||
|
% params input |
||||||
|
N = input("Shots Times: "); |
||||||
|
R = input("Repeating Times: "); |
||||||
|
|
||||||
|
% draw background |
||||||
|
drawBackGround(Radius, Width, Length); |
||||||
|
|
||||||
|
% calculate prs |
||||||
|
[score, totalTimes, prs, d_rx, d_bo] = getDisProb(R, N, Radius, Length, Width, true, @unifrnd_circle, @uniform_5case); |
||||||
|
|
||||||
|
% add legend |
||||||
|
legend([d_rx, d_bo], {'scored shot', 'missed shot'}); |
||||||
|
t_s = sprintf('Scatter plot for N=%d and R=%d. prs=%d%%', N, R, prs*100); |
||||||
|
title(t_s); |
||||||
|
|
||||||
|
display(prs); |
@ -0,0 +1,26 @@ |
|||||||
|
|
||||||
|
% init |
||||||
|
clear |
||||||
|
addpath(genpath('./func/')); |
||||||
|
|
||||||
|
% declear const |
||||||
|
Radius = sqrt(5); |
||||||
|
Width = 2; |
||||||
|
Length = 4; |
||||||
|
|
||||||
|
% params input |
||||||
|
N = input("Shots Times: "); |
||||||
|
R = input("Repeating Times: "); |
||||||
|
|
||||||
|
% draw background |
||||||
|
drawBackGround(Radius, Width, Length); |
||||||
|
|
||||||
|
% calculate prs |
||||||
|
[score, totalTimes, prs, d_rx, d_bo] = getDisProb(R, N, Radius, Length, Width, true, @normrnd_circle, @uniform_5case); |
||||||
|
|
||||||
|
% add legend |
||||||
|
legend([d_rx, d_bo], {'scored shot', 'missed shot'}); |
||||||
|
t_s = sprintf('Scatter plot for N=%d and R=%d. prs=%d%%', N, R, prs*100); |
||||||
|
title(t_s); |
||||||
|
|
||||||
|
display(prs); |
Loading…
Reference in new issue