@@ -51,6 +51,10 @@ Point foodLastPoint;
51
51
Point tailLastPoint ;
52
52
int snakeSize = 0 ;
53
53
54
+ Point controlLastPoint = {-1 , -1 };
55
+ int controlSnakeSize = 0 ;
56
+ int loops = 0 ;
57
+
54
58
void init_options (int argc , char * argv []);
55
59
void init_game (void );
56
60
// void init_score();
@@ -61,7 +65,6 @@ void draw_point(int x, int y, short color, int type);
61
65
void draw_score (Snake * snake );
62
66
void draw_walls ();
63
67
64
- int get_time (); // usleep() makes this fuction useless
65
68
int get_direction (int c );
66
69
int check_junk_pos (int x , int y );
67
70
void print_help ();
@@ -162,7 +165,6 @@ int main(int argc, char *argv[]) {
162
165
while (1 ) {
163
166
// Get a new path to follow if the autopilot or the screensaver are active
164
167
if ((selectedMode == AUTOPILOT || selectedMode == SCREENSAVER ) &&
165
- //(foodLastPoint.x != food.x || foodLastPoint.y != food.y)&&
166
168
!check_path ()) {
167
169
168
170
switch (selectedAlgorithm ) {
@@ -199,13 +201,6 @@ int main(int argc, char *argv[]) {
199
201
200
202
if (path != NULL ) {
201
203
202
- // if (selectedAlgorithm == GREEDY && !snake->onWayToFood) {
203
- // Point *p = point_create(snake->head->x, snake->head->y);
204
- // stack_push(path, p);
205
- // long_step(blocksTaken, path, snake->teleport);
206
- // free(stack_pop(path));
207
- // }
208
-
209
204
Point * point = stack_pop (path );
210
205
update_position_autopilot (snake , blocksTaken , & food , point -> x , point -> y ,
211
206
maxX , maxY );
@@ -218,24 +213,30 @@ int main(int argc, char *argv[]) {
218
213
update_position (snake , blocksTaken , & food , direction , maxX , maxY );
219
214
}
220
215
221
- // ignore this, is just a debug block
222
- // xymap_print_log(blocksTaken, snake->head->x, snake->head->y,
223
- // snake->tail->x, snake->tail->y);
224
-
225
- // FILE *fp;
226
- // fp = fopen("log.txt", "a+");
227
-
228
- // fprintf(fp, "Food (%i,%i) \n", food.x, food.y);
229
- // fclose(fp);
230
-
216
+ if (selectedMode == SCREENSAVER ) {
217
+ if (controlLastPoint .x == snake -> head -> x &&
218
+ controlLastPoint .y == snake -> head -> y &&
219
+ snake -> length == controlSnakeSize ) {
220
+ loops ++ ;
221
+ if (loops >= 2 ) {
222
+ stack_free (path );
223
+ path = a_star_search (blocksTaken , snake , maxX , maxY , food , 1 );
224
+ }
225
+ }
226
+ if (snake -> length == maxBlocks )
227
+ break ;
228
+ }
231
229
if (snake -> head -> x == food .x && snake -> head -> y == food .y ) {
232
230
if (junkCount + snake -> length < maxBlocks ) {
231
+ controlLastPoint = food ;
232
+ controlSnakeSize = snake -> length ;
233
+ loops = 0 ;
233
234
rand_pos_food (& food , blocksTaken , maxX , maxY );
235
+
234
236
} else {
235
237
food .x = -1 ;
236
238
food .y = -1 ;
237
239
}
238
- // snake->onWayToFood = 0;
239
240
240
241
if (selectedMode == ARCADE )
241
242
speed = speed - 2000 ;
@@ -289,8 +290,8 @@ int main(int argc, char *argv[]) {
289
290
2 | ▀ ▀ | ▀▀▀
290
291
3 | ▀ ▀ ▀ | ▀▀▀▀▀
291
292
292
- so from this two characters ▀ and █ we have this extra combination to fill the
293
- gaps in the snake body ▀▀ and █▀
293
+ so from this two characters ▀ and █ we have this two extra combination to fill
294
+ the gaps in the snake body ▀▀ and █▀
294
295
295
296
And like this we can have a really cool snake.
296
297
@@ -369,31 +370,9 @@ void draw_point(int x, int y, short color, int type) {
369
370
addwstr (L"▚▀" );
370
371
break ;
371
372
case 18 :
372
- addwstr (L"━━" );
373
- break ;
374
- case 19 :
375
- addwstr (L"┃ " );
376
- break ;
377
- case 20 :
378
- addwstr (L"┛ " );
379
- break ;
380
- case 21 :
381
- addwstr (L"┓ " );
382
- break ;
383
- case 22 :
384
- addwstr (L"┏━" );
385
- break ;
386
- case 23 :
387
- addwstr (L"┗━" );
388
- break ;
389
- case 24 :
390
- addwstr (L"╹ " );
391
- break ;
392
- case 25 :
393
- addwstr (L"━ " );
394
- break ;
395
- case 26 :
396
- addwstr (L"▀━" );
373
+ attron (A_BOLD );
374
+ addstr (". " );
375
+ attroff (A_BOLD );
397
376
break ;
398
377
}
399
378
attroff (COLOR_PAIR (color ));
@@ -502,6 +481,8 @@ void draw_snake(Snake *snake) {
502
481
draw_point (sPart -> x , sPart -> y , 0 , 9 );
503
482
// draw the second section of the body
504
483
draw_point (sPart -> next -> x , sPart -> next -> y , 0 , 8 );
484
+ // draw tail
485
+ draw_point (sPart2 -> x , sPart2 -> y , 0 , 18 );
505
486
break ;
506
487
case FANCY :
507
488
// draw the head
@@ -831,11 +812,6 @@ void init_options(int argc, char *argv[]) {
831
812
}
832
813
}
833
814
834
- int get_time () {
835
- clock_t difference = clock () - initTime ;
836
- return difference * 1000 / CLOCKS_PER_SEC ;
837
- }
838
-
839
815
void draw_score (Snake * snake ) {
840
816
841
817
move (minY + maxY + 1 , minX );
@@ -852,6 +828,7 @@ void draw_score(Snake *snake) {
852
828
void draw_walls () {
853
829
switch (selectedStyle ) {
854
830
case DOTS :
831
+ case FULL :
855
832
case FANCY :
856
833
if (score || walls ) {
857
834
for (int i = 0 ; i < maxX ; i ++ )
@@ -873,26 +850,26 @@ void draw_walls() {
873
850
draw_point (-1 , -1 , 4 , 17 );
874
851
draw_point (-1 , maxY , 4 , 17 );
875
852
}
876
- break ;
877
- case FULL :
878
- if (score || walls ) {
879
- for (int i = 0 ; i < maxX ; i ++ )
880
- draw_point (i , maxY , 4 , 0 );
881
- }
882
- if (walls ) {
883
- for (int i = -1 ; i < maxX + 1 ; i ++ ) {
884
- draw_point (i , -1 , 4 , 0 );
885
- }
886
-
887
- for (int i = -1 ; i < maxY + 1 ; i ++ ) {
888
- draw_point (-1 , i , 4 , 0 );
889
- }
890
-
891
- for (int i = -1 ; i < maxY + 1 ; i ++ ) {
892
- draw_point (maxX , i , 4 , 0 );
893
- }
894
- }
895
- break ;
853
+ break ; /*
854
+ case FULL:
855
+ if (score || walls) {
856
+ for (int i = 0; i < maxX; i++)
857
+ draw_point(i, maxY, 4, 0);
858
+ }
859
+ if (walls) {
860
+ for (int i = -1; i < maxX + 1; i++) {
861
+ draw_point(i, -1, 4, 0);
862
+ }
863
+
864
+ for (int i = -1; i < maxY + 1; i++) {
865
+ draw_point(-1, i, 4, 0);
866
+ }
867
+
868
+ for (int i = -1; i < maxY + 1; i++) {
869
+ draw_point(maxX, i, 4, 0);
870
+ }
871
+ }
872
+ break;*/
896
873
case ASCII :
897
874
if (score || walls ) {
898
875
for (int i = 0 ; i < maxX ; i ++ )
@@ -949,8 +926,9 @@ void print_help() {
949
926
"autopilot/screensaver mode\n."
950
927
951
928
" For now there are two options (algorithms):\n"
952
- " \"--try-hard 1\" is cpu efficient.\n"
953
- " \"--try-hard 2\" uses more cpu but it reaches the "
929
+ " \"--try-hard 1\" is cpu efficient, good for big "
930
+ "boards.\n"
931
+ " \"--try-hard 2\" uses more cpu, it reaches the "
954
932
"food faster and produces a cleaner board.\n"
955
933
" Neither of the two works well with junk in the "
956
934
"board.\n"
0 commit comments