Exemplo n.º 1
0
void DispBoard2(const BOARD *Board, const int Forbidden[]) {

   int Time, Rank, File, Square;
   static const char *Colour[] = { "Black", "?!?!?", "White" };

   Time = 0;

   if (Board == Game->Board) {
      Time = (int) ElapsedTime[0];
      if (Time < 0) Time = 0;
   }
   printf("\n  A B C D E F G H         %02d:%02d:%02d\n",Time/3600,(Time%3600)/60,Time%60);
   for (Rank = 0, Square = A1; Rank < 8; Rank++, Square++) {
      printf("%d ",Rank+1);
      for (File = 0; File < 8; File++, Square++) {
         board.Square[Rank][File].Colour = Board->Square[Square];
         if (Forbidden != NULL && Forbidden[Square]) {
            printf("= ");
            strcpy(board.Square[Rank][File].String,"#");
         } else if (IsLegalMove(Board,Square)) {
            printf(". ");
            strcpy(board.Square[Rank][File].String,"*");
         } else {
            printf("%c ","*-O"[Board->Square[Square]+1]);
            strcpy(board.Square[Rank][File].String,"");
         }
      }
      printf("%d",Rank+1);
      switch (Rank) {
         case 1 :
            printf("  %2d Disks * %2d Moves",DiskNb(Board,BLACK),Mobility(Board,BLACK));
            break;
         case 3 :
            printf("      %2d Empties",EmptyNb(Board));
            break;
         case 4 :
            if (IsFinished(Board)) {
               printf("      Game ended");
            } else {
               printf("     %s's Turn",Colour[Board->Colour+1]);
            }
            break;
         case 6 :
            printf("  %2d Disks O %2d Moves",DiskNb(Board,WHITE),Mobility(Board,WHITE));
            break;
      }
      printf("\n");
   }
   if (Board == Game->Board) {
      Time = (int) ElapsedTime[1];
      if (Time < 0) Time = 0;
   }
   printf("  A B C D E F G H         %02d:%02d:%02d\n\n",Time/3600,(Time%3600)/60,Time%60);

   board.Colour = Board->Colour;
   DispXBoard();
}
Exemplo n.º 2
0
Arquivo: game.c Projeto: zhu-jz/turtle
void DoGameMove(GAME *Game, int Move, double Value, double Time) {

   if (! IsLegalMove(Game->Board,Move)) FatalError("Illegal move in DoGameMove()");

   TurnTime = (Trust && Time >= 0.0) ? Time : Duration(TurnBegin,CurrentTime());
   ElapsedTime[Game->Board->Colour>0] += TurnTime;

   DoMove(Game->Board,Move);

   Game->Move[Game->MoveNo].Move  = Move;
   Game->Move[Game->MoveNo].Value = Value;
   Game->Move[Game->MoveNo].Time  = TurnTime;
   Game->MoveNo++;
   Game->Move[Game->MoveNo].Move  = NO_MOVE;

   TurnBegin = CurrentTime();
}
Exemplo n.º 3
0
int PhasePick (leaf **p1, int ply)
/***************************************************************************
 *
 *  A phase style routine which returns the next move to the search.
 *  Hash move is first returned.  If it doesn't fail high, captures are
 *  generated, sorted and tried.  If no fail high still occur, the rest of
 *  the moves are generated and tried.
 *  The idea behind all this is to save time generating moves which might
 *  not be needed.
 *  CAVEAT: To implement this, the way that genmoves & friends are called
 *  have to be modified.  In particular, TreePtr[ply+1] = TreePtr[ply] must
 *  be set before the calls can be made.
 *  If the board ever gets corrupted during the search, then there is a bug
 *  in IsLegalMove() which has to be fixed.
 *
 ***************************************************************************/
{
   static leaf* p[MAXPLYDEPTH];
   leaf *p2;
   int mv;
   int side;

   side = board.side;
   switch (pickphase[ply])
   {
      case PICKHASH:
         TreePtr[ply+1] = TreePtr[ply];
         pickphase[ply] = PICKGEN1;
         if (Hashmv[ply] && IsLegalMove (Hashmv[ply]))
         {
            TreePtr[ply+1]->move = Hashmv[ply];
            *p1 = TreePtr[ply+1]++;
            return (true);
         }

      case PICKGEN1:
         pickphase[ply] = PICKCAPT;
         p[ply] = TreePtr[ply+1];
         GenCaptures (ply);
         for (p2 = p[ply]; p2 < TreePtr[ply+1]; p2++)
            p2->score = SwapOff(p2->move) * WEIGHT + 
				Value[cboard[TOSQ(p2->move)]];

      case PICKCAPT:
         while (p[ply] < TreePtr[ply+1])
         {
            pick (p[ply], ply);
            if ((p[ply]->move & MOVEMASK) == Hashmv[ply])
            {
	       p[ply]++;
	       continue;
            } 
            *p1 = p[ply]++;
            return (true);
         }

      case PICKKILL1:
         pickphase[ply] = PICKKILL2;
         if (killer1[ply] && killer1[ply] != Hashmv[ply] && 
				IsLegalMove (killer1[ply]))
         {
            TreePtr[ply+1]->move = killer1[ply];
            *p1 = TreePtr[ply+1];
            TreePtr[ply+1]++;
            return (true);
         }
         
      case PICKKILL2:
         pickphase[ply] = PICKGEN2;
         if (killer2[ply] && killer2[ply] != Hashmv[ply] && 
				IsLegalMove (killer2[ply]))
         {
            TreePtr[ply+1]->move = killer2[ply];
            *p1 = TreePtr[ply+1];
            TreePtr[ply+1]++;
            return (true);
         }

      case PICKGEN2:
         pickphase[ply] = PICKREST;
         p[ply] = TreePtr[ply+1];
         GenNonCaptures (ply);
         for (p2 = p[ply]; p2 < TreePtr[ply+1]; p2++)
	 {
            p2->score = history[side][(p2->move & 0x0FFF)] + 
		taxicab[FROMSQ(p2->move)][D5]  - taxicab[TOSQ(p2->move)][E4];
	    if (p2->move & CASTLING)
	       p2->score += CASTLINGSCORE;
         }
	 
      case PICKREST:
         while (p[ply] < TreePtr[ply+1])
         {
            pick (p[ply], ply);
            mv = p[ply]->move & MOVEMASK;
            if (mv == Hashmv[ply] || mv == killer1[ply] || 
		mv == killer2[ply])
	    {
	       p[ply]++;
               continue;
	    }
            *p1 = p[ply]++;
            return (true);
         }
   }
   return (false);
}