% moves2048 computes the number of moves used on a 2048 game, based on the % tile values and the general score. % % Usage: % * m = moves2048(score, board) computes "m", the total number of moves % used plus two. This is the same as the total number of tiles that % appeared in the game: one on each movement, plus the two initial tiles. % * [m, p] = moves2048(score, board) also estimates the probability of a % random tile being 2. The product m*p efectively results in the total % number of "2" tiles that appeared in the game, while m*(1-p) results in % for the number of "4" tiles appeared. % % Example: % * m = moves2048(130788, [64 16 8 2; % 32 8192 512 64; % 8 1024 2048 128; % 2 64 4 2]); % % * [m, p] = moves2048(4, [4 4 2 2]) % % See also: % http://gabrielecirulli.github.io/2048/ function [m, p] = moves2048(score, board) board = board(:)'; lowerbound = max(log2(board)-2,0) * board'; moves2 = (score-lowerbound)/2 + sum(board==2); moves4 = (sum(board)-moves2*2)/4; moves = moves2+moves4; m = moves; p = moves2/moves; end