Exemple #1
0
void PickingWindow::DoPick(int x, int y)
{
    int viewX, viewY, viewW, viewH;
    mEngine->GetViewport(viewX, viewY, viewW, viewH);
    Vector4<float> origin, direction;
    if (mCamera->GetPickLine(viewX, viewY, viewW, viewH, x, y, origin, direction))
    {
        // Use a ray for picking.
        float tmin = 0.0f, tmax = std::numeric_limits<float>::max();

        // Set the distance tolerance for point and segment primitives.
        mPicker.SetMaxDistance(0.0625f);

        // Request the results in model-space coordinates.  All the objects
        // in the scene have the same model space, so we can set the sphere
        // centers in model-space coordinates.
        mPicker(mScene, origin, direction, tmin, tmax);
        mNumActiveSpheres = std::min((int)mPicker.records.size(), (int)SPHERE_BUDGET);
        if (mNumActiveSpheres > 0)
        {
            // Place spheres at the picked locations.
            Matrix4x4<float> const& invWMatrix = mScene->worldTransform.GetHInverse();
            for (int i = 0; i < mNumActiveSpheres; ++i)
            {
#if defined(GTE_USE_MAT_VEC)
                Vector4<float> modelPosition = invWMatrix * mPicker.records[i].primitivePoint;
#else
                Vector4<float> modelPosition = mPicker.records[i].primitivePoint * invWMatrix;
#endif
                mSphere[i]->localTransform.SetTranslation(modelPosition);
            }

            mTrackball.Update();
            mCameraRig.UpdatePVWMatrices();
        }
    }
}
Exemple #2
0
int Solve (int nodeType, Position& board, int ply, int alpha, int beta, int depth) {

	// return score for terminal state
	if (board.HasWon(board.get_arrayOfBitboard((board.get_nPlies() - 1) & 1))) {
		return -WIN + ply;
	} else if (board.get_nPlies() == 42) {
		return DRAW;
	}

	// Mate distance pruning
	alpha = std::max (ply - WIN, alpha);
	beta = std::min (WIN - (ply + 1), beta);
	if (alpha >= beta) {
		return alpha;
	}

	TTEntry entry = TranspositionTable.probeTTable(board.get_key());
		
	if (entry.flag == EXACT
		|| entry.flag == L_BOUND && entry.evaluationScore >= beta
		|| entry.flag == U_BOUND && entry.evaluationScore <= alpha) {

		if (entry.evaluationScore >= beta) {
			updateKillers(entry.move, ply);
		}
		return entry.evaluationScore;
	}

	int hashMove = (entry.flag == L_BOUND && entry.evaluationScore < beta) ? entry.move : NO_MOVE;
	int bestScore = -INF;
	int movesMade = 0;
	bool raisedAlpha = false;
	MovePicker mPicker(board, ply, hashMove);
	int bestMove = NO_MOVE;
	
	for (int i=0; i < 7; i++) {
			
		int move = mPicker.getNextMove();
		
		if (move == NO_MOVE) {
			break;
		}

		board.MakeMove(move);
		int score = -Solve(NON_ROOT, board, ply + 1, -beta, -alpha, depth - 1);
		board.UnmakeMove();
		nodesVisited++;
		movesMade++;

		if (score >= beta) {
			TTEntry newEntry = {board.get_key(), L_BOUND, depth, score, move};
			TranspositionTable.storeTTable(board.get_key(), newEntry);
			updateKillers(move, ply);
			updateHistory(depth, ply, move);

			if (movesMade == 1) {
				fh1++;
			} else {
				fh++;
			}
			return score;
		} else if (score > bestScore) {
			bestScore = score;
			bestMove = move;
			if (score > alpha) {
				alpha = score;
				raisedAlpha = true;
			}
		} 
	}

	if (raisedAlpha) {
		TTEntry newEntry = {board.get_key(), EXACT, depth, alpha, bestMove};
		TranspositionTable.storeTTable(board.get_key(), newEntry);
	} else {
		TTEntry newEntry = {board.get_key(), U_BOUND, depth, bestScore, NO_MOVE};
		TranspositionTable.storeTTable(board.get_key(), newEntry);
	}
	
	return bestScore; 
}