-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.m
More file actions
49 lines (39 loc) · 1.66 KB
/
Copy pathbenchmark.m
File metadata and controls
49 lines (39 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function [countSuccessfulGames, countedLongestLoops, countSuccessfulPrisoners] = benchmark(TEST_SUBJECTS, TOTAL_GAMES, FAST_MODE)
% Simulate the box game a certain amount
% of times and return the test data.
%
% params:
% TEST_SUBJECTS - how many prisoners should participate
% TOTAL_GAMES - how many games should be played
% FAST_MODE - set true if benchmark should skip unnecessary simulations
fprintf('Benchmark started. Please wait until it is complete...\n')
% prepare prisoners
prisoners(TEST_SUBJECTS) = Prisoner();
for i = 1:TEST_SUBJECTS
prisoners(i).badge = i;
prisoners(i).success = false;
end
% prepare boxes
boxes(TEST_SUBJECTS) = Box();
for idx = 1:TEST_SUBJECTS
boxes(idx).label = idx;
end
% Initialize variables
countedLongestLoops = zeros(1, TEST_SUBJECTS);
countSuccessfulPrisoners = zeros(1, TOTAL_GAMES);
h = waitbar(0, 'Running benchmark...'); % Waitbar (progress bar)
countSuccessfulGames = 0;
for i = 1:TOTAL_GAMES
% Simulating one game and collecting its' results.
[success, maxLoopLength, successfulPrisoners] = sim_game(TEST_SUBJECTS, prisoners, boxes, FAST_MODE);
if success
countSuccessfulGames = countSuccessfulGames + 1;
end
countedLongestLoops(maxLoopLength) = countedLongestLoops(maxLoopLength) + 1;
countSuccessfulPrisoners(i) = successfulPrisoners;
% Update waitbar according to the real benchmark progress
waitbar(i / TOTAL_GAMES, h, sprintf('Benchmark running...\nProgress: %d%%', round((i / TOTAL_GAMES) * 100)));
end
close(h);
fprintf('Benchmark completed! Results will be shown now...\n')
end