MATLAB: How to use optimtool to optimize a tetris game

fminsearchoptimizationoptimtool

Hello, I am trying to create a MATLAB adaptation of Tetris with an AI that efficiently plays the game. Currently I have a working AI, but it is lacking in terms of efficiency. I know that optimtool's fminsearch capability supposedly can help with finding correct weights, but the program that I have written, when loaded into fminsearch causes it to return the errors 'Error running optimization,' and 'Not enough input arguments.'
Any help with this endeavor would be hugely appreciated. Below is the program and the lines I put into optimtool's fminsearch.
@placementScore [-0.51,-0.36,0.16,-0.18]
function score = placementScore(agScore,holeScore,clearScore,bumpScore)
% uses agScore, holeScore, clearScore to make a composite score
score = (-.510066 * agScore) + (-.35663 * holeScore)+ (.161 * clearScore)+ (-.1845 * bumpScore);

Best Answer

Like all optimization solvers, fminsearch requires ONE variable as its argument. Fortunately, that variable can be a vector.
So you just need to rewrite your function as follows:
function score = placementScore(x)
% uses agScore, holeScore, clearScore to make a composite score
agScore = x(1);
holeScore = x(2);
clearScore = x(3);
bumpScore = x(4);
score = (-.510066 * agScore) + (-.35663 * holeScore)+ (.161 * clearScore)+ (-.1845 * bumpScore);
Alan Weiss
MATLAB mathematical toolbox documentation