示例#1
0
int main(int argc, char** argv)
{
    char inbuf[256];
    char playerstring[1];
    int X,Y;

    turn = 0;
    fgets(inbuf, 256, stdin);
    if (sscanf(inbuf, "game %1s %d %d %d", playerstring, &depthlimit,
                &timelimit1, &timelimit2) != 4) error("Bad initial input");
    if (timelimit2 != 0) timelimit1 = timelimit2 / 64;
    if (timelimit1 == 0 && depthlimit == 0) depthlimit = 4;

    if (playerstring[0] == 'B') me = 1; else me = -1;
    NewGame();
    if (me == 1) MakeMove();
    while (fgets(inbuf, 256, stdin)!=NULL){
        if (strncmp(inbuf,"pass",4)!=0) {
            if (sscanf(inbuf, "%d %d", &X, &Y) != 2) return 0;
            Update(gamestate, -me, X, Y);
            if (debug) printboard(gamestate, -me, ++turn, X, Y);
        }
        MakeMove();
    }
    return 0;
}
示例#2
0
/* 370 */
instruction      *rUSEREGISTER( instruction *ins )
/************************************************/
{
    instruction         *new_ins;
    instruction         *ins2;
    name                *name1;

    name1 = ins->operands[0];
    if( CanUseOp1( ins, name1 ) ) {
        new_ins = MakeMove( name1, ins->result, ins->type_class );
        ins->result = name1;
        MoveSegRes( ins, new_ins );
        SuffixIns( ins, new_ins );
        new_ins = ins;
    } else {
        name1 = AllocTemp( ins->type_class );
        new_ins = MakeMove( ins->operands[0], name1, ins->type_class );
        CheckCC( ins, new_ins );
        ins->operands[0] = name1;
        MoveSegOp( ins, new_ins, 0 );
        PrefixIns( ins, new_ins );
        ins2 = MakeMove( name1, ins->result, ins->type_class );
        ins->result = name1;
        MoveSegRes( ins, ins2 );
        SuffixIns( ins, ins2 );
        MarkPossible( ins, name1, ResultPossible( ins ) );
        ins->u.gen_table = NULL;
        GiveRegister( NameConflict( ins, name1 ), true );
    }
    return( new_ins );
}
示例#3
0
static  name    *GetNTTLSDataRef( instruction *ins, name *op, type_class_def tipe )
/**********************************************************************************
    Emit instructions to load allow a reference to op (a piece of
    TLS data) and return the resulting index name.
*/
{
    name                *tls_index;
    name                *tls_array;
    name                *t1;
    name                *t2;
    name                *t3;
    name                *temp_index;
    name                *result_index;
    instruction         *new_ins;

    tls_index = RTMemRef( RT_TLS_INDEX );
    tls_array = RTMemRef( RT_TLS_ARRAY );
    t1 = AllocTemp( WD );
    t2 = AllocTemp( WD );
    t3 = AllocTemp( WD );
    new_ins = MakeMove( tls_array, t1, WD );
    AddSegOverride( new_ins, HW_FS );
    PrefixIns( ins, new_ins );
    new_ins = MakeMove( tls_index, t2, WD );
    PrefixIns( ins, new_ins );
    new_ins = MakeBinary( OP_MUL, t2, AllocS32Const( 4 ), t2, WD );
    PrefixIns( ins, new_ins );
    new_ins = MakeBinary( OP_ADD, t1, t2, t1, WD );
    PrefixIns( ins, new_ins );
    temp_index = AllocIndex( t1, NULL, 0, WD );
    new_ins = MakeMove( temp_index, t3, WD );
    PrefixIns( ins, new_ins );
    result_index = ScaleIndex( t3, op, op->v.offset, tipe, TypeClassSize[ tipe ], 0, 0 );
    return( result_index );
}
示例#4
0
name    *StReturn( an retval, type_def *tipe, instruction **pins )
/****************************************************************/
{
    name        *retp;
    name        *ptr;
    name        *off;
    name        *seg;
    hw_reg_set  reg;

    if( CurrProc->state.attr & ROUTINE_ALLOCS_RETURN ) {
        retp = CurrProc->targ.return_points;
        AddIns( MakeUnary( OP_LA, retp, AllocRegName( CurrProc->state.return_reg ), WD ) );
        *pins = NULL;
    } else {
        if( _IsTargetModel( FLOATING_SS ) || _IsTargetModel( FLOATING_DS ) ) {
            ptr = AllocTemp( CP );
            off = OffsetPart( ptr );
            seg = SegmentPart( ptr );
            AddIns( MakeMove( AllocRegName( HW_SS ), seg, U2 ) );
        } else {
            ptr = AllocTemp( WD );
            off = ptr;
        }
        AddIns( MakeMove( CurrProc->targ.return_points, off, WD ) );
        retp = SAllocIndex( ptr, NULL, 0, TypeClass( retval->tipe ), tipe->length );
        reg = ReturnReg( WD, false );
        *pins = MakeMove( CurrProc->targ.return_points, AllocRegName( reg ), WD );
        CurrProc->state.return_reg = reg;
    }
    return( retp );
}
示例#5
0
void PGNReadFromFile (const char *file)
/****************************************************************************
 *
 *  To read a game from a PGN file.
 *
 ****************************************************************************/
{
   FILE *fp;
   char s[100], c, wmv[8], bmv[8];
   int moveno;
   leaf *p;

   fp = fopen (file, "r");
   if (fp == NULL)
   {
      printf ("Cannot open file %s\n", file);
      return;
   }

   /* Skip all the tags */
   do
   {
      if ((c = fgetc (fp)) == '[')
         fgets (s, 100, fp);
   } while (c == '[');
   ungetc (c, fp);

   InitVars ();
   while (!feof (fp))
   {
      c = fgetc(fp);
      if (c == '*') break;
      ungetc (c, fp);
      fscanf (fp, "%d. %7s %7s ", &moveno, wmv, bmv);
      p = ValidateMove (wmv);
      if (!p)
      {
	 printf ("Illegal move %d. %s\n", moveno, wmv);
	 break;
      }
      MakeMove (white, &p->move);
      strcpy (Game[GameCnt].SANmv, wmv);
      if (*bmv == '*' ) break;
      p = ValidateMove (bmv);
      if (!p)
      {
	 printf ("Illegal move %d. ... %s\n", moveno, bmv);
	 break;
      }
      MakeMove (black, &p->move);
      strcpy (Game[GameCnt].SANmv, bmv);
   }
   printf ("%d\n", GameCnt);
   fclose (fp);
   ShowBoard ();
   TTClear ();
   return;
}
示例#6
0
void
AutoMove(int From, int To, int Num)
{

	if(Num == 1) {
		MakeMove(From, To);
		return;
	}
	AutoMove(From, OTHER(From, To), Num-1);
	MakeMove(From, To);
	AutoMove(OTHER(From, To), To, Num-1);
}
示例#7
0
static void
AutoMove(int From, int To, int Num)
{
    if (Num == 1) {
	MakeMove(From, To);
	napms(500);
    } else {
	AutoMove(From, OTHER(From, To), Num - 1);
	MakeMove(From, To);
	napms(500);
	AutoMove(OTHER(From, To), To, Num - 1);
    }
}
示例#8
0
static  void    CheckOp( name **offsets, instruction *ins, name **pop ) {
/************************************************************************
    used by FixFarLocalRefs to change one far local reference to
    an index, using the appropriate multiple of 4K constant to get
    at the temporary. The constant values are adjusted after the
    prolog is generated.
*/

    name        *op;
    name        *base;
    name        *temp;
    unsigned_32 place;
    int         i;
    instruction *new_ins;

    op = *pop;
    if( op->n.class == N_INDEXED ) {
        temp = op->i.index;
        if( temp->n.class != N_TEMP ) return;
        if( !( temp->t.temp_flags & FAR_LOCAL ) ) return;
        new_ins = MakeMove( temp, AllocTemp( temp->n.name_class ), temp->n.name_class );
        *pop = ScaleIndex( new_ins->result, op->i.base,
                          op->i.constant, op->n.class, op->n.size,
                          op->i.scale, op->i.index_flags );
        PrefixIns( ins, new_ins );
        CheckOp( offsets, new_ins, &new_ins->operands[ 0 ] );
    }
    if( op->n.class != N_TEMP ) return;
    if( !( op->t.temp_flags & FAR_LOCAL ) ) return;
    base = DeAlias( op );
    place = base->t.location + ( op->v.offset - base->v.offset );
    i = place/_4K;
    if( offsets[ i ] == NULL ) {
        /*set the symbol field in the AddrConst to non-NULL for score-boarder*/
        new_ins = MakeMove( AllocAddrConst( (name *)&CurrProc, i,
                                            CONS_OFFSET, WD ),
                        AllocTemp( WD ), WD );
        offsets[ i ] = new_ins->result;
        PrefixIns( HeadBlock->ins.hd.next, new_ins );
    }
    temp = AllocTemp( WD ),
    new_ins = MakeMove( offsets[ i ], temp, WD );
    PrefixIns( ins, new_ins );
    new_ins = MakeBinary( OP_ADD, temp, AllocRegName( DisplayReg() ), temp, WD);
    PrefixIns( ins, new_ins );
    *pop = ScaleIndex( temp, op, place%_4K,
                        op->n.name_class, op->n.size, 0, X_FAKE_BASE );
}
示例#9
0
/**
 * MakeStepListForWin - 致胜招法生成器
 * @myInfo:		执棋方当前局面综合信息
 * @denInfo:	对方当前局面综合信息
 * @limit:		生成着法的数量限制
 * @return:		返回着法列表
 */
