char *ft_strtrim_bis(char const *s) { int l; int i; int j; char *p; j = count_back(s); i = count_top(s); l = ft_strlen(s); if (l - i - j <= 0) return (NULL); p = ft_strnew(l - i - j); if (i == l) return (NULL); ft_memmove(p, s + i, l - i - j); return (p); }
void legalmove_vert(char *part,board *b,turn *t, int horiz_i, int vert_i) { printf("Legal move: %s\n",part); // letters_played int pointcount = 0; int crosscheck_total=0; int multiplier = 1; int letters_used[TILES]={0}; // get word score for (int i=0;i<strlen(part);i++) { b_space curspace = b->space[horiz_i][vert_i-strlen(part)+1]; char placing = part[strlen(part)-1-i]; // current letter if(space_isempty(curspace)==true) { // if space is empty // get crosscheck points int crosscheck_pts = 0; int j; j = count_top(b,horiz_i,vert_i); while(j>0){ crosscheck_pts+=b->space[horiz_i-i][vert_i].points; j--; } while(b->space[horiz_i+1+j][vert_i].tile_letter!='-'){ crosscheck_pts+=b->space[horiz_i+1+j][vert_i].tile_letter; j++; } if (letters_used[placing-'a']<t->curr->off_rack[i]) { // if character tile left letters_used[placing-'a']++; // show that using char // get points for word placed if (curspace.special==12) { // double letter pointcount+=(tilescore(placing)*2); if (b->space[horiz_i+1][vert_i-strlen(part)+i].tile_letter!='-' || b->space[horiz_i-1][vert_i-strlen(part)+i].tile_letter!='-') // if crosscheck crosscheck_pts+=(tilescore(placing)*2); // get ltr pts 2x } else if (curspace.special==13){ // triple letter pointcount+=(tilescore(placing)*3); if (b->space[horiz_i+1][vert_i-strlen(part)+i].tile_letter!='-' || b->space[horiz_i-1][vert_i-strlen(part)+i].tile_letter!='-') // if crosscheck crosscheck_pts+=(tilescore(placing)*3); // get crosscheck } else { // not special pointcount+=tilescore(placing); if (crosscheck_letter_horiz(curspace,placing)==true) pointcount+=tilescore(placing); } } else if (letters_used[26]<t->curr->off_rack[26]){ // use blank; letters_used[26]++; } // get multiplier, if any if(curspace.special==14) { multiplier*=2; // double word crosscheck_pts*=2; // double word for crosscheck points } else if(curspace.special==15) { multiplier*=3; // triple word crosscheck_pts*=3; } crosscheck_total+=crosscheck_pts; // add crosscheck points to total } else {// if there is already a tile on the board pointcount+=curspace.points; // add the value of the tile } pointcount*=multiplier; // multiply points by any double or triple WS pointcount+=crosscheck_total; // add all crosscheck points } printf("Points: %d\n",pointcount); if (pointcount>t->best_points) { t->best_points=pointcount; strcpy(t->best_word,part); } }