Ejemplo n.º 1
0
//---------------------------------------------------------------------------
const double ChessGame::AttributeValue(
  const ChessMove& move) const
{
  double value = 0.0;
  const int y1 = move.y1;
  const int x1 = move.x1;
  const int y2 = move.y2;
  const int x2 = move.x2;
  const ChessPiece piece = mBoard.GetPiece(x1,y1);
  assert(piece.IsNull()==false);
  //const EnumChessPieceColor color = piece.GetColor();

  if (mBoard.GetPiece(x2,y2).IsNull()==false)
  {
    //An expensive piece should not take a cheaper piece
    //The more expensive the piece to move,
    //  the less motivated it will be to take a piece
    if (piece.GetType()==king  ) { value-=100.0; }
    if (piece.GetType()==queen ) { value-= 9.0; }
    if (piece.GetType()==rook  ) { value-= 4.0; }
    if (piece.GetType()==bishop) { value-= 2.0; }
    if (piece.GetType()==knight) { value-= 2.0; }
    if (piece.GetType()==pawn  ) { value-= 0.0; }
    //The more expensive the piece to take,
    //  the more motivated it will be to take it
    const ChessPiece victim = mBoard.GetPiece(x2,y2);
    if (victim.GetType()==king  ) { value+=100000.0; }
    if (victim.GetType()==queen ) { value+=10.0; }
    if (victim.GetType()==rook  ) { value+= 5.0; }
    if (victim.GetType()==bishop) { value+= 3.0; }
    if (victim.GetType()==knight) { value+= 3.0; }
    if (victim.GetType()==pawn  ) { value+= 1.0; }
  }
  return value;
}
Ejemplo n.º 2
0
void GamePresenter::drawBoard() {
	SDL_RenderClear(main_renderer);
	SDL_RenderCopy(main_renderer,background,NULL,&fullscreen);
	SDL_Rect currentField;
	currentField.h = SCREEN_HEIGHT/8;
	currentField.w = SCREEN_WIDTH/8;
	currentField.y = 0;
	for(int a = 7; a >= 0; a--){
		currentField.x = 0;
		for(int b = 0; b<8; b++){
			ChessPiece* CurrentPiece = currentgame->getPieceAtLocation(a*8 + b);
			if (CurrentPiece)
				SDL_RenderCopy(main_renderer,piecesheet,&pieces[getSpriteForPiece(CurrentPiece->GetType(),CurrentPiece->GetColor())],&currentField);
			currentField.x += currentField.w;
		}
		currentField.y += currentField.h;
	}
	if (currentgame->isGameOver()){
		SDL_SetTextureAlphaMod(piecesheet,160);
		if (currentgame->getResult() == "White wins"){
			SDL_RenderCopy(main_renderer,piecesheet,&pieces[getSpriteForPiece('K','W')],&fullscreen);

		}
		if (currentgame->getResult() == "Black wins"){
			SDL_RenderCopy(main_renderer,piecesheet,&pieces[getSpriteForPiece('K','B')],&fullscreen);
		}
		if (currentgame->getResult() == "Draw"){
			SDL_Rect lefthalf;
			lefthalf.h=SCREEN_HEIGHT;
			lefthalf.w=SCREEN_WIDTH/2;
			lefthalf.x=0;
			lefthalf.y=0;
			SDL_Rect righthalf(lefthalf);
			righthalf.x=SCREEN_WIDTH/2;
			SDL_Rect halfwhiteking=pieces[getSpriteForPiece('K','W')];
			SDL_Rect halfblackking=pieces[getSpriteForPiece('K','B')];
			halfwhiteking.w/=2;
			halfblackking.w/=2;
			halfblackking.x+=halfblackking.w;
			SDL_RenderCopy(main_renderer,piecesheet,&halfwhiteking,&lefthalf);
			SDL_RenderCopy(main_renderer,piecesheet,&halfblackking,&righthalf);
		}
		SDL_SetTextureAlphaMod(piecesheet,255);
	}
	SDL_RenderPresent(main_renderer);
}