How can I make an AI to the 2048game is there any template to how i can create it ?
2 views (last 30 days)
Show older comments
I wanna create my own AI
function direction = myAI4(A)
B = convertToLogBoard(A); %convert the board
save('myAI4inputData','A','B');
d = {'up', 'down', 'right', 'left'}; %the set of actions in the game
heuristicValues = zeros(1,4);
for i = 1:length(d)
Bnew = slide(B,d{i}); %Predictive state from action i
if isequal(Bnew ,B) %if action i does not change the state...
heuristicValues(i) = -Inf; %... then put heuristic to be -infinity
else
heuristicValues(i) = ... %otherwise, evaluate the state
heuristic0(Bnew);
end
end
%find the action of the maximum heuristic value
[~, iMax] = max(heuristicValues);
direction = d{iMax}; %output the string
end
function u = heuristic0(B)
u = sum(B(:) == 0); %the number of bricks that are zero
end
function B =convertToLogBoard(B)
B(isnan(B)) = 1;
B = log2(B);
end
This is an exemple how an AI for the game should be but how can i make my own AI ?
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!