Ejemplo n.º 1
0
static void
findstats(Pos p, Ori o)
{
	/* Recalculate cross assert and score total at 'p'
	 */
	Pos	left, right;
	Word lword, rword;
	Node n;
	Edge e;
	int	s;

	lword.n = rword.n = 0;
	if(EDGE(p))
		return;

	/* find word to the left */
	s = 0;
	for(left=PREV(p,o); HASLETTER(left); left = PREV(left,o))
		;
	left = NEXT(left,o);
	while (HASLETTER(left)) {
		lword.c[lword.n++] = LETTER(left);
		s += SCORE(left);
		left = NEXT(left,o);
	}
	/* find word to the right */
	for(right=NEXT(p,o); HASLETTER(right); right = NEXT(right,o)) {
		rword.c[rword.n++] = LETTER(right);
		s += SCORE(right);
	}
	if(DBG) {
		wordprint(&lword);
		print("X");
		wordprint(&rword);
		print(" [%d] ", s);
	}

	SIDE(p,o) = s;
	ISANCHOR(p) = true;

	/* calculate cross asserts */
	CROSS(p,o) = 0;
	n = traverse(root, &lword, 0);
	assert(n>=0);
	if(n>0)
		do {
			e = dict[n++];
			if ( (rword.n && isword(NODE(e), &rword)) || 
				 (!rword.n && TERM(e)) ) {
				CROSS(p,o) |= 1 << LET(e);
				DPRINT("%c, ", LET(e)+'a');
			}
		} while (!(LAST(e)));
	DPRINT("\n");
}
Ejemplo n.º 2
0
int best()
{
  int i,(*myab)();
  uint8 *mythrcnt;
  int me,x,work,score;
  u_int poscnt;

  nodes = 0;
  if (plycnt & 1) {
    mythrcnt = xthrcnt;
    myab = abx;
    me = 1;
  } else {
    mythrcnt = othrcnt;
    myab = abo;
    me = 2;
  }
  for (i = 0; i = r[i]; ) {
    if (mythrcnt[height[i]] || colthr[columns[i]] == me)
      return (plycnt&1) ? WIN2 : WIN1;
  }
  if (x = transpose(columns)) {
    score = SCORE(x);
    if (EXACT(score))
      return score;
  }
  for (i=0; i<64; i++)
     okiller[i] = xkiller[i] = 0x80;
  emptyht();
  score = myab(alp[window], bet[window]);
  poscnt = posed;
  for (work=1; poscnt>>=1; work++) ;	/* work = log of #positions stored */
  return work << 3 | score;		/* normally bestofall */
}
Ejemplo n.º 3
0
void calculate_word_score(cordinate_t start, enum word_direction wd, int player) {
	int i, j = 0;
	int score = 0, multi = 1;
	if (wd == RIGHT) {
		for (i = start.y; board_play[start.x][i] != '0' && i < BOARD_SIZE; i++) {
			j++;
			SCORE(start.x, i);
		}
	}
	else {
		for (i = start.x; board_play[i][start.y] != '0' && i < BOARD_SIZE; i++) {
			j++;
			SCORE(i, start.y);
		}
	}
	score *= multi;
	players[player].score += score;
}
Ejemplo n.º 4
0
void
play(Play *play)
{
/* put the pieces on the board,
 * adjust the board data structures.
 */
	int		j;
	Pos		p;
	char	c;

	firstmove = false;

	/* describe the play */
	if(1) {
		print("(%d,%d,%c) %d ",
			play->pos.x, play->pos.y, play->o ? 'V' : 'H', play->score);
		wordprint(&play->word);
		print("\n");
		if(DBG)
			score(&play->word, play->pos, play->o);
	}

	assert(isword(root, &play->word));

	/* place the letters */
	p = play->pos;
	for (j= play->word.n -1; j>= 0; j--) {
		if(!HASLETTER(p)){
			/* place the letter on the board */
			LETTER(p) = play->word.c[j];
			HASLETTER(p)=true;
			SPECIAL(p) = Not;	/* not needed */
			ISANCHOR(p) = false;
			SCORE(p) = play->word.blank[j] ? 0 : points[play->word.c[j]];
			adjust(p,ORTHO(play->o));
		}
		p = PREV(p,play->o);
	}
	p = NEXT(p,play->o);
	adjust(p, play->o);	 /* squares to the sides */
}
Ejemplo n.º 5
0
void MLX(int nr, int score) {
  int r,c,i,n, found,nm;
  char tmp;
  tot++;
  if(nr>0) { //Copy current state
    for(c=0;c<C;c++) {
      for(r=0;r<R;r++) s[nr][r][c]=s[nr-1][r][c];
      pos[nr][c]=pos[nr-1][c];
    }
  }
  //Crush
  while(1) {
    for(r=0;r<R;r++) for(c=0;c<C;c++) flag[r][c]=0;
    found=0;
    for(r=0;r<R;r++) {
      n=1;
      for(c=1;c<=C;c++) {
	if(c<C && s[nr][r][c]==s[nr][r][c-1]) n++;
	else {
	  if(n>=3) {
	    for(i=c-1;i>=c-n;i--) flag[r][i]=1;
	    score+=SCORE(n); 
	    found=1;
	  }
	  n=1;
	}
      }
    }
    for(c=0;c<C;c++) {
      n=1;
      for(r=1;r<=R;r++) {
	if(r<R && s[nr][r][c]==s[nr][r-1][c]) n++;
	else {
	  if(n>=3) {
	    for(i=r-1;i>=r-n;i--) flag[i][c]=1;
	    score+=SCORE(n);  
	    found=1;
	  }
	  n=1;
	}
      }
    }
    if(!found) break;
    for(c=0;c<C;c++) {
      i=0;
      for(r=R-1;r>=0;r--) if(!flag[r][c]) t[i++]=s[nr][r][c];
      while(i<R) {
	t[i++]=org[R-1-pos[nr][c]][c];
	pos[nr][c]=(pos[nr][c]+1)%R;
      }
      for(i=0;i<R;i++) s[nr][i][c]=t[R-1-i];
    } 
  }
  if(score>ma) ma=score;
  //for(i=0;i<nr;i++) printf("  ");  printf("%d\n", score);   //Graphical description of recursive tree with points  
  if(nr==N) return;
  nm=0;
  for(r=0;r<R;r++) for(c=0;c<C-1;c++) if(s[nr][r][c]!=s[nr][r][c+1]) {
      tmp=s[nr][r][c];
      s[nr][r][c]=s[nr][r][c+1];
      s[nr][r][c+1]=tmp;
      if(match(nr,r,c)||match(nr,r,c+1)) { nm++; MLX(nr+1,score); }
      tmp=s[nr][r][c];
      s[nr][r][c]=s[nr][r][c+1];
      s[nr][r][c+1]=tmp;
      }
  for(r=0;r<R-1;r++) for(c=0;c<C;c++) if(s[nr][r][c]!=s[nr][r+1][c]) {
      tmp=s[nr][r][c];
      s[nr][r][c]=s[nr][r+1][c];
      s[nr][r+1][c]=tmp;
      if(match(nr,r,c)||match(nr,r+1,c)) { nm++; MLX(nr+1,score); }
      tmp=s[nr][r][c];
      s[nr][r][c]=s[nr][r+1][c];
      s[nr][r+1][c]=tmp;
      }
  if(nm>mnm) mnm=nm;
}