Example #1
0
void Drawer::DrawMine(Block ***obj, Miner obj2, int startDrawX, int startDrawY, int Vision, int Colunas, int Linhas)
{

    int rMinimum = (obj2.getY() - Vision > 0) ? obj2.getY() - Vision : 0;
    int rMaximum = (obj2.getY() + Vision < Linhas) ? obj2.getY() + Vision : obj2.getY() + (Linhas - obj2.getY());

    int cMinimum = (obj2.getX() - Vision > 0) ? obj2.getX() - Vision : 0;
    int cMaximum = (obj2.getX() + Vision < Colunas) ? obj2.getX() + Vision : obj2.getX() + (Colunas - obj2.getX());

    for (int r = 0, mineR = startDrawY; r < 7; r++, mineR++)
        {
            for (int c = 0, mineC = startDrawX; c < 7; c++, mineC++)
                {
                    if (obj2.getX() == mineC && obj2.getY() == mineR)
                        {
                            if (typeid(*obj[mineR][mineC]).name() == typeid(Escada).name())
                                {
                                    Draw(obj2, c * 5, r * 5, SHOW, 1);
                                }
                            else if (typeid(*obj[mineR][mineC]).name() == typeid(Viga).name())
                                {
                                    Draw(obj2, c * 5, r * 5, SHOW, 2);
                                }
                            else
                                Draw(obj2, c * 5, r * 5, SHOW, 0);
                        }
                    else if (mineR >= rMinimum && mineR <= rMaximum && mineC >= cMinimum && mineC <= cMaximum)
                        {
                            DrawBlock(obj[mineR][mineC]->getDrawSequence(), c * 5, r * 5);
                        }
                }
        }
}
Example #2
0
int main()
{
//define this to send output to a text file (see locations.h)
#ifdef TEXTOUTPUT
  os.open("output.txt");
#endif

  //seed random number generator
  srand((unsigned) time(NULL));

  //create a miner
  Miner* Bob = new Miner(ent_Miner_Bob);

  //create his wife
  MinersWife* Elsa = new MinersWife(ent_Elsa);

  //create barfly
  BarFly* Henry = new BarFly(ent_Henry);

  //register them with the entity manager
  EntityMgr->RegisterEntity(Bob);
  EntityMgr->RegisterEntity(Elsa);
  EntityMgr->RegisterEntity(Henry);

  //run Bob and Elsa through a few Update calls
  for (int i=0; i<30; ++i)
  { 
    Bob->Update();
    Elsa->Update();
	Henry->Update();

    //dispatch any delayed messages
    Dispatch->DispatchDelayedMessages();

    Sleep(800);
  }

  //tidy up
  delete Bob;
  delete Elsa;
  delete Henry;

  //wait for a keypress before exiting
  PressAnyKeyToContinue();


  return 0;
}
Example #3
0
int main()
{
    
#ifdef TEXTOUTPUT
    os.open("output.txt");
#endif
    
    //seed random number generator
    srand((unsigned) time(NULL));
    
    Miner* Bob = new Miner(ent_Miner_Bob);
    MinersWife* Elsa = new MinersWife(ent_Elsa);
    Cat* Kitty = new Cat(ent_Cat);
    
    
    EntityMgr->RegisterEntity(Bob);
    EntityMgr->RegisterEntity(Elsa);
    EntityMgr->RegisterEntity(Kitty);
    
    for(int i=0; i<30;++i){
        Bob->Update();
        Elsa->Update();
        Kitty->Update();
        Dispatch->DispatchDelayedMessages();
        
        
        usleep(500000);

    }
    
   
    delete Bob;
    delete Elsa;
    delete Kitty;
    
    return 0;
    
}
Example #4
0
#define CATCH_CONFIG_MAIN
//------------------------------------------------------------------------------
#include <catch.hpp>
#include "miner_maxer.h"
//------------------------------------------------------------------------------
TEST_CASE("miner/init", "check init value") {
  Miner< int > miner(500);

  REQUIRE( 500 == miner.value() );
}
//------------------------------------------------------------------------------
TEST_CASE("miner/valid", "check valid") {
  Miner< int > miner(100);

  miner.setValue(10);
  miner.setValue(-10);
  miner.setValue(50);
  miner.setValue(0);
  miner.setValue(20);

  REQUIRE( -10 == miner.value() );
}
//------------------------------------------------------------------------------
TEST_CASE("maxer/init", "check init value") {
  Miner< int > miner(-500);

  REQUIRE( -500 == miner.value() );
}
//------------------------------------------------------------------------------
TEST_CASE("maxer/valid", "check valid") {
  Maxer< int > maxer(-100);
Example #5
0
int _tmain(int argc, _TCHAR* argv[])
{
	srand(time(NULL));

	Miner miner;
	Saper saper;
	texture tex;

	bool settingCows = true;

	//std::vector<Cow*> cows;
	application::gameMap.clearPathfinding();

	while ( application::window.isOpen())
	{
		sf::Event event;
		while (application::window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				application::window.close();

			if (event.type == sf::Event::KeyPressed)
			{
				if (event.key.code == sf::Keyboard::Space)
				{
					if (application::gameState == STATE_PAUSE) application::gameState = application::previousGameState;
					else
					{
						application::previousGameState = application::gameState;
						application::gameState = STATE_PAUSE;
					}
				}
			}
		}

		application::window.clear(sf::Color::Black);

		switch (application::gameState)
		{
			case STATE_MINER:
				miner.work();
				application::window.setTitle("Miner rozklada elementy otoczenia...");
				break;

			case STATE_SAPER:
				saper.work();
				application::window.setTitle("Saper analizuje pole minowe...");
				break;

			case STATE_COWS:
				if (Cow::allCows.size() == 0)
				{
					if (settingCows)
					{
					
						settingCows = false;
						for (size_t i = 0; i < application::gameMap.mapSize.y; i += 2)
						//for (size_t i = 0; i < 2; i += 2)
						{
							new Cow(application::gameMap.getTileByXY(sf::Vector2i(0, i)));
						}
					}
					else
					{
						application::gameState = STATE_MINER;
						settingCows = true;
						break;
					}
					
				}

				for (size_t i = 0; i < Cow::allCows.size(); i++)
				{
					if (!Cow::allCows[i]->workFinished())
					{
						Cow::allCows[i]->work();
					}
					else
					{
						Cow::allCows.erase(Cow::allCows.begin() + i);
					}
				}

				application::window.setTitle("Krowy probuja przejsc na druga strone...");

				break;


			case STATE_PAUSE:
				application::window.setTitle("PAUZA");
				break;

		}


		for (unsigned int a(0); a < iDraw::drawVector.size(); a++)
		{
			iDraw::drawVector[a]->draw();
		}

		sf::RectangleShape line(sf::Vector2f(5, application::gameMap.mapSize.y * TILE_SIZE));
		line.setFillColor(sf::Color::Black);
		line.move(TILE_SIZE - 2, 0);
		application::window.draw(line);
		line.move(TILE_SIZE * SIZE_X, 0);
		application::window.draw(line);
		line.move(TILE_SIZE * SIZE_X, 0);
		application::window.draw(line);
		line.move(TILE_SIZE * SIZE_X, 0);
		application::window.draw(line);
		
		sf::RectangleShape line2(sf::Vector2f((application::gameMap.mapSize.x - 2) * TILE_SIZE, 5));
		line2.setFillColor(sf::Color::Black);
		line2.move(TILE_SIZE, TILE_SIZE * SIZE_Y - 2);
		application::window.draw(line2);

		for (size_t i = 0; i < Cow::allCows.size(); i++)
		{
			Cow::allCows[i]->draw();
		}

		application::window.display();
	}

	return 0;
}
Example #6
0
bool MergedMiner::mine(std::string address1, std::string wallet1, std::string address2, std::string wallet2, size_t threads) {
  epee::net_utils::http::http_simple_client httpClient1;
  epee::net_utils::http::http_simple_client httpClient2;
  Miner miner;
  BlockTemplate blockTemplate1;
  BlockTemplate blockTemplate2;
  cryptonote::block block1;
  cryptonote::block block2;
  cryptonote::difficulty_type difficulty1;
  cryptonote::difficulty_type difficulty2;
  std::future<bool> request1;
  std::future<bool> request2;
  std::future<bool> mining;
  crypto::hash hash;
  std::chrono::steady_clock::time_point time1;

  uint64_t prefix1;
  cryptonote::account_public_address walletAddress1;
  if (!get_account_address_from_str(prefix1, walletAddress1, wallet1)) {
    std::lock_guard<std::mutex> lock(m_mutex);
    m_messages.push("Failed to parse donor wallet address");
    return false;
  }

  uint64_t prefix2;
  cryptonote::account_public_address walletAddress2;
  if (!address2.empty() && !get_account_address_from_str(prefix2, walletAddress2, wallet2)) {
    std::lock_guard<std::mutex> lock(m_mutex);
    m_messages.push("Failed to parse acceptor wallet address");
    return false;
  }

  m_blockCount = 0;
  for (;;) {
    miner.getHashCount();

    if (m_stopped) {
      if (mining.valid()) {
        miner.stop();
        mining.wait();
      }

      return true;
    }

    request1 = std::async(std::launch::async, getBlockTemplate, &httpClient1, &address1, &wallet1, MERGE_MINING_TAG_RESERVED_SIZE, &blockTemplate1);
    if (!address2.empty()) {
      request2 = std::async(std::launch::async, getBlockTemplate, &httpClient2, &address2, &wallet2, MERGE_MINING_TAG_RESERVED_SIZE, &blockTemplate2);
    }

    if (!request1.get()) {
      std::lock_guard<std::mutex> lock(m_mutex);
      m_messages.push("Failed to get donor block");
      continue;
    }

    if (!address2.empty()) {
      if (!request2.get()) {
        std::lock_guard<std::mutex> lock(m_mutex);
        m_messages.push("Failed to get acceptor block");
        continue;
      }

      if (blockTemplate2.block.major_version != BLOCK_MAJOR_VERSION_2) {
        std::lock_guard<std::mutex> lock(m_mutex);
        m_messages.push("Unsupported block version received from acceptor network, merged mining is not possible");
        if (mining.valid()) {
          miner.stop();
          mining.wait();
        }

        return false;
      }
    }

    if (mining.valid()) {
      miner.stop();
      if (mining.get()) {
        if (cryptonote::check_hash(hash, difficulty1)) {
          if (submitBlock(httpClient1, address1, block1)) {
            std::lock_guard<std::mutex> lock(m_mutex);
            m_messages.push("Submitted donor block");
          } else {
            std::lock_guard<std::mutex> lock(m_mutex);
            m_messages.push("Failed to submit donor block");
          }
        }

        if (!address2.empty() && cryptonote::check_hash(hash, difficulty2)) {
          if (!mergeBlocks(block1, block2)) {
            std::lock_guard<std::mutex> lock(m_mutex);
            m_messages.push("Internal error");
            return false;
          }

          if (submitBlock(httpClient2, address2, block2)) {
            std::lock_guard<std::mutex> lock(m_mutex);
            m_messages.push("Submitted acceptor block");
          } else {
            std::lock_guard<std::mutex> lock(m_mutex);
            m_messages.push("Failed to submit acceptor block");
          }
        }
      }

      std::chrono::steady_clock::time_point time2 = std::chrono::steady_clock::now();
      std::ostringstream stream;
      stream << "Hashrate: " << miner.getHashCount() / std::chrono::duration_cast<std::chrono::duration<double>>(time2 - time1).count();
      std::lock_guard<std::mutex> lock(m_mutex);
      m_messages.push(stream.str());
      time1 = time2;

      miner.start();
    } else {
      time1 = std::chrono::steady_clock::now();
    }

    block1 = blockTemplate1.block;
    difficulty1 = blockTemplate1.difficulty;
    cryptonote::difficulty_type difficulty = difficulty1;
    if (!address2.empty()) {
      block2 = blockTemplate2.block;
      difficulty2 = blockTemplate2.difficulty;
      difficulty = std::min(difficulty, difficulty2);
      if (!fillExtra(block1, block2)) {
        std::lock_guard<std::mutex> lock(m_mutex);
        m_messages.push("Internal error");
        return false;
      }
    }

    mining = std::async(std::launch::async, &Miner::findNonce, &miner, &block1, blockTemplate1.height, difficulty, threads, &hash);
    for (size_t i = 0; i < 50; ++i) {
      if (m_stopped || mining.wait_for(std::chrono::milliseconds(100)) == std::future_status::ready) {
        break;
      }
    }
  }
}
Example #7
0
void Drawer::DrawStats(Miner obj, int ACTION)
{
    switch (ACTION)
        {
        case SHOW:
            myConsole->setTextColor(myConsole->PRETO);
            myConsole->gotoxy(1, 35);
            std::cout << "X: " << obj.getX() << " Y: " << obj.getY();

            myConsole->gotoxy(1, 36);
            std::cout << "Lives: ";
            myConsole->setTextColor(myConsole->VERDE);
            for (int i = 0; i < obj.getExtraLiveCount(); i++)
                std::cout << (char)3;

            myConsole->setTextColor(myConsole->PRETO);
            myConsole->gotoxy(1, 37);
            std::cout << "Energy: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getEnergyLevel();
            myConsole->setTextColor(myConsole->PRETO);
            myConsole->gotoxy(1, 38);
            std::cout << "Coins: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getCoins();
            myConsole->gotoxy(1, 39);
            myConsole->setTextColor(myConsole->PRETO);
            std::cout << "Bag: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getCapacity() << "/" << obj.getMaxCapacity();
            myConsole->gotoxy(1, 40);
            myConsole->setTextColor(myConsole->PRETO);
            std::cout << "Ladders: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getLadderCount();
            myConsole->gotoxy(1, 41);
            myConsole->setTextColor(myConsole->PRETO);
            std::cout << "Beams: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getBeamCount();
            myConsole->setTextColor(myConsole->PRETO);
            myConsole->gotoxy(1, 42);
            myConsole->setTextColor(myConsole->PRETO);
            std::cout << "Dynamites: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getDynamiteCount();
            myConsole->setTextColor(myConsole->PRETO);
            myConsole->gotoxy(1, 43);
            std::cout << "Parachutes: ";
            myConsole->setTextColor(myConsole->VERDE);
            std::cout << obj.getParachuteCount();
            myConsole->setTextColor(myConsole->PRETO);
            break;
        case REMOVE:
            break;
        }
}