void buildTestScene1()
{
    float w,h,f;
    w = 9.0f;
    h = 6.0f;
    f = 6.0f;

    cam = PinholeCamera(Vec3(0.0f,0.0f,0.0f), Vec3(0.0f,0.0f,-5.0f), Vec3(0.0f,1.0f,0.0f),f,w,h);
    buffer = RayBuffer();
    PointLight *l;
    l = new PointLight(Vec3(1.0f,0.0f,1.0f),Col(1.0f,1.0f,1.0f), 15, 1, 1, 1);
    lights.addLight(*l);
    l = new PointLight(Vec3(-3.0f,3.0f,-1.0f),Col(1.0f,1.0f,1.0f), 10, 1, 1, 1);
    lights.addLight(*l);
    l = new PointLight(Vec3(2.0f,0.0f,0.0f),Col(0.30f,0.30f,0.30f), 4, 1, 1, 1);
    lights.addLight(*l);



    std::vector<Collidable *> *vec = new std::vector<Collidable *>();

    Collidable *c;

    c = new Sphere(Vec3(0.0f, .5f, -4.20f), 1.0f, Material(1));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Sphere(Vec3(-0.0f, -1.0f, -3.0f), 0.5f, Material(2));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Sphere(Vec3(-0.0f, 0.00f, -0.50f), 0.1f, Material(3));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Sphere(Vec3(0.7f, 0.30f, -2.5f), 0.5f, Material(4));
    c->precomputeBounds();
    //vec->push_back(c);
    c = new Sphere(Vec3(02.0f, 0.00f, -5.0f), 0.70f, Material(4));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Sphere(Vec3(0.9f, 0.00f, -02.50f), 0.50f, Material(7));
    c->precomputeBounds();
    vec->push_back(c);


    sceneTree.buildTreeStart(*vec);


    sceneTree.isLeaf = true;
    sceneTree.items = vec;
    sceneTree.xMin = -100;
    sceneTree.xMax = 100;
    sceneTree.yMin = -100;
    sceneTree.yMax = 100;
    sceneTree.zMin = -100;
    sceneTree.zMax = 100;

    sceneTree.axis = -1;
    sceneTree.depth = 0;
    sceneTree.id = 55;

}
Esempio n. 2
0
inline int Dist(FLD f1, FLD f2)
{
	int drow = Row(f1) - Row(f2);
	if (drow < 0)
		drow = -drow;

	int dcol = Col(f1) - Col(f2);
	if (dcol < 0)
		dcol = -dcol;

	return (drow > dcol)? drow : dcol;
}
Esempio n. 3
0
Col Cols::add(const CoinPackedVector & vector)
{
    _problem->addCol(vector);
    if (_cols.size() > 0)
    {
        _cols.push_back( Col(_problem, (_cols.back()).getindex() + 1) );
    }
    else
    {
        _cols.push_back( Col(_problem, 0) );
    }
    return _cols.back();
}
Esempio n. 4
0
void float3x3::Orthonormalize(int c0, int c1, int c2)
{
    assume(c0 != c1 && c0 != c2 && c1 != c2);
    if (c0 == c1 || c0 == c2 || c1 == c2)
        return;

    ///\todo Optimize away copies.
    float3 v0 = Col(c0);
    float3 v1 = Col(c1);
    float3 v2 = Col(c2);
    float3::Orthonormalize(v0, v1, v2);
    SetCol(c0, v0);
    SetCol(c1, v1);
    SetCol(c2, v2);
}
void MapParser::Stretch3 (int tx, int ty, int x, int y, int w, int h)
{
    //printf("\'St\' function called with arguments %d, %d, %d, %d, %d and %d.\n", tx, ty, x, y, w, h);

    keep_last_added_tile = false;

    Tile (tx, ty, x, y);
    Row (tx + 1, ty, x + TILE_SIZE, y, w - 2);
    Tile (tx + 2, ty, x + (w - 2)*TILE_SIZE, y);
    Col (tx, ty + 1, x, y + TILE_SIZE, h - 2);
    Tile (tx, ty + 2, x, y + (h - 2)*TILE_SIZE);
    Row (tx + 1, ty + 2, x + TILE_SIZE, y + (h - 2)*TILE_SIZE, w - 3);
    Col (tx + 2, ty + 1, x + (w - 2)*TILE_SIZE, y + TILE_SIZE, h - 3);
    Tile (tx + 2, ty + 2, x + (w - 2)*TILE_SIZE, y + (h - 2)*TILE_SIZE);
    Rect (tx + 1, ty + 1, x + TILE_SIZE, y + TILE_SIZE, w - 3, h - 3);
};
Esempio n. 6
0
void CTabFmt::RowS(const char *szDat[], int nDat)
{
	if (nDat > m_nCols) 
		nDat = m_nCols;
	if (nDat > 0) {
		char *r, *b;
		ColFmt cf;
		int i;

		m_nBuf = 0;

		RowB(&(r = b = (m_buf + m_nBuf)));
		m_nBuf += (r - b);
		
		for (i = 0; i < nDat; ++i) {
			cf = m_cFmt[i];
			cf.sum = 0;
			Col(cf, szDat[i]);
		}

		RowE(&(r = b = (m_buf + m_nBuf)));
		m_nBuf += (r - b);
		assert((r-m_buf) == m_nBuf);
		Out(m_buf, m_nBuf);
	}
}
Esempio n. 7
0
void CTabFmt::Row(const char *szDat[], int nDat)
{
	if (nDat > m_nCols) 
		nDat = m_nCols;
	if (nDat > 0) {
		int i;
		double val;

		m_nBuf = 0;
		m_nRows += 1;

		char *b, *r;

		RowB(&(r = b = (m_buf + m_nBuf)));
		m_nBuf += (r - b);

		for (i = 0; i < nDat; ++i) {
			val = Col(m_cFmt[i], szDat[i]);
			if (m_cFmt[i].sum) {
				m_cTot[i].tot += val;
				m_cTot[i].ssq += val * val;
			}
		}

		RowE(&(r = b = (m_buf + m_nBuf)));
		m_nBuf += (r - b);
		assert((r-m_buf) == m_nBuf);
		Out(m_buf, m_nBuf);
	}
}
Esempio n. 8
0
//----------------------------------------------------------------------
void GeneralMatrix::initialize(GeneralMatrix &source)
{
  isSparse = source.isSparse;
  nBlock = source.nBlock;
  if (blockStruct) delete[] blockStruct;
  blockStruct = new int[nBlock];
  CheckMemory(blockStruct);
  if (isSparse)
  {
    if (!mat.empty()) mat.clear();
    smat.resize(nBlock);
  }
  else
  {
    if (!smat.empty()) smat.clear();
    mat.resize(nBlock);
  }
  for(int j=0; j<nBlock; j++)
  {
    blockStruct[j] = source.blockStruct[j];
    if (isSparse)
    {
      Resize(smat[j],RowDimension(source.smat[j]),ColDimension(source.smat[j]),Allocated(source.smat[j]));
      for (int i=1; i<=ColDimension(smat[j]); i++) SetCol(smat[j], i, Col(source.smat[j], i));
    }
    else
    {
      mat[j] = source.mat[j];
    }
  }
}
Esempio n. 9
0
void Cols::update()
{
    _cols.clear();
    for (int i = 0; i < _problem->getNumCols(); ++i)
    {
        _cols.push_back( Col(_problem, i) );
    }
}
Esempio n. 10
0
cxStr *cxCSV::At(cxInt row,cxInt col)
{
    if(row >= Row() || col >= Col(row)){
        return nullptr;
    }
    cxArray *rs = rows->At(row)->To<cxArray>();
    return rs->At(col)->To<cxStr>();
}
Esempio n. 11
0
string FldToStr(FLD f)
{
  char buf[3];

  buf[0] = 'a' + Col(f);
  buf[1] = '8' - Row(f);
  buf[2] = 0;

  return buf;
}
Esempio n. 12
0
void float3x4::Orthonormalize(int c0, int c1, int c2)
{
	///\todo SSE.
	assume(c0 != c1 && c0 != c2 && c1 != c2);
	assume(c0 >= 0 && c1 >= 0 && c2 >= 0 && c0 < Cols && c1 < Cols && c2 < Cols);
#ifndef MATH_ENABLE_INSECURE_OPTIMIZATIONS
	if (c0 == c1 || c0 == c2 || c1 == c2)
		return;
#endif

	///@todo Optimize away copies.
	float3 v0 = Col(c0);
	float3 v1 = Col(c1);
	float3 v2 = Col(c2);
	float3::Orthonormalize(v0, v1, v2);
	SetCol(c0, v0);
	SetCol(c1, v1);
	SetCol(c2, v2);
}
Esempio n. 13
0
	void accumulate(const M &op1, const M &op2)
	{
		// Multiply matrices
		for(int i = Lb(op1,1); i<=Ub(op1,1); ++i)
		{
			for(int j = Lb(op2,1); j<=Ub(op2,1); ++j)
			{
				P& dotaccu = m_accu[i-m_lb1][j-m_lb2];
				cxsc::accumulate(dotaccu, op1[i], op2[Col(j)]);
			}
		}
	}
