master
iotcat 5 years ago
parent 37e1fd6e3d
commit ad0a9750ed
  1. 21
      func/getDisProb.asv
  2. 6
      func/getDisProb.m
  3. 10
      func/getDivByPos.asv
  4. 13
      func/getDivByPos.m
  5. 13
      func/isGoalKept.asv
  6. 13
      func/isGoalKept.m
  7. 14
      func/normrnd_circle.m
  8. 4
      func/uniform_5case.asv
  9. 5
      func/uniform_5case.m
  10. 9
      func/uniform_5case_plus.m
  11. 26
      t10_8.m
  12. 26
      t10_9.m
  13. 26
      t8.m
  14. 26
      t9.m

@ -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

@ -1,12 +1,12 @@
% compute distributation
function [score, totalTimes, prs, d_rx, d_bo] = getDisProb(R, N, Radius, Length, Width, isPlot, method)
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] = method(Radius);
[x, y] = disMethod(Radius);
totalTimes = totalTimes + 1;
if isInRect(Length/2, Width/2, x, y)
if isInRect(Length/2, Width/2, x, y) && (nargin<8 || ~isGoalKept(Length, Width, x, y, goalkeepMethod))
score = score + 1;
if isPlot
d_rx = plot(x, y, 'rx');

@ -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
function [res_x, res_y] = normrnd_circle(r)
ang = 2*pi*rand(1);
t_r = normrnd(0, r);
res_x = t_r*cos(ang);
res_y = t_r*sin(ang);
while true
ang = 2*pi*rand(1);
t_r = normrnd(0, r);
res_x = t_r*cos(ang);
res_y = t_r*sin(ang);
if sqrt(res_x^2 + res_y^2) < r
break;
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);

26
t8.m

@ -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);

26
t9.m

@ -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…
Cancel
Save