vector<Step> MakeStepListForWin(int side, unsigned int limit)
{
	SynInfo myInfo = GetBoardInfo(side, TOWIN | TOWILLWIN);
	LineInfo tempLine[2][4];//临时线信息备份
	Step tempStep;
	vector<Point>::iterator iterP, iterP2;
	vector<Step> stepList;//招法列表

	//如果存在致胜点,则直接返回第一个制胜点作为招法
	//否则选取第一个即将致胜点进行试下,并用其余试下后的第一个致胜点进行组步
	if (myInfo.winList.size() == 0)
	{
		tempStep.second = myInfo.willWinList[0];
		MakeMove(tempStep.second, tempLine, side, TOWIN);//因为必胜,故只对致胜点进行收集
		myInfo = GetBoardInfo(side, TOWIN);
		BackMove(tempStep.second, tempLine, side);
	}
	else
	{
		tempStep.second.x = tempStep.second.y = -1;
	}
	tempStep.first = myInfo.winList[0];
	tempStep.value = WINLOSE;
	stepList.push_back(tempStep);
	return stepList;
}
示例#10
0
extern  instruction     *NeedIndex( instruction *ins ) {
/*******************************************************
    Mark conflicts for any name used in instruction as as segment as
    NEEDS_SEGMENT, or split out the segment if it is marked as
    NEEDS_SEGMENT_SPLIT (move the segment operand to a temp and use the
    temp as the segment override).  Also, if any index conflicts are
    marked as NEEDS_INDEX_SPLIT, split them out into a temp as well.
*/

    name                *temp;
    name                *index;
    conflict_node       *conf;
    name                *name;

    if( ins->num_operands > NumOperands( ins ) ) {
        name = ins->operands[ins->num_operands - 1];
        conf = NameConflict( ins, name );
        if( conf != NULL && _Isnt( conf, CST_NEEDS_SEGMENT_SPLIT ) ) {
            _SetTrue( conf, CST_NEEDS_SEGMENT );
            MarkSegment( ins, name );
        } else if( name->n.class != N_REGISTER ) {
            if( conf != NULL ) {
                _SetFalse( conf, CST_NEEDS_SEGMENT );
                _SetTrue( conf, CST_WAS_SEGMENT );
            }
            temp = AllocTemp( U2 );
            ins->operands[ins->num_operands - 1] = temp;
            PrefixIns( ins, MakeMove( name, temp, U2 ) );
            MarkSegment( ins, temp );
            _SetTrue( NameConflict( ins, temp ), CST_SEGMENT_SPLIT );
            ins = ins->head.prev;
        }
    }
示例#11
0
void MakeMoveRoot(TMove& move, int wtm)
{
	MakeMove(1, move, wtm);

	cb.EnPassantB[1] = cb.EnPassantB[2];
	cb.EnPassantN[1] = cb.EnPassantN[2];
}
示例#12
0
/*
因为没有传入side参数,因此只适合计算黑子的策略
*/
int NegaMaxEngine::NegaMax(int depth)
{
	int bestScore = -INFINITY;
	int side = (m_nSearchDepth - depth)%2;
	int childNodeCount, score;

	if(depth <= 0)
	{
		return m_pEval->Evaluate(CurPosition, side);
	}
	childNodeCount = m_pMG->CreatePossibleMove(CurPosition, depth , side);
	if(childNodeCount <= 0) return NOMORE_MOVE;
	for(int i=0; i<childNodeCount; ++i)
	{
		MakeMove(&m_pMG->m_MoveList[depth][i], side);
		score = -NegaMax(depth  -1);
		UnMakeMove(&m_pMG->m_MoveList[depth][i]);
		if(score > bestScore)
		{
			bestScore = score;
			if(depth == m_nSearchDepth)
			{
				m_cmBestMove = m_pMG->m_MoveList[depth][i];
			}
		}
	}
	return bestScore;
}
示例#13
0
// Enleve tout ce qui est en echec.
void TMoveList::ChoisiMove(int ply, int wtm)
{
#ifdef JOURNAL
	journal.Log( "ChoisiMove: NbMove: %d\n", nbmove );
#endif
  if ( nbmove == 0 )
    return;

  currmove = 0;
  int iDernierValide = -1;
  // Verifier chaque coup.
  while( currmove < nbmove ) {

    // Effectuer le coup et verifier si est en echec.
    MakeMove(ply, moves[currmove], wtm);
    int bEstEchec = Check(wtm);
    UnmakeMove(ply, moves[currmove], wtm);

    // Si le coup est valide le copier dans la case suivant le dernier
    // coup valide trouver.
    if ( !bEstEchec ) {
      iDernierValide++;
      moves[iDernierValide] = moves[currmove];
    }

    currmove++;
  }
  // Nombre de coup valide.
  nbmove = iDernierValide+1;
}
示例#14
0
文件: perft.c 项目: peterwankman/vice
void PerftTest(int depth, S_BOARD *pos) {
	S_MOVELIST list[1];
	int move;
	int MoveNum = 0;
	int start = GetTimeMs();
	long cumnodes, oldnodes;

	ASSERT(CheckBoard(pos));

	PrintBoard(pos);
	printf("\nStarting Test To Depth:%d\n", depth);
	leafNodes = 0;
	
	GenerateAllMoves(pos, list);

	for(MoveNum = 0; MoveNum < list->count; ++MoveNum) {
		move = list->moves[MoveNum].move;
		if(!MakeMove(pos, move))
			continue;

		cumnodes = leafNodes;
		Perft(depth - 1, pos);
		TakeMove(pos);
		oldnodes = leafNodes - cumnodes;
		printf("move %d : %s : %ld\n", MoveNum + 1, PrMove(move), oldnodes);
	}

	printf("\nTest Complete : %ld nodes visited in %dms\n", leafNodes, GetTimeMs() - start);
}
示例#15
0
int CAlphaBetaEngine::alphabeta(int depth, int alpha, int beta)
{
	int score;
	int Count,i;
	BYTE type;

	i = IsGameOver(CurPosition, depth);
	if (i != 0)
		return i;

	if (depth <= 0)	//叶子节点取估值
		return m_pEval->Eveluate(CurPosition, (m_nMaxDepth-depth)%2);
	
	Count = m_pMG->CreatePossibleMove(CurPosition, depth, (m_nMaxDepth-depth)%2);

	for (i=0;i<Count;i++) 
	{

		type = MakeMove(&m_pMG->m_MoveList[depth][i]);
		score = -alphabeta(depth - 1, -beta, -alpha);
		UnMakeMove(&m_pMG->m_MoveList[depth][i],type); 

		if (score > alpha)
		{
			alpha = score;
			if(depth == m_nMaxDepth)
				m_cmBestMove = m_pMG->m_MoveList[depth][i];
		}
        if (alpha >= beta) 
              break;

				
	}
	return alpha;
}
示例#16
0
// During idle time make random moves if Random! has been selected
void SimpleGoPanel::Idle(wxIdleEvent& event)
{	if(!frame->playmenu->IsChecked(ID_RANDOM))
	{	if(!gnugopause && ((curmove%2==1 && frame->whitelevel>0) || (curmove%2==0 && frame->blacklevel>0)))
			frame->MakeGNUGoMove();
		return;
	}

	int x = 1+rand()%boardsize, y = 1+rand()%boardsize;
	char attempts[21][21], temp[21][21];
	memset(attempts, 0, BOARDMEMORYLEN);
	int count = 0;
	while(count<boardsize*boardsize)
	{	while(attempts[x][y]==1)
		{	x = 1+rand()%boardsize;
			y = 1+rand()%boardsize;
		}
		memcpy(temp, board, BOARDMEMORYLEN);
		if(ValidMove(temp, x, y, curmove%2+1))
		{	MakeMove(x, y);
			#ifdef __WXMSW__
			event.RequestMore();
			#endif
			return;
		}
		count++;
		attempts[x][y] = 1;
	}

	MakePass();
	#ifdef __WXMSW__
	event.RequestMore();
	#endif
}
示例#17
0
void SelfPlay()
{
	printf("\n\n--------------The Bot Will Now Play itself to Some Randomized Depth-------------\n\n");
	printf("Press Any Key To See The Next Move\n");
	BOARD *board=new BOARD;
	SetStart(board);
	getchar();
	while(1)
	{
		MOVE *list=new MOVE;
		GenMoves(board,list);
		if(list->Count==0)
		{
			printf("%c LOST THE GAME\n\n",PceSideChar[board->Side]);
			break;
		}
		int Depth=5+rand()%4;
		vector<int>BestMove=SearchPos(board,Depth);
		PrintBoard(board);
		MakeMove(board,BestMove);
		getchar();
		getchar();
	}
	StartGame();
}
示例#18
0
文件: search.c 项目: raimarHD/lcec
static int DrawMove(BOARD *board, MOVE move)
{
  MakeMove(board, &move);
  int draw = AssessDraw(board, 0);
  Takeback(board, move);
  return draw != ERRORVALUE;
}
示例#19
0
bool Chess::GetInput() {
 bool invalid = true;
 std::string input;
 while(invalid){
  Refresh();
  std::cout << "Algebraic move instructions: " << std::endl;
  getline(std::cin,input);
  if(input[0]-48 >= 1 || input[0]-48 <= boardsize){ //int
   invalid = false;
  }else
  if(input[1] >= 97 || input[1] <= 104){ //char
   invalid = false;
  }else
  if(input[3]-48 >= 1 || input[3]-48 <= boardsize){ //int
   invalid = false;
  }else
  if(input[4] >= 97 || input[4] <= 104){ //char
   invalid = false;
  }
 }
  int startY(input[0]-49), startX(input[1]-97);
  int destY(input[3]-49), destX(input[4]-97);
  if(startunit(startY,startX) != 0){
   if(startunit(startY,startX)->isWhite == whoseTurnW){
    if(MakeMove(startX,startY,destX,destY)){
     whoseTurnW = !whoseTurnW;
    }
   }
  }
  return true;
}
示例#20
0
static  name    *GetGenericTLSDataRef( instruction *ins, name *op, type_class_def tipe )
/**************************************************************************************/
{
    name                *tls;
    name                *result_index;
    name                *temp;
    instruction         *new_ins;


    tls = CurrProc->targ.tls_index;
    if( tls == NULL ) {
        tls = AllocTemp( WD );
        CurrProc->targ.tls_index = tls;
        if( !BlockByBlock ) {
            /* 2007-06-28 RomanT
             * Grrr... DropCall() inserts new ins _before_ old one, screwing
             * startup sequence. So keep call in first block, but make it
             * before next instruction of last one  (== after last one).
             */
            DropCall( HeadBlock->ins.hd.prev->head.next, tls );
        }
    }
    if( BlockByBlock ) {
        DropCall( ins, tls );
    }
    temp = AllocTemp( WD );
    new_ins = MakeMove( tls, temp, WD );
    PrefixIns( ins, new_ins );
    result_index = ScaleIndex( temp, op, op->v.offset, tipe, TypeClassSize[ tipe ], 0, 0 );
    return( result_index );
}
示例#21
0
int main()
{
	// Display a few instructions
	printf("Instructions:\nWhen ready, hit enter. You will have five seconds "
		"to place your mouse cursor in the upper left hand corner of the game board.\n"
		"\nTips: I would hit enter, then wait a few seconds and then click play. It might"
		" take a game or two to get your timing right.\n");
	system("pause");

	while (true)
	{
		CountDown(5);
		InitGame();

		// Play game for specified time_limit
		for (time_t start_time = time(0);
			start_time + time_limit - time(0) >= 0;)
		{
			GetGems();
			DisplayGrid();
			MakeMove();
			Sleep(throttle_time);
		}

		ClearGame();

		printf("Game over. . . Play again?\n");
		system("Pause");
	}
	
	return 0;
}
示例#22
0
extern void BGProcDecl( cg_sym_handle sym, type_def *tipe )
/******************************************************/
{
    type_class_def      class;
    name                *temp;
    hw_reg_set          reg;

    class = AddCallBlock( sym, tipe );
    SaveTargetModel = TargetModel;
    if( tipe != TypeNone ) {
        if( class == XX ) {
            // Handle structure returns - we need to "eat up" the first
            // register used for argument passing here, so that it isn't
            // used for passing actual arguments. NB: Must also bump
            // parm.offset here so that arguments end up in the right
            // locations.
            reg = HW_D4;
            temp = AllocTemp( WD );
            temp->v.usage |= USE_IN_ANOTHER_BLOCK;
            AddIns( MakeMove( AllocRegName( reg ), temp, WD ) );
            HW_TurnOn( CurrProc->state.parm.used, reg );
// TODO: need to do anything here?
//            HW_CTurnOn( CurrProc->state.parm.used, HW_F16 );
            CurrProc->targ.return_points = temp;
            CurrProc->state.parm.offset += REG_SIZE;
        }
    }
}
示例#23
0
void PrintRecord(Gamerec *g)
{

int i, len, count;
unsigned char xside;
Position temp;

if(g->moves[0].mtype == EMPTY)  {
  printf("\nGame record is empty.\n");
  return;  }

StartPosition(&temp);

printf("\n***** GAME RECORD *****\n");

for(len = 1; len < MAXGAMESIZE; len++)  {
  if(g->moves[(len*(len-1)/2)].mtype != EMPTY) printf("\n     %2d. ", len);
  count = 0;
  if(temp.side == WHITE) xside = BLACK;
  else xside = WHITE;
  while(count < len && !IsCheck(&temp, xside))  {
    i = len * (len - 1) / 2 + count;
    if(g->moves[i].mtype != EMPTY)   {
      PrintMove(&temp, &(g->moves[i]));
      MakeMove(&temp, &(g->moves[i]));  }
    else  {
      printf("\n");
      return;  }
    count++;  
    }
  if(temp.side == WHITE) temp.side = BLACK;
  else temp.side = WHITE;
  }
}
/* Search game tree by alpha-beta algorith */
short AlphaBeta(short alpha, short beta, short depth)
{
    short i, value, best;

    if (!depth) return Eval();

    Gen();
    best = -INFINITY;

    for (i=gen_begin[ply]; i<gen_end[ply] && best<beta; i++)
    {
        if (best > alpha) alpha = best;

        if (MakeMove(gen_dat[i].m)) value = 1000-ply;
        else value = -AlphaBeta(-beta, -alpha, depth-1);
        UnMakeMove();

        if (value > best)
        {
            best = value; if (!ply) newmove = gen_dat[i].m;
        }
    }

    return best;
}
示例#25
0
// method for making move at Left Mouse Button
void Game::OnLButtonDown(D2D1_POINT_2F ptMouse)
{
	float Start_x = m_pRenderGame->GetStart_x();
	float Start_y = m_pRenderGame->GetStart_y();
	float SquareWidth = m_pRenderGame->GetSquareWidth();
	// compute the corresponding square indices
	if (GetPlayer(m_iTurn) == Human && ptMouse.x > Start_x && ptMouse.y > Start_y)
	{
		int i = int((ptMouse.x - Start_x) / SquareWidth);
		int j = int((ptMouse.y - Start_y) / SquareWidth);
		SMOVE Move = { i,j,m_iTurn };
		if (MakeMove(Move))
		{
			InvalidateRect(m_hwnd, NULL, FALSE);
			m_pRenderGame->OnPaint(this);
			if (CheckEndGame())
			{
				InvalidateRect(m_hwnd, NULL, FALSE);
				m_pRenderGame->OnPaint(this);
				PostMessage(m_hwnd, WM_ENDGAME, 0, 0);
			}
			else if (GetPlayer(m_iTurn) == AI)
				PostMessage(m_hwnd, WM_AIMOVE, 0, 0);
		}
	}
}
示例#26
0
extern  an      PassProcParm( an rtn ) {
/**************************************/

    name        *op;
    name        *reg;

    op = AllocTemp( XX );
    op->n.size = TypePtr->length + SizeDisplayReg();
    reg = AllocRegName( DisplayReg() );
    AddIns( MakeMove( GenIns( rtn ),
            TempOffset( op, 0, ClassPointer ),
            ClassPointer ) );
    AddIns( MakeMove( reg, TempOffset( op, TypePtr->length,
                                       reg->n.name_class ),
                      reg->n.name_class ) );
    return( AddrName( op, TypeProcParm ) );
}
示例#27
0
void CAlphaBetaEngine::SearchAGoodMove(BYTE position[10][9])
{
	memcpy(CurPosition, position, 90);
	m_nMaxDepth = m_nSearchDepth;
	alphabeta(m_nMaxDepth, -20000, 20000);
	MakeMove(&m_cmBestMove);
	memcpy(position, CurPosition, 90);
}
示例#28
0
文件: uci.c 项目: raimarHD/lcec
int make_move(char *input, ENGINE_STATE *stat)
{
  char *str_param = strtok(input, " \n\t");
  if (str_param) {
    MOVE curr_move = AlgebToMove(str_param);
    if (IsLegal(stat->board, &curr_move)) MakeMove(stat->board, &curr_move);
  }
  return 1;
}
示例#29
0
int CAlphabeta_HHEngine::AlphaBeta(int nDepth, int alpha,int beta)
{
	int score;
	int Count,i;
	BYTE type;

	i=IsGameOver(CurPosition, nDepth);
	if(i!=0)
		return i;

	if(nDepth<=0)//叶子节点取估值
		return m_pEval->Eveluate(CurPosition,(m_nMaxDepth-nDepth)%2,m_nUserChessColor);
	
	Count=m_pMG->CreatePossibleMove(CurPosition,nDepth,(m_nMaxDepth-nDepth)%2,m_nUserChessColor);
	if(nDepth==m_nMaxDepth)
	{
		//在根节点设定进度条
		m_pThinkProgress->SetRange(0,Count);
		m_pThinkProgress->SetStep(1);
	}

	//取所有走法的历史得分
	for(i=0;i<Count;i++) 

		m_pMG->m_MoveList[nDepth][i].Score=GetHistoryScore(&m_pMG->m_MoveList[nDepth][i]);

	MergeSort(m_pMG->m_MoveList[nDepth],Count,0);//对Count种走法按历史得分大小排序

	int bestmove=-1;//记录最佳走法的变量

	for(i=0;i<Count;i++) 
	{
		if(nDepth==m_nMaxDepth)
			m_pThinkProgress->StepIt();//走进度条

		type=MakeMove(&m_pMG->m_MoveList[nDepth][i]);
		score=-AlphaBeta(nDepth-1,-beta,-alpha);
		UnMakeMove(&m_pMG->m_MoveList[nDepth][i],type); 

		if(score>alpha)
		{
			alpha=score;
			if(nDepth==m_nMaxDepth)
				m_cmBestMove=m_pMG->m_MoveList[nDepth][i];
			bestmove=i;
		}
        if(alpha>=beta) 
		{
			bestmove=i;
			break;
		}			
	}
	if(bestmove!=-1)
		EnterHistoryScore(&m_pMG->m_MoveList[nDepth][bestmove],nDepth);//将最佳走法汇入历史记录表

	return alpha;
}
示例#30
0
extern  void    BigGoto( int level )
/**********************************/
{
    name        *reg;

    if( level != 0 ) {
        reg = AllocRegName( DisplayReg() );
        AddIns( MakeMove( DisplayField( level ), reg, reg->n.name_class ) );
    }
}