Esempio n. 14
0
std::string FldToStr(FLD f)
{
	if (f == NF)
		return "-";

	char buf[3];
	buf[0] = static_cast<char>('a' + Col(f));
	buf[1] = static_cast<char>('8' - Row(f));
	buf[2] = 0;

	return std::string(buf);
}
Esempio n. 15
0
void Bitboard::Print(U64 b)
{
	out("\n");
	for (int f = 0; f < 64; f++)
	{
		if (b & Single(f))
			out(" 1");
		else
			out(" -");
		if (Col(f) == 7) out("\n");
	}
	out("\n");
}
Esempio n. 16
0
BLOCO_API HumanView::Console::Console()
	: CILKeyboardState("console keyboard handler"), m_bActive( false ), m_bExecuteStringOnUpdate( false )
{
	m_CurrentInputString = std::string("");

	SetFontColor(Col( 1.0f, 1.0f, 1.0f, 1.0f ));
	SetFontSize(20.0f);

	m_CursorBlinkTimer = kCursorBlinkTimeMS;
	m_bCursorOn = true;
	
	m_helperPos = 0;

	g_pInput->AddListener((ICILKeyboardHandler*)this);
}
Esempio n. 17
0
 int copyToCrsMatrixView() {
   int r_val = 0;
   if (hasDenseFlatBase() && isDenseFlatBaseValid())  {
     const ordinal_type nrows = this->NumRows();
     for (ordinal_type i=0;i<nrows;++i) {
       auto row = this->RowView(i);
       const ordinal_type nnz = row.NumNonZeros();
       for (ordinal_type j=0;j<nnz;++j)
         row.Value(j) = _A.Value(i, row.Col(j));
     }
   } else {
     r_val = -1;
   }
   return r_val;
 }
