From: bfe22 on
I need some help. I'm totally new to matlab but uni forced me to do a paper coding in mathlab so i'm having a hard time :). My question is the following:

I did find a genetic algorithm for the mastermind game online. However I should be able to determine the average guesses of the algorithm for a play of 6 colours and 4 positions. How should incorporate a function to loop for all the 4^6 elements and get an average result?
It might be a stupid question but i'm strugglin real hard!

below you can find the matlab code I have so far. Thanx!!

function mastermind(numpos, numcolors, code)
% use binary genetic algorithm to play mastermind
%
% parameters:
% numpos number of positions (default 4)
% numcolors number of colors (default 6)
% code code to use (default: random)
%
% Author : Fabian J. Theis. fabian(a)theis.name
% This software is for non-commercial use only.

if nargin<1, numpos = 4; end
if nargin<2, numcolors = 6; end
if nargin<3, code = ceil(rand(1,numpos)*numcolors); end
code

ingame=1;
round=1;
result=[];
guesses=[];

while ingame
if round == 1
% start with random guess
newguess = ceil(rand(1,numpos)*numcolors);
else
% random player...
%newguess = ceil(rand(1,numpos)*numcolors);

% genetic algorithm player
newguess = mastermind_ga_guess(guesses, result, numcolors);
end
% store old guesses
guesses = [guesses; newguess];

% output
fprintf('%2i: ',round);
for i=1:numpos
fprintf('%2i ', newguess(i));
end
fprintf(' ');
[white,black] = mastermind_evalguess(newguess, code);
for i=1:black, fprintf('b'); end
for i=1:white, fprintf('w'); end
fprintf('\n');
result=[result; [white,black]];
%pause

if black==numpos, ingame=0; else round=round+1; end
end