Beispiel #1
0
int main()
{
    int x,y;  // position joueur
    int touche;
    x = y = 1;
    touche = 0;
    while(touche!=27) // ECHAP
    {
        Afficher(x,y);
        touche = MyGetch();
        switch(touche)
        {
        case 'q':
            TryMove(&x,&y,0,-1);
            break;
        case 'd':
            TryMove(&x,&y,0,1);
            break;
        case 'z':
            TryMove(&x,&y,-1,0);
            break;
        case 's':
            TryMove(&x,&y,1,0);
        default:
            break;
        }
    }
    return 0;
}
Beispiel #2
0
void Board::OnKeyDown (wxKeyEvent &event)
{
    if (!isStarted || curPiece.GetShape() == NoShape)
    {
        event.Skip();
        return;
    }

    int keycode = event.GetKeyCode();

    if (keycode == 'p' || keycode == 'P')
    {
        Pause();
        return;
    }

    if (isPaused)
    {
        return;
    }

    switch (keycode)
    {
        case WXK_LEFT:
            TryMove (curPiece, curX - 1, curY);
            break;

        case WXK_RIGHT:
            TryMove (curPiece, curX + 1, curY);
            break;

        case WXK_DOWN:
            TryMove (curPiece.RotateRight(), curX, curY);
            break;

        case WXK_UP:
            TryMove (curPiece.RotateLeft(), curX, curY);
            break;

        case WXK_SPACE:
            DropDown();
            break;

        case 'd':
            OneLineDown();
            break;

        case 'D':
            OneLineDown();
            break;

        default:
            event.Skip();
    }
}
Beispiel #3
0
void CLogicBoad::NewPiece()
{
	curPiece.SetRandomShape();
	curX = BoardWidth / 2 + 1;
	curY = BoardHeight - 1 + curPiece.MinY();

	if (!TryMove(curPiece, curX, curY)) {
		curPiece.SetShape(NoShape);
		isStarted = false;
		
		stTetrisDrawText cmd;
		if (m_user && m_user->m_GameRoom) {
			CGameRoom* pRoom = m_user->m_GameRoom;
			for (int i =0 ;i  < 2; ++i) {
				CPlayer* pUser = pRoom->m_vPlayer[i];
				if (pUser) {
					if (pUser != m_user) {
						cmd.isMe = false;
						sprintf(cmd.szDrawText,"%s最终得分:%d",m_user->szAccount,numLinesRemoved);
					}else {
						cmd.isMe = true;
						sprintf(cmd.szDrawText,"游戏结束,您的得分:%d",numLinesRemoved);
					}
					pUser->SendToMe((stBaseCmd*)&cmd,sizeof(cmd));
				}
			}
		}
	}
}
Beispiel #4
0
void Board::OneLineDown()
{
    if (!TryMove (curPiece, curX, curY - 1))
    {
        PieceDropped();
    }
}
// 활성 아이템 오브젝트 처리 (이텍트 == 칼)
void MoveEffect() {
  int i;
  for(i = 0; i<40; ++i) {
    if(effect[i].state == DEAD)
      continue;
    if(clock() - effect[i].tick > speed_fastest) {
      effect[i].tick = clock();
      enum ObjectType target = TryMove(effect[i].pos, effect[i].dir);
      if(target == WALL) {
        effect[i].state = DEAD;
        effect[i].dir = STOP;
      }
      else if(target == PLAYER) {
        Move(&effect[i].pos, effect[i].dir);
        int j;
        for(j = 0; j<3; ++j) {
          if(IsSamePos(&player[j].pos, &effect[i].pos))
            DamagePlayer(j);
        }
      }
      else if(target == ENEMY) {
        Move(&effect[i].pos, effect[i].dir);
        int j;
        for(j = 0; j<number_of_enemies; ++j) {
          if(IsSamePos(&enemy[j].pos, &effect[i].pos))
            DamageEnemy(j);
        }
      }
      else {
        Move(&effect[i].pos, effect[i].dir);
        refresh_object = 1;
      }
    }
  }
}
Beispiel #6
0
void
CmdMove(CORE_DATA *cd)
{
	USER_DATA *ud = UD(cd);

	// the game hasnt started
	if (ud->in_progress == false) {
		Reply("The game has not yet begun");
		return;
	}

	// check for correct arg count
	if (cd->cmd_argc != 2) {
		ReplyFmt("Usage: !move Coord,Coord");
		ReplyFmt("Example: !move e2,e4");
		return;
	}

	// make sure the player is playing
	if (IsPlaying(ud, cd->cmd_name) == false) {
		Reply("You are not playing in this match");
		return;
	}

	// replies to players in-game are via arena

	// check whos turn it is
	if (GetColor(ud, cd->cmd_name) != ud->to_move) {
		ArenaMessage("It is not your move");
		return;
	}
				
	// parse argument
	char xstr[3];
	char ystr[3];
	DelimArgs(xstr, 3, cd->cmd_argv[1], 0, ',', false);
	DelimArgs(ystr, 3, cd->cmd_argv[1], 1, ',', false);

	int x1, y1, x2, y2;
	if (ParseCoords(xstr, &x1, &y1) == true &&
	    ParseCoords(ystr, &x2, &y2) == true) {
		
		char *err = TryMove(ud, ud->to_move, x1, y1, x2, y2);
		if (err == NULL && ud->in_progress == true) {
			// successful moves are announced in TryMove()
			ud->to_move = GetOppositeColor(ud->to_move);
			LvzToMove(ud->to_move, NULL);
			ArenaMessageFmt("%s (%s) to Move",
			    GetPlayerName(ud, ud->to_move), GetColorText(ud->to_move));
		} else if (ud->in_progress == true) {
			ArenaMessageFmt("Couldn't move: %s", err);
		}
	} else {
		ArenaMessageFmt("Invalid coordinates");
	}
}
Beispiel #7
0
void Board::DropDown()
{
    int newY = curY;
    while (newY > 0) {
        if (!TryMove(curPiece, curX, newY - 1))
            break;
        --newY;
    }
    PieceDropped();
}
bool CASW_Simple_Alien::PerformMovement(float deltatime)
{
	if (!m_bMoving)
		return false;

	if (m_hMoveTarget.Get())	// if we're moving to a specific object, update our target vector with its current location
	{
		m_vecMoveTarget = m_hMoveTarget->GetAbsOrigin();
	}
	Vector vecStartDiff = m_vecMoveTarget - GetAbsOrigin();
	vecStartDiff.z = 0;

	// check we're not there already
	if (vecStartDiff.Length2D() <= m_fArrivedTolerance)
	{
		FinishedMovement();
		return true;
	}
	
	// work out the new position we want to be in
	Vector vecDir = vecStartDiff;
	vecDir.NormalizeInPlace();
	//Msg("moving with delta %f\n", delta);
	Vector vecNewPos = GetAbsOrigin() + vecDir * GetIdealSpeed() * deltatime;
	if (TryMove(GetAbsOrigin(), vecNewPos, deltatime))
	{
		// apply gravity to our new position
		ApplyGravity(vecNewPos, deltatime);

		// we moved (at least some portion, maybe all)
		UTIL_SetOrigin(this, vecNewPos);

		// check if we're close enough, or have gone past, the move target
		Vector vecEndDiff = m_vecMoveTarget - GetAbsOrigin();
		vecEndDiff.z = 0;
		if (vecStartDiff.Dot(vecEndDiff) < 0 || vecEndDiff.Length2D() <= m_fArrivedTolerance)
		{
			// we've arrived
			FinishedMovement();
		}
		return true;
	}
	else
	{
		vecNewPos = GetAbsOrigin();
		if (ApplyGravity(vecNewPos, deltatime))	// if we failed to move forward, make sure gravity is still applied
		{
			// we moved (at least some portion, maybe all)
			UTIL_SetOrigin(this, vecNewPos);
		}
	}
	
	FailedMove();
	return false;
}
// 플레이어 이동 및 충돌 검사
void MovePlayer() {
  int i;
  for(i = 0; i<number_of_players; ++i) {
    if(player[i].state == DEAD)
      continue;
    if(player[i].state == FROZEN)
      continue;
    int speed = speed_normal;
    if(player[i].state == FAST) {
      speed = speed_fast;
      if(player[i].state_end <= clock())
        player[i].state = NORMAL;
    }
    else if(player[i].state == SLOW) {
      speed = speed_slow;
    }
    else {
    }
    if(clock() - player[i].tick > speed) {
      player[i].tick = clock();
      enum ObjectType target = TryMove(player[i].pos, player[i].dir);
      if(target == WALL) {
      }
      else if(target == ENEMY || target == EFFECT) {
        Move(&player[i].pos, player[i].dir);
        DamagePlayer(i);
      }
      else if(target == FRUIT) {
        Move(&player[i].pos, player[i].dir);
        int fruit_id = FindFruitByPos(player[i].pos);
        if(!(fruit_id == -1)) {
          fruit[fruit_id].state = DEAD;
          player[i].fruit++;
          fruit_remain--;
          refresh_status = 1;
          refresh_object = 1;
        }
      }
      else if(target == ITEM) {
        Move(&player[i].pos, player[i].dir);
        int item_id = FindItemByPos(player[i].pos);
        if(!(item_id == -1)) {
          item[item_id].state = DEAD;
          player[i].item = rand()%4+1;
          refresh_status = 1;
          refresh_object = 1;
        }
      }
      else {
        Move(&player[i].pos, player[i].dir);
        refresh_object = 1;
      }
    }
  }
}
Beispiel #10
0
bool CLogicBoad::DoLogicBoardCmd( stBaseCmd* pcmd,int nLen )
{
	switch (pcmd->value)
	{
	case stTetrisRefresh::_value:
		{

		}break;
	case stTetrisOperator::_value:
		{
			stTetrisOperator* pDstcmd = (stTetrisOperator*)pcmd;
			switch (pDstcmd->btOperator)
			{
			case emTR_OPERATOR_START:
				{
					Start();
				}break;
			case emTR_OPERATOR_RIGHT:
				{
					TryMove(curPiece,curX+1,curY);
				}break;
			case emTR_OPERATOR_LEFT:
				{
					TryMove(curPiece,curX-1,curY);
				}break;
			case emTR_OPERATOR_DOWN:
				{
					TryMove(curPiece,curX,curY-1);
				}break;
			case emTR_OPERATOR_ROTATELEFT:
				{
					TryMove(curPiece.RotateLeft(),curX,curY);
				}break;
			case emTR_OPERATOR_PAUSE:
				{
					Pause();
				}break;
			}
		}break;
	}
	return true;
}
Beispiel #11
0
void CLogicBoad::NewPiece()
{
    curPiece.SetRandomShape();
    curX = BoardWidth / 2 + 1;
    curY = BoardHeight - 1 + curPiece.MinY();

    if (!TryMove(curPiece, curX, curY)) {
        curPiece.SetShape(NoShape);
        isStarted = false;
    }
}
Beispiel #12
0
bool CASW_Simple_Alien::TryMove(const Vector &vecSrc, Vector &vecTarget, float deltatime, bool bStepMove)
{
	// do a trace to the dest
	Ray_t ray;
	trace_t trace;
	CTraceFilterSimple traceFilter(this, GetCollisionGroup() );
	ray.Init( vecSrc, vecTarget, GetHullMins(), GetHullMaxs() );
	enginetrace->TraceRay( ray, MASK_NPCSOLID, &traceFilter, &trace );
	if (trace.startsolid)
	{
		// doh, we're stuck in something!
		//  todo: move us to a safe spot? wait for push out phys props?
		if (asw_debug_simple_alien.GetBool())
			Msg("CASW_Simple_Alien stuck!\n");
		m_MoveFailure.trace = trace;
		m_MoveFailure.vecStartPos = vecSrc;
		m_MoveFailure.vecTargetPos = vecTarget;
		return false;
	}
	if (trace.fraction < 0.1f)	 // barely/didn't move
	{
		// try and do a 'stepped up' move to the target
		if (!bStepMove)
		{
			Vector vecStepSrc = vecSrc;
			vecStepSrc.z += 24;
			Vector vecStepTarget = vecTarget;
			vecTarget.z += 24;
			if (TryMove(vecStepSrc, vecStepTarget, deltatime, true))
			{
				vecTarget = vecStepTarget;
				return true;
			}
		}

		m_MoveFailure.trace = trace;
		m_MoveFailure.vecStartPos = vecSrc;
		m_MoveFailure.vecTargetPos = vecTarget;

		return false;
	}
	else if (trace.fraction < 1)  // we hit something early, but we did move
	{
		// we hit something early
		m_MoveFailure.trace = trace;
		m_MoveFailure.vecStartPos = vecSrc;
		m_MoveFailure.vecTargetPos = vecTarget;

		vecTarget = trace.endpos;		
	}

	return true;
}
Beispiel #13
0
// tries moving checker from one cell to another (maybe with beats)
// returns: NULL if failed, otherwise byte array to be sent to another player
byte* Field::TryComplexMove(Cell from, Cell to, byte* prevBuffer)
{
	// correctness checking
	if (!from.IsGood() || !to.IsGood()) return false;
	if (!from.IsBlack() || !to.IsBlack()) return false;
	if (!IsMyChecker(from) || !IsEmptyCell(to)) return false;

	// once preserve space enought to store info about all possible beats
	if (!prevBuffer)
	{
		if (!(prevBuffer = new byte[packetSize])) return NULL;
		for (int i = 0; i < packetSize; prevBuffer[i++] = 0);
	}
	byte* subResult;

	// if no beats before checker can simply move
	if (prevBuffer[0] == 0 && (subResult = TryMove(from, to)))
		return subResult;

	// try to beat enemy and land on "to" cell
	if (subResult = TryBeat(from, to, prevBuffer)) return subResult;

	// recursively beat enemy checkers
	List jumps = GetAvailableBeatJumps(from);
	int before;	// for backup
	for (int i = 0; i < jumps.Count(); i++)
	{
		before = strlen(prevBuffer);
		if (TryBeat(from, *jumps[i], prevBuffer))
		{
			// if we can beat, check for the next beat
			if (TryComplexMove(*jumps[i], to, prevBuffer)) return prevBuffer;
			else
			{
				// if recursive beats fails, restore backup info
				Cell beaten((max(from.row, jumps[i]->row) + min(from.row, jumps[i]->row)) / 2,
					(max(from.column, jumps[i]->column) + min(from.column, jumps[i]->column)) / 2);
				enemyCheckers.Add(beaten);
				myCheckers[*jumps[i]]->MoveChecker(from);
				for (int i = before, len = strlen(prevBuffer); i < len; prevBuffer[i++] = 0);
			}
		}
	}
	jumps.Clear();

	if (!strlen(prevBuffer))
	{
		delete [] prevBuffer;
		prevBuffer = NULL;
	}
	return NULL;
}
Beispiel #14
0
void Board::NewPiece()
{
    curPiece.SetRandomShape();
    curX = BoardWidth / 2 + 1;
    curY = BoardHeight - 1 + curPiece.MinY();

    if (!TryMove(curPiece, curX, curY)) {
        curPiece.SetShape(NoShape);
        timer->Stop();
        isStarted = false;
        m_stsbar->SetStatusText(wxT("game over"));
    }
}
Beispiel #15
0
// 적 이동 및 충돌 검사
void MoveEnemy() {
  int i;
  for(i = 0; i<number_of_enemies; ++i) {
    if(enemy[i].state == DEAD)
      continue;
    if(enemy[i].state == FROZEN) {
      if(enemy[i].state_end <= clock()) {
        enemy[i].state = SLOW;
        enemy[i].state_end = clock()+5000;
      }
      else {
        continue;
      }
    }
    int speed = speed_normal;
    if(enemy[i].state == FAST) {
      speed = speed_fast;
    }
    else if(enemy[i].state == SLOW) {
      speed = speed_slow;
      if(enemy[i].state_end <= clock())
        enemy[i].state = NORMAL;
    }
    else {
    }
    if(clock() - enemy[i].tick > speed) {
      enemy[i].tick = clock();
      enum ObjectType target = TryMove(enemy[i].pos, enemy[i].dir);
      if(target == WALL) {
        enemy[i].dir = rand()%4+1;
        enemy[i].tick -= 1000;
      }
      else if(target == PLAYER) {
        Move(&enemy[i].pos, enemy[i].dir);
        int j;
        for(j = 0; j<3; ++j) {
          if(IsSamePos(&player[j].pos, &enemy[i].pos))
            DamagePlayer(j);
        }
      }
      else if(target == EFFECT) {
        DamageEnemy(i);
      }
      else {
        Move(&enemy[i].pos, enemy[i].dir);
        refresh_object = 1;
      }
    }
  }
}
Beispiel #16
0
void L_ToGround( ati_t *ati )
{
	vec3d_t		pos, newpos;

	__chkptr( ati->ftbl->GetOrigin );
	__chkptr( ati->ftbl->SetOrigin );

	ati->ftbl->GetOrigin( ati, pos );
	Vec3dCopy( newpos, pos );

	newpos[1]-=8.0;

	TryMove( pos, newpos );
	
	ati->ftbl->SetOrigin( ati, newpos );
}
Beispiel #17
0
void IMovable::ProcessForce()
{
    Dir step = VDirToDir(force_);

    TryMove(step);

    if (!NonZero(force_))
    {
        return;
    }

    VDir vstep = DirToVDir[step];
    force_.x -= (vstep.x * Friction::CombinedFriction(GetTurf())) / Friction::BASE_FRICTION;
    force_.y -= (vstep.y * Friction::CombinedFriction(GetTurf())) / Friction::BASE_FRICTION;
    force_.z -= (vstep.z * Friction::CombinedFriction(GetTurf())) / Friction::BASE_FRICTION;
}
Beispiel #18
0
static void AddEcco(const char *szPgnFile, const EccoApiStruct &EccoApi) {
  int i, nStatus;
  uint32_t dwEccoIndex, dwFileMove[20];
  PgnFileStruct pgn;
  PositionStruct pos;

  if (pgn.Read(szPgnFile, NO_ADVERT)) {
    pos.FromFen(cszStartFen);
    for (i = 1; i <= MIN(pgn.nMaxMove, 20); i ++) {
      dwFileMove[i - 1] = Move2File(pgn.wmvMoveTable[i], pos);
      TryMove(pos, nStatus, pgn.wmvMoveTable[i]);
    }
    if (pgn.nMaxMove < 20) {
      dwFileMove[pgn.nMaxMove] = 0;
    }
    dwEccoIndex = EccoApi.EccoIndex((const char *) dwFileMove);
    strcpy(pgn.szEcco, (const char *) &dwEccoIndex);
    strcpy(pgn.szOpen, EccoApi.EccoOpening(dwEccoIndex));
    strcpy(pgn.szVar, EccoApi.EccoVariation(dwEccoIndex));
    pgn.Write(szPgnFile);
  }
}
Beispiel #19
0
void CLogicBoad::OneLineDown()
{
	if (!TryMove(curPiece, curX, curY - 1))
		PieceDropped();
}
Beispiel #20
0
int Xqf2Pgn(const char *szXqfFile, const char *szPgnFile, const EccoApiStruct &EccoApi) {
  int i, nArg0, nArgs[4];
  int nCommentLen, mv, nStatus;
  bool bHasNext;
  PgnFileStruct pgn;
  PositionStruct pos;

  FILE *fp;
  XqfHeaderStruct xqfhd;  
  XqfMoveStruct xqfmv;
  // 版本号和加密偏移值
  int nXqfVer, nPieceOff, nSrcOff, nDstOff, nCommentOff;
  // 密钥流
  int nEncStream[32];
  // 密钥流索引号
  int nEncIndex;
  // 局面初始位置
  int nPiecePos[32];

  uint32_t dwEccoIndex, dwFileMove[20];

  fp = fopen(szXqfFile, "rb");
  if (fp == NULL) {
    return XQF2PGN_ERROR_OPEN;
  }
  fread(&xqfhd, sizeof(xqfhd), 1, fp);
  fseek(fp, sizeof(xqfhd), SEEK_CUR);
  if (xqfhd.szTag[0] == 'X' && xqfhd.szTag[1] == 'Q') {
    // PGN文件可以打开,现在正式解析XQF文件
    nXqfVer = xqfhd.szTag[2];
    if (nXqfVer < 11) {
      nPieceOff = nSrcOff = nDstOff = nCommentOff = 0;
      for (i = 0; i < 32; i ++) {
        nEncStream[i] = 0;
      }
    } else {
      // 局面初始位置的加密偏移值
      nPieceOff = (uint8_t) (Square54Plus221((uint8_t) xqfhd.szTag[13]) * (uint8_t) xqfhd.szTag[13]);
      // 着法起点的加密偏移值
      nSrcOff = (uint8_t) (Square54Plus221((uint8_t) xqfhd.szTag[14]) * nPieceOff);
      // 着法终点的加密偏移值
      nDstOff = (uint8_t) (Square54Plus221((uint8_t) xqfhd.szTag[15]) * nSrcOff);
      // 注释的加密偏移值
      nCommentOff = ((uint8_t) xqfhd.szTag[12] * 256 + (uint8_t) xqfhd.szTag[13]) % 32000 + 767;
      // 基本掩码
      nArg0 = xqfhd.szTag[3];
      // 密钥 = 前段密钥 | (后段密钥 & 基本掩码)
       for (i = 0; i < 4; i ++) {
        nArgs[i] = xqfhd.szTag[8 + i] | (xqfhd.szTag[12 + i] & nArg0);
      }
      // 密钥流 = 密钥 & 密钥流掩码
      for (i = 0; i < 32; i ++) {
        nEncStream[i] = (uint8_t) (nArgs[i % 4] & cszEncStreamMask[i]);
      }
    }
    nEncIndex = 0;

    // 记录棋谱信息
    if (xqfhd.szEvent[0] == 0) {
      GetXqfString(pgn.szEvent, xqfhd.szTitle);
    } else {
      GetXqfString(pgn.szEvent, xqfhd.szEvent);
    }
    GetXqfString(pgn.szDate, xqfhd.szDate);
    GetXqfString(pgn.szSite, xqfhd.szSite);
    GetXqfString(pgn.szRed, xqfhd.szRed);
    GetXqfString(pgn.szBlack, xqfhd.szBlack);
    pgn.nResult = cnResultTrans[(int) xqfhd.szResult[3]];

    if (xqfhd.szSetUp[0] < 2) {
      // 如果是开局或者全局,那么直接设置起始局面
      pgn.posStart.FromFen(cszStartFen);
    } else {
      // 如果是中局或者排局,那么根据"xqfhd.szPiecePos[32]"的内容摆放局面
      // 当版本号达到12时,还要进一步解密局面初始位置
      if (nXqfVer < 12) {
        for (i = 0; i < 32; i ++) {
          nPiecePos[i] = (uint8_t) (xqfhd.szPiecePos[i] - nPieceOff);
        }
      } else {
        for (i = 0; i < 32; i ++) {
          nPiecePos[(nPieceOff + 1 + i) % 32] = (uint8_t) (xqfhd.szPiecePos[i] - nPieceOff);
        }
      }
      // 把"nPiecePos[32]"的数据放到"PositionStruct"中
      pgn.posStart.ClearBoard();
      for (i = 0; i < 32; i ++) {
        if (nPiecePos[i] < 90) {
          pgn.posStart.AddPiece(cucsqXqf2Square[nPiecePos[i]], cpcXqf2Piece[i]);
        }
      }
      pgn.posStart.SetIrrev();
    }
    pos = pgn.posStart;

    bHasNext = true;
    while (bHasNext && pgn.nMaxMove < MAX_MOVE_LEN) {
      // 读取着法记录
      if (nXqfVer < 11) {
        fread(&xqfmv, sizeof(xqfmv), 1, fp);
        fread(&nCommentLen, sizeof(int), 1, fp);
        if ((xqfmv.ucTag & 0xf0) == 0) {
          bHasNext = false;
        }
      } else {
        ReadAndDecrypt(fp, &xqfmv, sizeof(xqfmv), nEncStream, nEncIndex);
        if ((xqfmv.ucTag & 0x20) != 0) {
          ReadAndDecrypt(fp, &nCommentLen, sizeof(int), nEncStream, nEncIndex);
          nCommentLen -= nCommentOff;
        } else {
          nCommentLen = 0;
        }
        if ((xqfmv.ucTag & 0x80) == 0) {
          bHasNext = false;
        }
      }
      if (pgn.nMaxMove > 0) {
        // 记录着法
        mv = MOVE(cucsqXqf2Square[(uint8_t) (xqfmv.ucSrc - 24 - nSrcOff)], cucsqXqf2Square[(uint8_t) (xqfmv.ucDst - 32 - nDstOff)]);
        if (pgn.nMaxMove == 1) {
          if ((pgn.posStart.ucpcSquares[SRC(mv)] & 32) != 0) {
            pgn.posStart.ChangeSide();
            pos.ChangeSide();
          }
        }
        if (xqfhd.szSetUp[0] < 2 && pgn.nMaxMove <= 20) {
          dwFileMove[pgn.nMaxMove - 1] = Move2File(mv, pos);
        }
        TryMove(pos, nStatus, mv);
        pgn.wmvMoveTable[pgn.nMaxMove] = mv;
        if (pos.nMoveNum == MAX_MOVE_NUM) {
          pos.SetIrrev();
        }
      }
      if (nCommentLen > 0) {
        pgn.szCommentTable[pgn.nMaxMove] = new char[nCommentLen + 1];
        ReadAndDecrypt(fp, pgn.szCommentTable[pgn.nMaxMove], nCommentLen, nEncStream, nEncIndex);
        pgn.szCommentTable[pgn.nMaxMove][nCommentLen] = '\0';
      }
      pgn.nMaxMove ++;
    }
    pgn.nMaxMove --;

    // 解析ECCO
    if (xqfhd.szSetUp[0] < 2) {
      if (pgn.nMaxMove < 20) {
        dwFileMove[pgn.nMaxMove] = 0;
      }
      if (EccoApi.Available()) {
        dwEccoIndex = EccoApi.EccoIndex((const char *) dwFileMove);
        strcpy(pgn.szEcco, (const char *) &dwEccoIndex);
        strcpy(pgn.szOpen, EccoApi.EccoOpening(dwEccoIndex));
        strcpy(pgn.szVar, EccoApi.EccoVariation(dwEccoIndex));
      }
    }

    fclose(fp);
    return (pgn.Write(szPgnFile) ? XQF2PGN_OK : XQF2PGN_ERROR_CREATE);
  } else {
    fclose(fp);
    return XQF2PGN_ERROR_FORMAT;
  }
}
Beispiel #21
0
//=============================================================================
void Update(float dt)
{
	// selecting unit
	INT2 tile((cursor_pos.x + cam_pos.x)/32, (cursor_pos.y + cam_pos.y)/32);
	if(tile.x >= 0 && tile.y >= 0 && tile.x < MAP_W && tile.y < MAP_W && MousePressedRelease(1))
	{
		Tile& t = mapa[tile.x+tile.y*MAP_W];
		selected = t.unit;
	}

	// sleep button
	if(player && player->alive && player->inside_building && cursor_pos.x >= 32 && cursor_pos.y >= 700 && cursor_pos.x < 32+16 && cursor_pos.y < 700+16 && MousePressedRelease(1))
	{
		if(player->gold >= 10 && !player->sleeping && player->hp != player->base->hp)
		{
			player->gold -= 10;
			player->sleeping = true;
			player->sleeping_progress = 0.f;
		}
	}

	// update player
	if(player && player->alive && player->waiting <= 0.f && !player->moving)
	{
		Unit& u = *player;

		if(player->sleeping)
		{
			player->sleeping_progress += dt;
			if(player->sleeping_progress >= 1.f)
			{
				player->hp += 5;
				player->sleeping_progress = 0.f;
				if(player->hp >= player->base->hp)
				{
					player->hp = player->base->hp;
					player->sleeping = false;
				}
			}
		}
		else if(u.inside_building)
		{
			// unit inside building, press SPACE to exit
			if(KeyPressedRelease(SDL_SCANCODE_SPACE) && !mapa[u.pos.x+u.pos.y*MAP_W].unit)
			{
				if(!TryMove(u, DIR_S, false))
				{
					if(rand()%2 == 0)
					{
						if(!TryMove(u, DIR_SW, false))
						{
							if(TryMove(u, DIR_SE, false))
								u.inside_building = false;
						}
						else
							u.inside_building = false;
					}
					else
					{
						if(!TryMove(u, DIR_SE, false))
						{
							if(TryMove(u, DIR_SW, false))
								u.inside_building = false;
						}
						else
							u.inside_building = false;
					}
				}
				else
					u.inside_building = false;
			}
		}
		else
		{
			struct Key1
			{
				SDL_Scancode k1;
				SDL_Scancode k2;
				DIR dir;
			};
			const Key1 keys1[] = {
				SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_4, DIR_W,
				SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_6, DIR_E,
				SDL_SCANCODE_UP, SDL_SCANCODE_KP_8, DIR_N,
				SDL_SCANCODE_DOWN, SDL_SCANCODE_KP_2, DIR_S
			};
			struct Key2
			{
				SDL_Scancode k1;
				SDL_Scancode k2;
				SDL_Scancode k3;
				DIR dir;
			};
			const Key2 keys2[] = {
				SDL_SCANCODE_KP_1, SDL_SCANCODE_LEFT, SDL_SCANCODE_DOWN, DIR_SW,
				SDL_SCANCODE_KP_3, SDL_SCANCODE_RIGHT, SDL_SCANCODE_DOWN, DIR_SE,
				SDL_SCANCODE_KP_7, SDL_SCANCODE_LEFT, SDL_SCANCODE_UP, DIR_NW,
				SDL_SCANCODE_KP_9, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, DIR_NE
			};

			for(int i=0; i<4; ++i)
			{
				if(KeyDown(keys2[i].k1) || (KeyDown(keys2[i].k2) && KeyDown(keys2[i].k3)))
				{
					if(TryMove(u, keys2[i].dir, true))
						break;
				}
			}
			if(!u.moving && u.waiting <= 0.f)
			{
				for(int i=0; i<4; ++i)
				{
					if(KeyDown(keys1[i].k1) || KeyDown(keys1[i].k2))
					{
						if(TryMove(u, keys1[i].dir, true))
							break;
					}
				}
			}
		}
	}

	// update ai
	for(vector<Unit*>::iterator it = units.begin(), end = units.end(); it != end; ++it)
	{
		Unit& u = **it;
		u.attack_timer -= dt;
		if(u.hp <= 0)
		{
			if(&u == player)
				player = NULL;
			if(u.moving)
				mapa[u.new_pos.x+u.new_pos.y*MAP_W].unit = NULL;
			mapa[u.pos.x+u.pos.y*MAP_W].unit = NULL;
			delete &u;
			it = units.erase(it);
			end = units.end();
			if(it == end)
				break;
		}
		else if(u.waiting > 0.f)
			u.waiting -= dt;
		else if(u.moving)
		{
			u.move_progress += dt*u.base->move_speed;
			if(u.move_progress >= 1.f)
			{
				u.moving = false;
				mapa[u.pos.x+u.pos.y*MAP_W].unit = NULL;
				u.pos = u.new_pos;
				Tile& tile = mapa[u.pos.x+u.pos.y*MAP_W];
				if(tile.building)
				{
					tile.unit = NULL;
					u.inside_building = true;
					if(player->untaxed_gold)
					{
						int tax = player->untaxed_gold*TAX/100;
						player->untaxed_gold -= tax;
						player->gold += player->untaxed_gold;
						player->untaxed_gold = 0;
					}
				}
			}
		}
		else if(&u != player && player && player->alive && !player->inside_building)
		{
			INT2 enemy_pt;
			int dist = GetClosestPoint(u.pos, *player, enemy_pt);
			if(dist <= 50)
			{
				if(dist <= 15)
				{
					// in attack range
					if(u.attack_timer <= 0.f)
					{
						Hit& hit = Add1(hits);
						hit.pos = player->GetPos();
						hit.timer = 0.5f;
						hit._ref = player->_ref;
						u.waiting = 0.5f;
						u.attack_timer = 1.f/u.base->attack_speed;
						player->hp -= u.base->attack - player->base->defense;
						if(player->hp <= 0)
						{
							player->alive = false;
							u.gold += (player->gold + player->untaxed_gold);
							player->gold = 0;
							player->untaxed_gold = 0;
						}
					}
				}
				else
				{
					DIR dir = GetDir(u.pos, enemy_pt);
					if(!TryMove(u, dir, false))
					{
						struct SubDir
						{
							DIR a, b;
						};
						const SubDir sub_dir[8] = {
							DIR_SE, DIR_SW, //DIR_S,
							DIR_W, DIR_S, //DIR_SW,
							DIR_NW, DIR_SW, //DIR_W,
							DIR_N, DIR_W, //DIR_NW,
							DIR_NE, DIR_NW, //DIR_N,
							DIR_N, DIR_E, //DIR_NE,
							DIR_SE, DIR_NE, //DIR_E,
							DIR_S, DIR_E //DIR_SE,
						};
						if(rand()%2 == 0)
						{
							if(!TryMove(u, sub_dir[dir].a, false))
								TryMove(u, sub_dir[dir].b, false);
						}
						else
						{
							if(!TryMove(u, sub_dir[dir].b, false))
								TryMove(u, sub_dir[dir].a, false);
						}
					}
				}
			}
		}
	}

	// update hit animations
	for(vector<Hit>::iterator it = hits.begin(), end = hits.end(); it != end;)
	{
		Hit& hit = *it;
		hit.timer -= dt;
		if(hit.timer <= 0.f)
		{
			if(it+1 == end)
			{
				hits.pop_back();
				break;
			}
			else
			{
				std::iter_swap(it, end-1);
				hits.pop_back();
				end = hits.end();
			}
		}
		else
		{
			if(CheckRef(hit._ref))
				hit.pos = hit._ref->GetRef().GetPos();
			++it;
		}
	}

	// set camera
	if(player)
	{
		cam_pos = player->GetPos() - SCREEN_SIZE/2;
		if(cam_pos.x < 0)
			cam_pos.x = 0;
		if(cam_pos.y < 0)
			cam_pos.y = 0;
		if(cam_pos.x + SCREEN_SIZE.x > MAP_W*32)
			cam_pos.x = MAP_W*32-SCREEN_SIZE.x;
		if(cam_pos.y + SCREEN_SIZE.y > MAP_H*32)
			cam_pos.y = MAP_H*32-SCREEN_SIZE.y;
	}
}
Beispiel #22
0
void Player::Update(float elapsed)
{
    //Add friction into the acceleration.

    //If the player isn't accelerating, slow down his velocity completely.
    if (Acceleration.x == 0.0f && Acceleration.y == 0.0f)
    {
        if (Velocity.x != 0.0f || Velocity.y != 0.0f)
        {
            Acceleration = -Velocity * LevelConstants::Instance.PlayerFriction;
        }
    }
    else
    {
        //Split the acceleration and velocity into "forward" and "side" components.
        Vector2f forward = LookDir.XY().Normalized(),
                 side = Vector2f(forward.y, forward.x),
                 forwardA = forward * forward.Dot(Acceleration),
                 forwardV = forward * forward.Dot(Velocity),
                 sideA = side * side.Dot(Acceleration),
                 sideV = side * side.Dot(Velocity);

        //Add friction to any velocity components that go against the acceleration.
        if (forwardA.Dot(forwardV) < 0.0f && (abs(forwardV.x) > 0.00001f || abs(forwardV.y) > 0.00001f))
        {
            Acceleration -= forwardV.Normalized() * LevelConstants::Instance.PlayerFriction;
        }
        if (sideA.Dot(sideV) < 0.0f && (abs(sideV.x) > 0.00001f || abs(sideV.y) > 0.00001f))
        {
            Acceleration -= sideV.Normalized() * LevelConstants::Instance.PlayerFriction;
        }
    }


    //Update velocity and acceleration.
    Velocity += Acceleration * elapsed;
    Acceleration = Vector2f();

    //Constrain the velocity.
    float speedSqr = Velocity.LengthSquared();
    if (speedSqr > LevelConstants::Instance.PlayerMaxSpeed * LevelConstants::Instance.PlayerMaxSpeed)
    {
        Velocity = (Velocity / sqrtf(speedSqr)) * LevelConstants::Instance.PlayerMaxSpeed;
    }

    //Update position.
    TryMove(elapsed);


    //Handle weapons.
    if (Fire)
    {
        if (!firedLastFrame)
        {
            firedLastFrame = true;
            GetCurrentWeapon()->StartFire();
        }
        Fire = false;
    }
    else if (firedLastFrame)
    {
        GetCurrentWeapon()->StopFire();
        firedLastFrame = false;
    }
    GetCurrentWeapon()->Update(elapsed);
}
Beispiel #23
0
bool CLogicBoad::DoLogicBoardCmd( stBaseCmd* pcmd,int nLen )
{
    switch (pcmd->value)
    {
    case stTetrisRefresh::_value:
    {
        stTetrisRefresh* pDstCmd = (stTetrisRefresh*)pcmd;
        for (int i = 0; i < BoardWidth * BoardHeight; ++i) {
            board[i] = Tetrominoes(pDstCmd->board[i]);
        }
        curX = pDstCmd->nCurX;
        curY = pDstCmd->nCurY;
        memcpy(&curPiece,&pDstCmd->curPiece,sizeof(curPiece));
        Refresh();
    }
    break;
    case stTetrisDrawText::_value:
    {
        stTetrisDrawText* pDstCmd = (stTetrisDrawText*)pcmd;
        strcpy_s(szDrawText,sizeof(szDrawText),pDstCmd->szDrawText);
        Refresh();
    }
    break;
    case stTetrisOperator::_value:
    {
        stTetrisOperator* pDstcmd = (stTetrisOperator*)pcmd;
        switch (pDstcmd->btOperator)
        {
        case emTR_OPERATOR_START:
        {
            Start();
        }
        break;
        case emTR_OPERATOR_RIGHT:
        {
            TryMove(curPiece,curX+1,curY);
        }
        break;
        case emTR_OPERATOR_LEFT:
        {
            TryMove(curPiece,curX-1,curY);
        }
        break;
        case emTR_OPERATOR_DOWN:
        {
            TryMove(curPiece,curX,curY-1);
        }
        break;
        case emTR_OPERATOR_ROTATELEFT:
        {
            TryMove(curPiece.RotateLeft(),curX,curY);
        }
        break;
        case emTR_OPERATOR_PAUSE:
        {
            Pause();
        }
        }
    }
    break;
    }
    return true;
}
Beispiel #24
0
BOOL WINAPI CchessTryMove(PositionStruct *lppos, LPLONG lpStatus, LONG mv) {
  return TryMove(*lppos, *(int *) lpStatus, mv);
}
Beispiel #25
0
// ***********************************************************
// custom keyFunc with preset keys
void keyFunc(unsigned char ch, int x, int y) {
  bool bPostRedisplay = false;
  
	switch(ch) {
		case 'q':
    case 'Q':
      bPostRedisplay = false;
			exit(0);
			break;
      
    case '`':
      cindex = 0;
      
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 0.\n");
      else
        printf("Now controlling Primitive 0.\n");        
  
      break;
      
    case '1':
      cindex = 1;
        
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 1.\n");
      else
        printf("Now controlling Primitive 1.\n");  
          
      break;
      
    case '2':
      cindex = 2;
          
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 2.\n");
      else
        printf("Now controlling Primitive 2.\n");  
            
      break;
      
    case '3':
      cindex = 3;
        
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 3.\n");
      else
        printf("Now controlling Primitive 3.\n");  
          
      break;
      
    case '4':
      cindex = 4;
        
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 4.\n");
      else
        printf("Now controlling Primitive 4.\n");  
          
      break;
      
    case '5':
      cindex = 5;
        
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 5.\n");
      else
        printf("Now controlling Primitive 5.\n");  
          
      break;

    case '6':
      cindex = 6;
        
      if(cmode == ControlMode_Lights)
        printf("Now controlling Light 6.\n");
      else
        printf("Now controlling Primitive 6.\n");  
          
      break;
      
    case '7':
      LoadPresetScene1();
      break;

    case '8':
      LoadPresetScene2();
      break;

    case '9':
      LoadPresetScene3();
      break;
      
    case 'A':
    case 'a':
      ToggleAmbient();
      break;
      
    case 'S':
    case 's':
      ToggleSpecular();
      break;
      
    case 'D':
    case 'd':
      ToggleDiffuse();
      break;
            
    case 'R':
    case 'r':
      ToggleReflections();
      break;

    case 'T':
    case 't':
      ToggleTransparency();
      break;
         
    case 'E':
    case 'e':
      ToggleTexturing();
      break;
      
    case 'J':
    case 'j':
      ToggleAntiAliasing();
      break;
      
    case 'U':
    case 'u':
      ToggleAttenuation();
      break;
      
    case 'L':
    case 'l':
      cmode = ControlMode_Lights;
      printf("Control Mode: LIGHTS.\n");
      break;
            
    case 'P':
    case 'p':
      cmode = ControlMode_Prims;
      printf("Control Mode: PRIMITIVES.\n");
      break;
 
    case 'V':
    case 'v':
      TryToggleVisibility();
      
      bPostRedisplay = true;
      break;
      
    case 'M':
    case 'm':
      TryCycleMaterial();
      
      bPostRedisplay = true;
      break;
      
    case 'X':
    case 'x':
      TryCycleTexture();
      
      bPostRedisplay = true;
      break;
        
    // move controlled object left
    case '[':
      TryMove(-2.0f, 0.0f, 0.0f);
      
      bPostRedisplay = true;
      break;
      
    // move controlled object right
    case ']':
      TryMove(2.0f, 0.0f, 0.0f);
      
      bPostRedisplay = true;
      break;
      
    // move controlled object down
    case '-':
      TryMove(0.0f, -2.0f, 0.0f);
      
      bPostRedisplay = true;
      break;
 
    // move controlled object up
    case '=':
      TryMove(0.0f, 2.0f, 0.0f);
      
      bPostRedisplay = true;
      break;
        
    case ';':
      TryMove(0.0f, 0.0f, -2.0f);
      
      bPostRedisplay = true;
      break;
      
    case '\'':
      TryMove(0.0f, 0.0f, 2.0f);
      
      bPostRedisplay = true;
      break;
      
    case '.':
      if( scene->DecreaseRayDepth())
        printf("Ray depth decreased to %d.\n", scene->GetRayDepth());
      else
        printf("Ray depth already at 1.\n");
      
      bPostRedisplay = true;
      break;
      
    case ',':
      if( scene->IncreaseRayDepth())
        printf("Ray depth increased to %d.\n", scene->GetRayDepth());
      else
        printf("Ray depth already at max.\n");
      
      
      bPostRedisplay = true;
      break;
      
    case 'B':
    case 'b':
      ExportScene();
      break;
      
    case 'Z':
    case 'z':
      ResetScene();
      break;
      
    case 'O':
    case 'o':
      if(cmode == ControlMode_Lights) {
        AddRandomLight();

      } else {
        AddRandomPrimitive();
      }
      
      break;

		default:
			/* Unrecognized keypress */
      return;
	}
  
  if(bPostRedisplay)
    glutPostRedisplay();
    
}
//-----------------------------------------------------------------------------
// Purpose: Does the basic move attempting to climb up step heights.  It uses
//          the mv->m_vecAbsOrigin and mv->m_vecVelocity.  It returns a new
//          new mv->m_vecAbsOrigin, mv->m_vecVelocity, and mv->m_outStepHeight.
//-----------------------------------------------------------------------------
void CASW_Drone_Movement::StepMove( Vector &vecDestination, trace_t &trace )
{
//	CheckStuck();
	Vector vecEndPos;
	VectorCopy( vecDestination, vecEndPos );

	// Try sliding forward both on ground and up 16 pixels
	//  take the move that goes farthest
	Vector vecPos, vecVel;
	VectorCopy( mv->GetAbsOrigin(), vecPos );
	VectorCopy( mv->m_vecVelocity, vecVel );

	// Slide move down.
	Vector downWallNormal;
	TryMove( &vecEndPos, &trace );
	downWallNormal = m_LastHitWallNormal;
	
	// Down results.
	Vector vecDownPos, vecDownVel;
	VectorCopy( mv->GetAbsOrigin(), vecDownPos );
	VectorCopy( mv->m_vecVelocity, vecDownVel );
	
	// Reset original values.
	mv->SetAbsOrigin( vecPos );
	VectorCopy( vecVel, mv->m_vecVelocity );
	
	// Move up a stair height.
	VectorCopy( mv->GetAbsOrigin(), vecEndPos );
	vecEndPos.z += STEP_SIZE;	
	
	UTIL_TraceEntity( m_pNPC, mv->GetAbsOrigin(), vecEndPos, MASK_NPCSOLID, &trace );
	//TraceBBox( mv->GetAbsOrigin(), vecEndPos, MASK_NPCSOLID, m_pNPC->GetCollisionGroup(), trace );
	if ( !trace.startsolid && !trace.allsolid )
	{
		mv->SetAbsOrigin( trace.endpos );
	}
	
	// Slide move up.
	Vector upWallNormal;
	TryMove(NULL, NULL);
	upWallNormal = m_LastHitWallNormal;
	
	// Move down a stair (attempt to).
	VectorCopy( mv->GetAbsOrigin(), vecEndPos );
	vecEndPos.z -= STEP_SIZE;
		
	UTIL_TraceEntity( m_pNPC, mv->GetAbsOrigin(), vecEndPos, MASK_NPCSOLID, &trace );
	//TraceBBox( mv->GetAbsOrigin(), vecEndPos, MASK_NPCSOLID, m_pNPC->GetCollisionGroup(), trace );
	
	// If we are not on the ground any more then use the original movement attempt.
	if ( trace.plane.normal[2] < 0.7 )
	{
		mv->SetAbsOrigin( vecDownPos );
		VectorCopy( vecDownVel, mv->m_vecVelocity );
		VectorCopy( downWallNormal, m_LastHitWallNormal );
		float flStepDist = mv->GetAbsOrigin().z - vecPos.z;
		if ( flStepDist > 0.0f )
		{
			mv->m_outStepHeight += flStepDist;
		}

		return;
	}
	
	// If the trace ended up in empty space, copy the end over to the origin.
	if ( !trace.startsolid && !trace.allsolid )
	{
		mv->SetAbsOrigin( trace.endpos );
	}
	
	// Copy this origin to up.
	Vector vecUpPos;
	VectorCopy( mv->GetAbsOrigin(), vecUpPos );
	VectorCopy( upWallNormal, m_LastHitWallNormal);
	
	// decide which one went farther
	float flDownDist = ( vecDownPos.x - vecPos.x ) * ( vecDownPos.x - vecPos.x ) + ( vecDownPos.y - vecPos.y ) * ( vecDownPos.y - vecPos.y );
	float flUpDist = ( vecUpPos.x - vecPos.x ) * ( vecUpPos.x - vecPos.x ) + ( vecUpPos.y - vecPos.y ) * ( vecUpPos.y - vecPos.y );
	if ( flDownDist > flUpDist )
	{
		mv->SetAbsOrigin( vecDownPos );
		VectorCopy( vecDownVel, mv->m_vecVelocity );
		VectorCopy( downWallNormal, m_LastHitWallNormal);
	}
	else 
	{
		// copy z value from slide move
		mv->m_vecVelocity.z = vecDownVel.z;
	}
	
	float flStepDist = mv->GetAbsOrigin().z - vecPos.z;
	if ( flStepDist > 0 )
	{
		mv->m_outStepHeight += flStepDist;
	}
}
Beispiel #27
0
int main(void) {
    int i;
    bool bPonderTime;
    UcciCommStruct UcciComm;
    const char *szEngineName;
    PositionStruct posProbe;
#ifdef _WIN32
    HMODULE hModule;
#else
    void *hModule;
#endif

    int mv, stat;
    char fen[1024];

    /* disable stdio buffering */
    if (setvbuf(stdin, NULL, _IONBF, 0) != 0)
        perror("setvbuf");
    if (setvbuf(stdout, NULL, _IONBF, 0) != 0)
        perror("setvbuf");

    // myfp = fopen("test", "w+");
    // fputs("test\n", myfp);

    xb_mv_left = 40;
    xb_mv_ctrl = 40;
    xb_tm_left = 30000;
    xb_tm_ctrl = 30000;
    xb_tm_incr = 0;
    xb_post = 0;
    xb_ponder = 0;
    xb_depth = UCCI_MAX_DEPTH;
    xb_force = 0;
    Search.nHashSize = 4;
    Search.nRandom = 0;
    Search.nRandomSave = 2;

    /* if not working with autotools */
#ifndef PKGDATADIR
#define PKGDATADIR "."
#endif

    LocatePath(Search.szBookFile, PKGDATADIR "/book.dat");
    //LocatePath(Search.szBookFile, "book.dat");
    LocatePath(Search.szLibEvalFile, cszLibEvalFile);
    hModule = LoadEvalApi(Search.szLibEvalFile);

    bPonderTime = false;
    PreGenInit();
    NewHash(24); // 24=16MB, 25=32MB, 26=64MB, ...
    Search.pos.FromFen(cszStartFen);
    Search.pos.nDistance = 0;
    Search.PreEvaluate(&Search.pos, &PreEval);
    Search.nBanMoves = 0;
    Search.bQuit = Search.bBatch = Search.bDebug = Search.bAlwaysCheck = false;
    Search.bUseHash = Search.bUseBook = Search.bNullMove = Search.bKnowledge = true;
    Search.bIdle = false;
    Search.nCountMask = INTERRUPT_COUNT - 1;
    Search.nRandomMask = 0;
    Search.rc4Random.InitRand();

    szEngineName = Search.GetEngineName();
    if (szEngineName == NULL) {
        PrintLn("id name ElephantEye");
    } else {
        printf("id name %s / ElephantEye\n", szEngineName);
        fflush(stdout);
    }
    PrintLn("id version 3.15");
    PrintLn("id copyright 2004-2008 www.elephantbase.net");
    PrintLn("id author Morning Yellow");
    PrintLn("id user ElephantEye Test Team");

    while (BootLine() != UCCI_COMM_XBOARD);
    // PrintLn("option usemillisec type check default true");
    // PrintLn("option promotion type check default false");
    // PrintLn("option batch type check default false");
    // PrintLn("option debug type check default false");
    // PrintLn("option ponder type check default false");
    // PrintLn("option alwayscheck type check default false");
    // PrintLn("option usehash type check default true");
    // PrintLn("option usebook type check default true");
    // printf("option bookfiles type string default %s\n", Search.szBookFile);
    // fflush(stdout);
    // printf("option evalapi type string default %s\n", szLibEvalFile);
    // fflush(stdout);
    // PrintLn("option hashsize type spin min 16 max 1024 default 16");
    // PrintLn("option idle type combo var none var small var medium var large default none");
    // PrintLn("option pruning type combo var none var small var medium var large default large");
    // PrintLn("option knowledge type combo var none var small var medium var large default large");
    // PrintLn("option randomness type combo var none var small var medium var large default none");
    // PrintLn("option newgame type button");
    // PrintLn("ucciok");

    // 以下是接收指令和提供对策的循环体
    while (!Search.bQuit) {
        switch (IdleLine(UcciComm, Search.bDebug)) {
        case UCCI_COMM_STOP:
            PrintLn("nobestmove");
            break;
        case UCCI_COMM_POSITION:
            BuildPos(Search.pos, UcciComm);
            Search.pos.nDistance = 0;
            Search.PreEvaluate(&Search.pos, &PreEval);
            Search.nBanMoves = 0;
            hint_mv = 0;
            break;
        case UCCI_COMM_NEW:
            Search.pos.FromFen(cszStartFen);
            Search.pos.nDistance = 0;
            Search.PreEvaluate(&Search.pos, &PreEval);
            Search.nBanMoves = 0;
            xb_force = 0;
            xb_tm_left = xb_tm_ctrl;
            xb_mv_left = xb_mv_ctrl;
            xb_depth = UCCI_MAX_DEPTH;
            hint_mv = 0;
            break;
        case UCCI_COMM_BANMOVES:
            Search.nBanMoves = UcciComm.nBanMoveNum;
            for (i = 0; i < UcciComm.nBanMoveNum; i ++) {
                Search.wmvBanList[i] = COORD_MOVE(UcciComm.lpdwBanMovesCoord[i]);
            }
            break;
        case UCCI_COMM_SETOPTION:
            switch (UcciComm.Option) {
            case UCCI_OPTION_PROMOTION:
                PreEval.bPromotion = UcciComm.bCheck;
                break;
            case UCCI_OPTION_ALWAYSCHECK:
                Search.bAlwaysCheck = UcciComm.bCheck;
                break;
            case UCCI_OPTION_USEHASH:
                Search.bUseHash = UcciComm.bCheck;
                break;
            case UCCI_OPTION_USEBOOK:
                Search.bUseBook = UcciComm.bCheck;
                break;
            case UCCI_OPTION_BOOKFILES:
                if (AbsolutePath(UcciComm.szOption)) {
                    strcpy(Search.szBookFile, UcciComm.szOption);
                } else {
                    LocatePath(Search.szBookFile, UcciComm.szOption);
                }
                break;
            case UCCI_OPTION_EVALAPI:
                if (AbsolutePath(UcciComm.szOption)) {
                    strcpy(Search.szLibEvalFile, UcciComm.szOption);
                } else {
                    LocatePath(Search.szLibEvalFile, UcciComm.szOption);
                }
                FreeEvalApi(hModule);
                hModule = LoadEvalApi(Search.szLibEvalFile);
                break;
            case UCCI_OPTION_HASHSIZE:
                DelHash();
                Search.nHashSize = UcciComm.nSpin;
                NewHash(UcciComm.nSpin + 20);
                break;
            case UCCI_OPTION_PRUNING:
                Search.bNullMove = UcciComm.bCheck;
                break;
            case UCCI_OPTION_KNOWLEDGE:
                Search.bKnowledge = UcciComm.bCheck;
                break;
            case UCCI_OPTION_RANDOMNESS:
                Search.nRandom = UcciComm.nSpin;
                if (UcciComm.nSpin)
                    Search.nRandomSave = UcciComm.nSpin;
                Search.nRandomMask = (1 << Search.nRandom) - 1;
                break;
            default:
                break;
            }
            break;
        case UCCI_COMM_GO:
            // Search.bPonder = UcciComm.bPonder;
            // Search.bDraw = UcciComm.bDraw;
            // switch (UcciComm.Go) {
            // case UCCI_GO_DEPTH:
            //   Search.nGoMode = GO_MODE_INFINITY;
            //   Search.nNodes = 0;
            //   SearchMain(UcciComm.nDepth);
            //   break;
            // case UCCI_GO_NODES:
            //   Search.nGoMode = GO_MODE_NODES;
            //   Search.nNodes = UcciComm.nNodes;
            //   SearchMain(UCCI_MAX_DEPTH);
            //   break;
            // case UCCI_GO_TIME_MOVESTOGO:
            // case UCCI_GO_TIME_INCREMENT:
            //   Search.nGoMode = GO_MODE_TIMER;
            //   if (UcciComm.Go == UCCI_GO_TIME_MOVESTOGO) {
            //     // 对于时段制,把剩余时间平均分配到每一步,作为适当时限。
            //     // 剩余步数从1到5,最大时限依次是剩余时间的100%、90%、80%、70%和60%,5以上都是50%
            //     Search.nProperTimer = UcciComm.nTime / UcciComm.nMovesToGo;
            //     Search.nMaxTimer = UcciComm.nTime * MAX(5, 11 - UcciComm.nMovesToGo) / 10;
            //   } else {
            //     // 对于加时制,假设棋局会在20回合内结束,算出平均每一步的适当时限,最大时限是剩余时间的一半
            //     Search.nProperTimer = UcciComm.nTime / 20 + UcciComm.nIncrement;
            //     Search.nMaxTimer = UcciComm.nTime / 2;
            //   }
            //   // 如果是后台思考的时间分配策略,那么适当时限设为原来的1.25倍
            //   Search.nProperTimer += (bPonderTime ? Search.nProperTimer / 4 : 0);
            //   Search.nMaxTimer = MIN(Search.nMaxTimer, Search.nProperTimer * 10);
            //   SearchMain(UCCI_MAX_DEPTH);
            //   break;
            // default:
            //   break;
            // }
            xb_force = 0;
            Search.nGoMode = GO_MODE_TIMER;
            prepare_clock();
            SearchMain(xb_depth);
            update_clock();
            break;
        case UCCI_COMM_PROBE:
            BuildPos(posProbe, UcciComm);
            if (!PopHash(posProbe)) {
                PopLeaf(posProbe);
            }
            break;
        case UCCI_COMM_QUIT:
            Search.bQuit = true;
            break;
        case UCCI_COMM_UNDO:
            if (Search.pos.nDistance >= 1)
                Search.pos.UndoMakeMove();
            hint_mv = 0;
            break;
        case UCCI_COMM_REMOVE:
            if (Search.pos.nDistance >= 2) {
                Search.pos.UndoMakeMove();
                Search.pos.UndoMakeMove();
            }
            hint_mv = 0;
            break;
        case UCCI_COMM_USERMOVE:
            mv = COORD_MOVE(UcciComm.dwMoveCoord);
            TryMove(Search.pos, stat, mv);
            switch (stat) {
            case MOVE_ILLEGAL:
                printf("Illegal move: %.4s\n", (char *)&UcciComm.dwMoveCoord);
                break;
            case MOVE_INCHECK:
                printf("Illegal move (in check): %.4s\n", (char *)&UcciComm.dwMoveCoord);
                break;
            case MOVE_DRAW:
                puts("1/2-1/2 {Draw by rule}\n");
                break;
            case MOVE_PERPETUAL_LOSS:
                printf("Illegal move (perpetual attack): %.4s\n", (char *)&UcciComm.dwMoveCoord);
                break;
            case MOVE_PERPETUAL:
                puts("1/2-1/2 {Draw by repetition}\n");
                break;
            case MOVE_MATE:
                if (Search.pos.sdPlayer == 0)
                    puts("1-0 {checkmate or stalemate}\n");
                else
                    puts("0-1 {checkmate or stalemate}\n");
                break;
            default:
                Search.pos.MakeMove(mv);
                if (!xb_force) {
                    prepare_clock();
                    SearchMain(xb_depth);
                    update_clock();
                }
                break;
            }
            break;
        default:
            break;
        }
    }
    DelHash();
    FreeEvalApi(hModule);
    return 0;
}