Skip to content

Commit

Permalink
an exact reverse engineered cole of 2048 is made
Browse files Browse the repository at this point in the history
  • Loading branch information
eightnoteight committed Jun 22, 2014
1 parent e9c4c8e commit 305b7c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 14 additions & 5 deletions 2048.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ void printboard()
{
int i,j;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
mvprintw(((row-9)/2) + i*2,((col-32)/2) + j*10,"%d ", board[i][j]);
}
}
}
int boardcount()
{
Expand Down Expand Up @@ -85,15 +81,27 @@ inline void bunchcall(int* p, int* q, int* r, int* s)
zerodrag(p,q,r,s);
sumsitup(p,q,r,s);
}
char* hashgen()
{
int i;
for (i = 0; i < 16; ++i)
{
hash[i]=board[i/4][i%4]+48;
}
hash[16]='\0';
return hash;
}
boool gameinit()
{
int c;
int i;
char hashi[17];
randinsertboard();
randinsertboard();
printboard();
while((c=getch())!=27)
{
strcpy(hashi,hashgen());
switch(c)
{
case UP_KEY:
Expand All @@ -113,7 +121,8 @@ boool gameinit()
bunchcall(&board[i][3],&board[i][2],&board[i][1],&board[i][0]);
break;
}
randinsertboard();
if (strcmp(hashi,hashgen())!=0)
randinsertboard();
printboard();
switch(boardcheck())
{
Expand Down
3 changes: 1 addition & 2 deletions 2048.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#include <setjmp.h>
#include <signal.h>
#include <ncurses.h>

int row,col;
char hash[17];
typedef enum { False, True } boool;

int board[4][4] = {
{0,0,0,0},
{0,0,0,0},
Expand Down

0 comments on commit 305b7c6

Please sign in to comment.