2048: Difference between revisions

m
Line 262:
(IF c = 0 THEN count +:= 1 FI;
IF count = nth THEN
result := c; GOTO outreturn
FI));
outreturn: result);
 
PROC add new number = (BOARD board) VOID:
(INT nblanks = count blanks(board);
INT whatnumber := (next random >= .9 | 4 | 2);
INT whereposition := ENTIER (next random * nblanks) + 1;
 
nth blank(board, whereposition) := whatnumber);
 
PROC crowdshift = (REF[]INT row, BOOL to the end) VOID:
(INT from = (to the end | UPB row | LWB row),
to = (to the end | LWB row | UPB row),
Line 304:
FOR i TO side DO
CASE direction IN
# right # (crowdshift(board[i,], TRUE); combine(board[i,], TRUE); crowdshift(board[i,], TRUE)),
# up # (crowdshift(board[,i], FALSE); combine(board[,i], FALSE); crowdshift(board[,i], FALSE)),
# left # (crowdshift(board[i,], FALSE); combine(board[i,], FALSE); crowdshift(board[i,], FALSE)),
# down # (crowdshift(board[,i], TRUE); combine(board[,i], TRUE); crowdshift(board[,i], TRUE))
ESAC
OD;
 
PROC print board = (BOARD board)VOID:
(FOR i FROM 1 LWB board TO 21 UPB board DO
print("+");
FOR j FROM 2 LWB board TO 2 UPB board DO print("------+") OD;
Line 374:
)
</lang>
 
 
=={{header|AutoHotkey}}==
26

edits