How can I make an AI to the 2048game is there any template to how i can create it ?

2 views (last 30 days)
Diyara Rashid
Diyara Rashid on 20 Oct 2021
I wanna create my own AI
function direction = myAI4(A)
B = convertToLogBoard(A); %convert the board
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
heuristicValues(i) = ... %otherwise, evaluate the state
%find the action of the maximum heuristic value
[~, iMax] = max(heuristicValues);
direction = d{iMax}; %output the string
function u = heuristic0(B)
u = sum(B(:) == 0); %the number of bricks that are zero
function B =convertToLogBoard(B)
B(isnan(B)) = 1;
B = log2(B);
This is an exemple how an AI for the game should be but how can i make my own AI ?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!