from
MATLAB Contest - Peg Solitaire
by The MATLAB Contest Team
All the files needed to develop and score an entry for the MATLABĀ® Programming Contest.
|
| runcontest(varargin)
|
function [message,results,timeElapsed] = runcontest(varargin)
%RUNCONTEST Test a Solitaire contest entry.
% [MESSAGE,RESULTS,TIME] = RUNCONTEST runs the M-file solver.m against all
% the problems defined in testsuite_sample.mat. MESSAGE returns a summary
% of the testing. RESULTS measures how well the entry solved the problem
% and TIME measures the time the entry took to compute its answer.
%
% ... = RUNCONTEST(TRUE) steps into each of the solutions.
% Copyright 2007 The MathWorks, Inc.
load testsuite_sample testsuite
if nargin == 0 % no board drawing
boards = {testsuite.board};
solutions = cell(size(testsuite));
time0 = cputime;
for i = 1:numel(testsuite)
solutions{i} = solver(testsuite(i).board);
end
timeElapsed = cputime-time0;
scores = zeros(size(testsuite));
for i = 1:numel(testsuite)
scores(i) = grade(boards{i},solutions{i});
end
else % step into each of the solutions
n = numel(testsuite);
scores = zeros(n,1);
for i = 1:n
solution = solver(testsuite(i).board);
scores(i) = grade(testsuite(i).board, solution);
solitaireGUI(testsuite(i).board,solution,min(1,5/size(solution,1)))
msg = sprintf('Board number: %d\nBoard score: %.4f',i,scores(i));
uiwait(msgbox(msg))
end
timeElapsed = NaN;
end
results = sum(scores);
message = sprintf('results: %.4f\ntime: %.2f',results,timeElapsed);
|
|
Contact us at files@mathworks.com