PlayerAI_Actions PlayerAI::moveAlongThePath() { /* get next coordinates */ if (path->empty()) return NO_ACTION; int x = path->getX(); int y = path->getY(); if (debug_AI) printf("Player wants at %d,%d\n", x, y); if (x < 0 || x >= cd->mapx || y < 0 || y >= cd->mapy || cd->terrain[x][y] != 0) { purpose = BASIC; return NO_ACTION; /* rethink this action */ } if (debug_AI) printf("Move to %d,%d (%d)\n", x, y, path->size()); #define empty_cell(x,y) ( cd->map[MAX_CLIENT_VIEW + x][MAX_CLIENT_VIEW + y].type != CELL_PLAYER ) /* select move action */ PlayerAI_Actions action = NO_ACTION; if (x < cd->xpos && empty_cell(-1, 0)) action = MOVE_LEFT; if (y < cd->ypos && empty_cell(0, -1)) action = MOVE_UP; if (x > cd->xpos && empty_cell(1, 0)) action = MOVE_RIGHT; if (y > cd->ypos && empty_cell(0, 1)) action = MOVE_DOWN; path->pop(); /* update 'should be' position */ sb_wait_count = 0; sbx = x; sby = y; return action; }
int solve(int **puz, int *x, int *y, int display){ /*solves the given sudoku stored in puz, returns 1 if solve successful, returns WRONG_IP if i/p was invalid*/ int *p, s = 0, count = 0, r, q; srand(time(NULL)); int i, j, val; istack w; char c, chk; pstack POS; init(&POS); chk = check_ip(puz); if(chk == WRONG_IP){ return WRONG_IP; } if(x == NULL){ i = j = 0; } else{ i = *x; j = *y; } while(i != ROW){ empty_cell(puz, &i, &j); if(!f.found){ if(display){ display_puz(puz); refresh(); } return 1; } p = scan(puz, i, j); if(p == NULL){ return WRONG_IP; } w = pos_val(p); check: if(i_empty(&w)){ /*no possible values*/ if(!empty(&POS)){ w = pop(&POS); puz[i][j] = EMPTY; if(display){ display_puz(puz); refresh(); } count--; i = cell[count].x; j = cell[count].y; goto check; } } else if(!i_empty(&w)){ val = i_pop(&w); push(&POS, w); cell[count].x = i; cell[count].y = j; count++; } puz[i][j] = val; if(display){ display_puz(puz); refresh(); } traverse_line(&i, &j); } f.flag = 0; return 1; }