Esempio n. 18
0
void Print(U64 b)
{
  out("\n");
  for (int f = 0; f < 64; ++f)
  {
    if (b & BB_SINGLE[f])
      out(" 1");
    else
      out(" -");

    if (Col(f) == 7)
      out("\n");
  }
  out("\n");
}
Esempio n. 19
0
 BLOCO_API ActorParams::ActorParams() 
{
	m_Mat = MatIdentity();
	m_Pos=Vec(0,0,0); 
	m_Type=AT_Unknown; 
	m_Col = Col(1.0f,1.0f,1.0f,1.0f);
	strcpy( m_OnCreateLuaFunctionName, "" );
	strcpy( m_sScriptFilename, "" );
	strcpy( m_sName, "" );
	strcpy( m_OnDestroyLuaFunctionName, "" );
	m_Size=sizeof(ActorParams); 
	m_IsModified= false;
	m_bPhysicActor = true;
	m_bHasScript = false;
}
Esempio n. 20
0
int PawnShieldWhite(const PawnEntry& pentry, FLD K)
{
	int r = 0;
	int file = Col(K) + 1;
	for (int i = file - 1; i <= file + 1; ++i)
	{
		int rank = pentry.m_ranks[i][WHITE];
		if (rank == 6)
			;
		else if (rank == 5)
			r += 1;
		else if (rank == 4)
			r += 2;
		else
			r += 3;
	}
	return r;
}
Esempio n. 21
0
int PawnShieldBlack(const PawnEntry& pentry, FLD K)
{
	int r = 0;
	int file = Col(K) + 1;
	for (int i = file - 1; i <= file + 1; ++i)
	{
		int rank = pentry.m_ranks[i][BLACK];
		if (rank == 1)
			;
		else if (rank == 2)
			r += 1;
		else if (rank == 3)
			r += 2;
		else
			r += 3;
	}
	return r;
}
Esempio n. 22
0
void float3x4::Decompose(float3 &translate, float3x3 &rotate, float3 &scale) const
{
	assume(this->IsColOrthogonal());

	translate = Col(3);
	rotate = RotatePart();
	scale.x = rotate.Col(0).Length();
	scale.y = rotate.Col(1).Length();
	scale.z = rotate.Col(2).Length();
	assume(!EqualAbs(scale.x, 0));
	assume(!EqualAbs(scale.y, 0));
	assume(!EqualAbs(scale.z, 0));
	rotate.ScaleCol(0, 1.f / scale.x);
	rotate.ScaleCol(1, 1.f / scale.y);
	rotate.ScaleCol(2, 1.f / scale.z);

	// Test that composing back yields the original float3x4.
	assume(float3x4::FromTRS(translate, rotate, scale).Equals(*this, 0.1f));
}
Esempio n. 23
0
void ASlider::OnPaint(wxPaintEvent & WXUNUSED(event))
{
   wxPaintDC dc(this);

#ifdef EXPERIMENTAL_THEMING
   wxColour Col(GetParent()->GetBackgroundColour());
   this->SetBackgroundColour( Col );
#endif

   mLWSlider->OnPaint(dc, false);

   if ( mSliderIsFocused )
   {
      wxRect r( 0, 0, mLWSlider->mWidth, mLWSlider->mHeight );

      r.Deflate( 1, 1 );

      AColor::DrawFocus( dc, r );
   }
}
Esempio n. 24
0
void Position::Print() const
{
	const char names[] = "-?PpNnBbRrQqKk";
	out("\n");
	for (int f = 0; f < 64; f++)
	{
		PIECE p = m_board[f];
		Highlight (p && GetColor(p) == WHITE);
		out(" %c", names[p]);
		Highlight(false);
		if (Col(f) == 7) out("\n");
	}
	if (m_undoSize)
	{
		out("\n ");
		for (int m = 0; m < m_undoSize; ++m)
			out("%s ", MoveToStrLong(m_undos[m].m_mv));
		out("\n ");
	}
	out("\n");
}
Esempio n. 25
0
void CTabFmt::RowH(const char *szDat[], int nDat)
{
	--nDat;
	if (nDat > m_nCols) 
		nDat = m_nCols;
	if (nDat > 0) {
		char *r, *b;
		int i;
		ColFmt cf, hf;

		memset(&hf, 0, sizeof(hf));
		hf.pad = 'c';
		hf.rgb = -1;
		hf.tho = ',';
		ColDef(hf, szDat[0]);

		m_nBuf = 0;
		
		RowB(&(r = b = (m_buf + m_nBuf)));
		m_nBuf += (r - b);

		for (i = 0; i < nDat; ++i) {
			cf = m_cFmt[i];

			if (hf.pad) cf.pad = hf.pad;
			if (hf.rgb!=-1) cf.rgb = hf.rgb;

			cf.wid += cf.spc; cf.spc = 0; cf.sum = 0; cf.dec = -1;
			cf.hdr = 'h';

			Col(cf, szDat[i+1]);
		}

		RowE(&(r = b = (m_buf + m_nBuf)));
		m_nBuf += (r - b);
		assert((r-m_buf) == m_nBuf);
		Out(m_buf, m_nBuf);
	}
}
Esempio n. 26
0
EVAL_ESTIMATION EstimateDraw(const Position& pos)
{
	static const int FIELD_COLOR[64] =
	{
		0, 1, 0, 1, 0, 1, 0, 1,
		1, 0, 1, 0, 1, 0, 1, 0,
		0, 1, 0, 1, 0, 1, 0, 1,
		1, 0, 1, 0, 1, 0, 1, 0,
		0, 1, 0, 1, 0, 1, 0, 1,
		1, 0, 1, 0, 1, 0, 1, 0,
		0, 1, 0, 1, 0, 1, 0, 1,
		1, 0, 1, 0, 1, 0, 1, 0
	};

	// KBP-K

	if (pos.MatIndex(WHITE) == 3 && pos.Count(PW) == 1)
	{
		if (pos.MatIndex(BLACK) == 0 && pos.Count(PB) == 0)
		{
			FLD pawn = Bitboard::LSB(pos.Bits(PW));
			FLD bishop = Bitboard::LSB(pos.Bits(BW));
			FLD king = pos.King(BLACK);
			if (Col(pawn) == 0)
			{
				if (FIELD_COLOR[A8] != FIELD_COLOR[bishop])
				{
					if (king == A8 || king == A7 || king == B8 || king == B7)
						return EVAL_PRACTICAL_DRAW;
				}
			}
			if (Col(pawn) == 7)
			{
				if (FIELD_COLOR[H8] != FIELD_COLOR[bishop])
				{
					if (king == H8 || king == H7 || king == G8 || king == G7)
						return EVAL_PRACTICAL_DRAW;
				}
			}
		}
	}

	if (pos.MatIndex(BLACK) == 3 && pos.Count(PB) == 1)
	{
		if (pos.MatIndex(WHITE) == 0 && pos.Count(PW) == 0)
		{
			FLD pawn = Bitboard::LSB(pos.Bits(PB));
			FLD bishop = Bitboard::LSB(pos.Bits(BB));
			FLD king = pos.King(WHITE);
			if (Col(pawn) == 0)
			{
				if (FIELD_COLOR[A1] != FIELD_COLOR[bishop])
				{
					if (king == A1 || king == A2 || king == B1 || king == B2)
						return EVAL_PRACTICAL_DRAW;
				}
			}
			if (Col(pawn) == 7)
			{
				if (FIELD_COLOR[H1] != FIELD_COLOR[bishop])
				{
					if (king == H1 || king == H2 || king == G1 || king == G2)
						return EVAL_PRACTICAL_DRAW;
				}
			}
		}
	}

	// KB-KB

	if (pos.MatIndex(WHITE) == 3 && pos.MatIndex(BLACK) == 3)
	{
		if (pos.Count(BW) == 1 && pos.Count(BB) == 1)
		{
			FLD bw = Bitboard::LSB(pos.Bits(BW));
			FLD bb = Bitboard::LSB(pos.Bits(BB));
			if (FIELD_COLOR[bw] != FIELD_COLOR[bb])
				return EVAL_PROBABLE_DRAW;
		}
	}

	// LOW MATERIAL

	// We can claim draw only in case of "King + minor vs. King".
	if (pos.Count(PW) == 0 && pos.Count(PB) == 0)
	{
		if (pos.MatIndex(WHITE) + pos.MatIndex(BLACK) <= 3)
			return EVAL_THEORETICAL_DRAW;
	}

	// Engames like "King + minor vs. King + minor" - just practical draw,
	// but no draw claim, because checkmate positions do exist.
	if (pos.Count(PW) == 0 && pos.MatIndex(WHITE) < 5)
	{
		if (pos.Count(PB) == 0 && pos.MatIndex(BLACK) < 5)
			return EVAL_PRACTICAL_DRAW;
		else
			return EVAL_WHITE_CANNOT_WIN;
	}

	if (pos.Count(PB) == 0 && pos.MatIndex(BLACK) < 5)
	{
		if (pos.Count(PW) == 0 && pos.MatIndex(WHITE) < 5)
			return EVAL_PRACTICAL_DRAW;
		else
			return EVAL_BLACK_CANNOT_WIN;
	}

	return EVAL_UNKNOWN;
}
Esempio n. 27
0
void PawnEntry::Read(const Position& pos)
{
	U64 x;
	FLD f;
	int file, rank;

	m_pawnHash = pos.PawnHash();
	m_score = 0;
	m_passed[WHITE] = m_passed[BLACK] = 0;

	for (file = 0; file < 10; ++file)
	{
		m_ranks[file][WHITE] = 0;
		m_ranks[file][BLACK] = 7;
	}

	x = pos.Bits(PW);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		file = Col(f) + 1;
		rank = Row(f);
		if (rank > m_ranks[file][WHITE])
			m_ranks[file][WHITE] = rank;
	}

	x = pos.Bits(PB);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		file = Col(f) + 1;
		rank = Row(f);
		if (rank < m_ranks[file][BLACK])
			m_ranks[file][BLACK] = rank;
	}

	x = pos.Bits(PW);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		file = Col(f) + 1;
		rank = Row(f);

		m_score += PSQ_P[f];
		if (m_ranks[file][BLACK] == 7)
		{
			if (m_ranks[file - 1][BLACK] >= rank && m_ranks[file + 1][BLACK] >= rank)
				m_passed[WHITE] |= Bitboard::Single(f);
		}

		if (rank != m_ranks[file][WHITE])
			m_score += PawnDoubled;

		if (m_ranks[file - 1][WHITE] == 0 && m_ranks[file + 1][WHITE] == 0)
			m_score += PawnIsolated;
		else if (m_ranks[file - 1][WHITE] < rank && m_ranks[file + 1][WHITE] < rank)
			m_score += PawnBackwards;
	}

	x = pos.Bits(PB);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		file = Col(f) + 1;
		rank = Row(f);

		m_score -= PSQ_P[FLIP[f]];
		if (m_ranks[file][WHITE] == 0)
		{
			if (m_ranks[file - 1][WHITE] <= rank && m_ranks[file + 1][WHITE] <= rank)
				m_passed[BLACK] |= Bitboard::Single(f);
		}

		if (rank != m_ranks[file][BLACK])
			m_score -= PawnDoubled;

		if (m_ranks[file - 1][BLACK] == 7 && m_ranks[file + 1][BLACK] == 7)
			m_score -= PawnIsolated;
		else if (m_ranks[file - 1][BLACK] > rank && m_ranks[file + 1][BLACK] > rank)
			m_score -= PawnBackwards;
	}
}
Esempio n. 28
0
EVAL Evaluate(const Position& pos, EVAL alpha, EVAL beta)
{
	EVAL_ESTIMATION ee = EstimateDraw(pos);
	if (ee == EVAL_THEORETICAL_DRAW || ee == EVAL_PRACTICAL_DRAW)
		return DRAW_SCORE;

	EVAL matScore = pos.Material(WHITE) - pos.Material(BLACK);
	if (pos.Count(BW) == 2)
		matScore += BishopPair;
	if (pos.Count(BB) == 2)
		matScore -= BishopPair;
	matScore = matScore * g_evalParams.Material / 50;

	EVAL lazy = (pos.Side() == WHITE)? matScore : -matScore;
	if (lazy <= alpha - g_evalParams.LazyEvalMargin)
		return alpha;
	if (lazy >= beta + g_evalParams.LazyEvalMargin)
		return beta;

	EVAL posScore = 0;
	EVAL boardScore = 0;
	EVAL mobScore = 0;
	EVAL pawnStructScore = 0;
	EVAL pawnPassedScore = 0;
	EVAL kingSafetyScore = 0;
	U64 x, y, occ = pos.BitsAll();
	FLD f;

	//
	//   PAWNS
	//

	int index = pos.PawnHash() % g_pawnHashSize;

	PawnEntry& pentry = g_pawnHash[index];
	if (pentry.m_pawnHash != pos.PawnHash())
		pentry.Read(pos);

	pawnStructScore += pentry.m_score;

	x = pentry.m_passed[WHITE];
	while (x)
	{
		f = Bitboard::PopLSB(x);

		if (pos[f - 8] == NOPIECE)
			pawnPassedScore += PAWN_PASSED_FREE[7 - Row(f)];
		else
			pawnPassedScore += PAWN_PASSED_BLOCKED[7 - Row(f)];

		if (pos.MatIndex(BLACK) == 0)
		{
			FLD f1 = f;
			if (pos.Side() == BLACK)
				f1 += 8;
			if ((Bitboard::PawnSquare(f1, WHITE) & pos.Bits(KB)) == 0)
				pawnPassedScore += PawnPassedSquare * (7 - Row(f1)) / 6;
		}
		else if (pos.MatIndex(BLACK) < 10)
			pawnPassedScore += PassedKingDist * Dist(f - 8, pos.King(BLACK));
	}

	x = pentry.m_passed[BLACK];
	while (x)
	{
		f = Bitboard::PopLSB(x);

		if (pos[f + 8] == NOPIECE)
			pawnPassedScore -= PAWN_PASSED_FREE[Row(f)];
		else
			pawnPassedScore -= PAWN_PASSED_BLOCKED[Row(f)];

		if (pos.MatIndex(WHITE) == 0)
		{
			FLD f1 = f;
			if (pos.Side() == WHITE)
				f1 -= 8;
			if ((Bitboard::PawnSquare(f1, BLACK) & pos.Bits(KW)) == 0)
				pawnPassedScore -= PawnPassedSquare * Row(f1) / 6;
		}
		else if (pos.MatIndex(WHITE) < 10)
			pawnPassedScore -= PassedKingDist * Dist(f + 8, pos.King(WHITE));
	}

	//
	//   KNIGHTS
	//

	static const int outpost[64] =
	{
		0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 1, 1, 0, 0, 0,
		0, 0, 1, 1, 1, 1, 0, 0,
		0, 1, 1, 1, 1, 1, 1, 0,
		0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0
	};

	static const int knight_mob[64] =
	{
		2, 3, 4, 4, 4, 4, 3, 2,
		3, 4, 6, 6, 6, 6, 4, 2,
		4, 6, 8, 8, 8, 8, 6, 4,
		4, 6, 8, 8, 8, 8, 6, 4,
		4, 6, 8, 8, 8, 8, 6, 4,
		4, 6, 8, 8, 8, 8, 6, 4,
		3, 4, 6, 6, 6, 6, 4, 2,
		2, 3, 4, 4, 4, 4, 3, 2
	};

	x = pos.Bits(NW);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		boardScore += PSQ_N[f];
		int mob = knight_mob[f];
		mobScore += KNIGHT_MOBILITY[mob];
		if (outpost[f])
		{
			if (Bitboard::PawnAttacks(f, BLACK) & pos.Bits(PW))
				boardScore += KnightOutpost;
		}
	}

	x = pos.Bits(NB);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		boardScore -= PSQ_N[FLIP[f]];
		int mob = knight_mob[f];
		mobScore -= KNIGHT_MOBILITY[mob];
		if (outpost[FLIP[f]])
		{
			if (Bitboard::PawnAttacks(f, WHITE) & pos.Bits(PB))
				boardScore -= KnightOutpost;
		}
	}

	//
	//   BISHOPS
	//

	x = pos.Bits(BW);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		boardScore += PSQ_B[f];
		y = Bitboard::BishopAttacks(f, occ);
		mobScore += BISHOP_MOBILITY[Bitboard::CountBits(y)];
	}

	x = pos.Bits(BB);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		boardScore -= PSQ_B[FLIP[f]];
		y = Bitboard::BishopAttacks(f, occ);
		mobScore -= BISHOP_MOBILITY[Bitboard::CountBits(y)];
	}

	//
	//   ROOKS
	//

	x = pos.Bits(RW);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		y = Bitboard::RookAttacks(f, occ ^ pos.Bits(RW));
		mobScore += ROOK_MOBILITY[Bitboard::CountBits(y)];

		if (Row(f) == 1)
			boardScore += Rook7th;

		int file = Col(f) + 1;
		if (pentry.m_ranks[file][WHITE] == 0)
			boardScore += RookOpen;
	}

	x = pos.Bits(RB);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		y = Bitboard::RookAttacks(f, occ ^ pos.Bits(RB));
		mobScore -= ROOK_MOBILITY[Bitboard::CountBits(y)];

		if (Row(f) == 6)
			boardScore -= Rook7th;

		int file = Col(f) + 1;
		if (pentry.m_ranks[file][BLACK] == 7)
			boardScore -= RookOpen;
	}

	//
	//   QUEENS
	//

	x = pos.Bits(QW);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		kingSafetyScore += QUEEN_KING_TROPISM[Dist(f, pos.King(BLACK))];
	}

	x = pos.Bits(QB);
	while (x)
	{
		f = Bitboard::PopLSB(x);
		kingSafetyScore -= QUEEN_KING_TROPISM[Dist(f, pos.King(WHITE))];
	}

	//
	//   KINGS
	//

	{
		f = pos.King(WHITE);
		kingSafetyScore += PSQ_K_MID[f] * pos.MatIndex(BLACK) / 32;
		boardScore += PSQ_K_END[f] * (32 - pos.MatIndex(BLACK)) / 32;
		int penalty = PawnShieldWhite(pentry, f);
		kingSafetyScore += KING_PAWN_SHIELD[penalty] * pos.MatIndex(BLACK) / 32;
	}

	{
		f = pos.King(BLACK);
		kingSafetyScore -= PSQ_K_MID[FLIP[f]] * pos.MatIndex(WHITE) / 32;
		boardScore -= PSQ_K_END[FLIP[f]] * (32 - pos.MatIndex(WHITE)) / 32;
		int penalty = PawnShieldBlack(pentry, f);
		kingSafetyScore -= KING_PAWN_SHIELD[penalty] * pos.MatIndex(WHITE) / 32;
	}

	posScore += mobScore * g_evalParams.Mobility / 50;
	posScore += pawnStructScore * g_evalParams.PawnStruct / 50;
	posScore += pawnPassedScore * g_evalParams.PawnPassed / 50;
	posScore += kingSafetyScore * g_evalParams.KingSafety / 50;
	posScore += boardScore * g_evalParams.BoardControl / 50;

	EVAL e = matScore + posScore;

	if (e > 0 && ee == EVAL_WHITE_CANNOT_WIN)
		e = 0;

	if (e < 0 && ee == EVAL_BLACK_CANNOT_WIN)
		e = 0;

	if (ee == EVAL_PROBABLE_DRAW)
		e /= 2;

	return (pos.Side() == WHITE)? e : -e;
}
void buildTestScene2()
{
    float w,h,f;
    w = 9.0f;
    h = 6.0f;
    f = 3.0f;

    float con = 2;

    cam = PinholeCamera(Vec3(0.0f,0.0f,0.0f), Vec3(0.0f,0.0f,-5.0f), Vec3(0.0f,1.0f,0.0f),f,w,h);
    buffer = RayBuffer();
    PointLight *l;
    l = new PointLight(Vec3(0.0f, con-0.10f, -con),Col(1.0f,1.0f,1.0f), 15, 1, 1, 1);
    lights.addLight(*l);


    std::vector<Collidable *> *vec = new std::vector<Collidable *>();

    Collidable *c;

    c = new Sphere(Vec3(0.0f, 0.0f, -2.0f), 0.50f, Material(3));
    c->precomputeBounds();
    vec->push_back(c);

    c = new Sphere(Vec3(-1.0f, -1.0f, -3.0f), 1.0f, Material(1));
    c->precomputeBounds();
    vec->push_back(c);


    //left
    c = new Triangle( Vec3(-con,-con,0), Vec3(-con,-con,-2*con), Vec3(-con,con,0), Material(8));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Triangle( Vec3(-con,-con,-2*con), Vec3(-con,con,-2*con), Vec3(-con,con,0), Material(8));
    c->precomputeBounds();
    vec->push_back(c);
    //right
    c = new Triangle( Vec3(con,-con,0), Vec3(con,con,0), Vec3(con,-con,-2*con), Material(9));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Triangle( Vec3(con,-con,-2*con), Vec3(con,con,0), Vec3(con,con,-2*con), Material(9));
    c->precomputeBounds();
    vec->push_back(c);
    //back
    c = new Triangle( Vec3(-con,con,-2*con), Vec3(-con,-con,-2*con), Vec3(con,-con,-2*con), Material(10));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Triangle( Vec3(-con,con,-2*con), Vec3(con,-con,-2*con), Vec3(con,con,-2*con), Material(10));
    c->precomputeBounds();
    vec->push_back(c);
    //bottom
    c = new Triangle( Vec3(-con,-con,0), Vec3(con,-con,0), Vec3(con,-con,-2*con), Material(10));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Triangle( Vec3(-con,-con,-2*con), Vec3(-con,-con,0), Vec3(con,-con,-2*con), Material(10));
    c->precomputeBounds();
    vec->push_back(c);
    //top
    c = new Triangle( Vec3(-con,con,0), Vec3(con,con,-2*con), Vec3(con,con,0), Material(10));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Triangle( Vec3(-con,con,-2*con), Vec3(con,con,-2*con), Vec3(-con,con,0), Material(10));
    c->precomputeBounds();
    vec->push_back(c);


    //front
    c = new Triangle( Vec3(-con,con,con), Vec3(con,-con,con), Vec3(-con,-con,con), Material(2));
    c->precomputeBounds();
    vec->push_back(c);
    c = new Triangle( Vec3(-con,con,con), Vec3(con,con,con), Vec3(con,-con,con), Material(2));
    c->precomputeBounds();
    vec->push_back(c);


    sceneTree.buildTreeStart(*vec);


    sceneTree.isLeaf = true;
    sceneTree.items = vec;
    sceneTree.xMin = -100;
    sceneTree.xMax = 100;
    sceneTree.yMin = -100;
    sceneTree.yMax = 100;
    sceneTree.zMin = -100;
    sceneTree.zMax = 100;

    sceneTree.axis = -1;
    sceneTree.depth = 0;
    sceneTree.id = 55;

}
Esempio n. 30
0
void Level::render() {
    GameState::render();

    camera->commit();

    glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
    // Applies camera changes to the scene

    Col axisColor(0.2f, 0.7f, 0.95f, 0.7f);
    //ColExp1 axisColor1(0.2f, 0.7f, 0.95f, 0.7f);
    //ColExp2 axisColor2(0.2f, 0.7f, 0.95f, 0.7f);
    GrcPrimitives::segment(Vec3(0, 0, 0), Vec3(10, 0, 0), axisColor);
    GrcPrimitives::segment(Vec3(0, 0, 0), Vec3(0, 10, 0), axisColor);
    GrcPrimitives::segment(Vec3(0, 0, 0), Vec3(0, 0, 10), axisColor);
    
    GrcPrimitives::ray(exampleEntity->getTransform().getPosition(), exampleEntity->getTransform().getForward(), Col(1.0f, 1.0f, 1.0f, 1.0f));
    GrcPrimitives::ray(exampleEntity->getTransform().getPosition(), exampleEntity->getTransform().getRight(), Col(1.0f, 1.0f, 1.0f, 1.0f));
    GrcPrimitives::ray(exampleEntity->getTransform().getPosition(), exampleEntity->getTransform().getUp(), Col(1.0f, 1.0f, 1.0f, 1.0f));
    
    floorProg->enable();
    floorProg->bindTexture("tex", floorTex->index, GL_TEXTURE_2D, 0);
    GLfloat light0Color[]={1.0f, 1.0f, 0.8f};
    floorProg->setUniformfv("lightColor", light0Color, 3);
    glColor3f(1.0f, 1.0f, 1.0f);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glBegin(GL_QUADS);
    {
        float s = 20.f;
        float rep = 20.f;
        glTexCoord2f(0.f, 0.f);
        glVertex3f(-s, -5, -s);
        glTexCoord2f(rep, 0.f);
        glVertex3f(s, -5.f, -s);
        glTexCoord2f(rep, rep);
        glVertex3f(s, -5.f, s);
        glTexCoord2f(0.f, rep);
        glVertex3f(-s, -5.f, s);
    }
    glEnd();
    floorProg->disable();

    objProg->enable();
    objProg->setUniformfv("lightColor", light0Color, 3);
    exampleEntity->Render();
    objProg->disable();
}