Beispiel #1
0
bool Leg::canStepTo(const Vec3f& p) {
  ActLens a = solveIK(p);
  ActLens b = solveIK(Vec3f(p.x, p.y, parent->getUpHeight()));
  ActLens c = solveIK(Vec3f(p.x, p.y, parent->getDownHeight()));

  return (canMoveTo(a) && canMoveTo(b) && canMoveTo(c));
}
Beispiel #2
0
//! Can the player intersect the checking piece?
bool Board::canIntersectChecker(Color color, Piece* checker)
{
	// Impossible to intersect a Knight
	if(checker->getType() == KNIGHT)
		return false;

	Position kingPos = getPiece(KING, color)->getPos();

	// Impossible to intersect something that's one unit close
	Position diff;
	diff.x = checker->getPos().x - kingPos.x;
	diff.y = checker->getPos().y - kingPos.y;

	if(abs(diff.x) + abs(diff.y) <= 2 && abs(diff.x) <= 1 && abs(diff.y) <= 1)
	{
		return false;
	}
	else
	{
		// Vertically
		if(diff.x == 0 && diff.y != 0)
		{
			for(int i = 0; i < abs(diff.y); i++)
			{
				if(canMoveTo(color, kingPos.x, kingPos.y + i*diff.y/abs(diff.y)))	{
					return true;
				}

			}
		}
		// Horizontally
		else if(diff.x != 0 && diff.y == 0)
		{
			for(int i = 0; i < abs(diff.x); i++)
			{
				if(canMoveTo(color, kingPos.x + i*diff.x/abs(diff.x), kingPos.y))	{
					return true;
				}

			}
		}
		// Diagonally
		else if(abs(diff.x) == abs(diff.y) && diff.x != 0)
		{
			for(int i = 0; i < abs(diff.x); i++)
			{
				if(canMoveTo(color, kingPos.x + i*diff.x/abs(diff.x), kingPos.y + i*diff.y/abs(diff.y)))	{
					return true;
				}

			}
		}
	}

	return false;
}
Beispiel #3
0
/* moves down the figure and returns true if gameover */
static void move_down (void)
{
    int l, i, rx, ry;

    if (!canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co)) {
        /* save figure to board */
        for (i = 0; i < 4; i++) {
            rx = getRelativeX (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cx;
            ry = getRelativeY (rockblox_status.cf, i, rockblox_status.co) + rockblox_status.cy;
            rockblox_status.board[ry][rx] = rockblox_status.cf;
        }
        /* check if formed some lines */
        l = check_lines ();
        if (l) {
            /* the original scoring from "http://en.wikipedia.org/wiki/Rockblox" */
            rockblox_status.score += scoring[l - 1] * rockblox_status.level;
            rockblox_status.lines += l;
            rockblox_status.level = (int) rockblox_status.lines / 10 + 1;
        }

        /* show details */
        show_details ();

        /* generate a new figure */
        new_block ();
    } else
        move_block (0, 1, rockblox_status.co);
}
Beispiel #4
0
/* move the block to a relative location */
static void move_block (int x, int y, int o)
{
    if (!rockblox_status.dropped && canMoveTo (rockblox_status.cx + x, rockblox_status.cy + y, o)) {
        rockblox_status.cy += y;
        rockblox_status.cx += x;
        rockblox_status.co = o;
    }
}
Beispiel #5
0
void GenericTetris::oneLineDown()
{
    if (currentLine == -1)
        return;
    if (canMoveTo(currentPos,currentLine - 1)) {
        moveTo(currentPos,currentLine - 1);
    } else
		pieceDropped(0);
}
Beispiel #6
0
void GenericTetrix::moveRight(int steps)
{
    while(steps) {
        if (!canMoveTo(currentPos + 1,currentLine))
            return;
        moveTo(currentPos + 1,currentLine);
        steps--;
    }
}
Beispiel #7
0
void GenericTetris::moveLeft(int steps)
{
    while(steps) {
        if (!canMoveTo(currentPos - 1,currentLine))
            return;
        moveTo(currentPos - 1,currentLine);
        steps--;
    }
}
/* try to add a new block to play with (return true if gameover) */
static void new_block (void)
{
    rockblox_status.cy = 1;
    rockblox_status.cx = 5;
    rockblox_status.cf = rockblox_status.nf;
    rockblox_status.co = 0;                     /* start at the same orientation all time */
    rockblox_status.nf = t_rand (BLOCKS_NUM);
    rockblox_status.gameover = !canMoveTo (rockblox_status.cx,
            rockblox_status.cy, rockblox_status.co);

    draw_next_block ();
}
Beispiel #9
0
bool	Dir8TileMap::lineOfSight(int x1, int y1, int x2, int y2, int* rx, int* ry) const
{
	if (isPassable(x1, y1) == false ||
		isPassable(x2, y2) == false)
		return false;

	int dx = ::abs(x2 - x1);
	int sx = x1 < x2 ? 1 : -1;

	int dy = ::abs(y2 - y1);
	int sy = y1 < y2 ? 1 : -1;

	int err = (dx > dy ? dx : -dy) / 2;

	int nx = x1;
	int ny = y1;

	for (;;)
	{
		if (nx == x2 && ny == y2)
		{
			// 성공시 마직막 지점
			if (rx != nullptr) *rx = x2;
			if (ry != nullptr) *ry = y2;
			break;
		}

		x1 = nx;
		y1 = ny;
		int temp = err;
		if (temp > -dx)
		{
			err -= dy;
			nx += sx;
		}
		if (temp < dy)
		{
			err += dx;
			ny += sy;
		}

		if (canMoveTo(x1, y1, nx, ny) == false)
		{
			// 충돌 직전 지점
			if (rx != nullptr) *rx = x1;
			if (ry != nullptr) *ry = y1;
			return false;
		}
	}

	return true;
}
Beispiel #10
0
bool World::canMove(Bot* bot , int x , int y) // no diagonal movement. Current assumption is that |x| + |y| = 1
{
    Grid g = bot->getLocation();
    Grid target = Grid(g.row+y , g.col+x);
    if(canMoveTo(target))
    {
        return true;    
    }
    else
    {
        return false;
    }

}
Beispiel #11
0
void GenericTetris::newPiece()
{
    currentPiece = nextPiece;
    if (showNext)
        eraseNextPiece();
    nextPiece.setRandomType(gameType());
    if (showNext)
        showNextPiece();
    currentLine = Height - 1 + currentPiece.getMinY();
    currentPos  = Width/2 + 1;
    if (!canMoveTo(currentPos,currentLine)) {
	currentLine = -1;
        gameOver();
    } else {
        showPiece();
    }
}
Beispiel #12
0
void GenericTetrix::dropDown()
{
    if (currentLine == -1)
        return;

    int dropHeight = 0;
    int newLine    = currentLine;
    while(newLine) {
        if (!canMoveTo(currentPos,newLine - 1))
            break;
        newLine--;
        dropHeight++;
    }
    if (dropHeight != 0)
        moveTo(currentPos,newLine);
    internalPieceDropped(dropHeight);
}
void MapModel::readMapInfo(bool backup){
	ResourceModel *rm = ResourceModel::getModel();
    size_t pos = mapName.find(".tmx");
	mapName.replace(pos, pos + 4, "");
	string filename = mapName + ".info";

	if (backup)
		filename += ".backup";

	FILE *fp = rm->OpenFileR(filename);
	CCASSERT(fp != nullptr, "read map info fail");

    int id, x, y, height;
    char owner[256];
	while (~fscanf(fp, "%d %d %d %d %s", &id, &x, &y, &height, owner)){
		CCLOG("info: %d %d %d %d %s", id, x, y, height, owner);
		string ownerString = string(owner);

		//@brief for server assigned map
		if (height > SZ(_pfLayers))
			height = SZ(_pfLayers) - 1;
		while (height > 2 && !canMoveTo(MapPoint(x, y), height))
			height--;

		addBuildingToMap(id, ownerString, MapPoint(x, y), height, false);
	}

	fclose(fp);

	
	/*
	CCLOG(">> _baseBuidling = nullptr => %s", PlayerManager::getInstance()->getCurPlayer()->height == -1 ? "Yes" : "No");
	if (PlayerManager::getInstance()->getCurPlayer()->height != -1 && rm->strWorldMap == mapName){
		CCLOG(">> after win, delete basebuilding");
		//pm->_baseBuilding->sett
		Building* tmp = Building::build(1);
		tmp->setZ(PlayerManager::getInstance()->getCurPlayer()->height);
		tmp->setCoord(PlayerManager::getInstance()->getCurPlayer()->coord);
		buildingDelete(tmp);
		PlayerManager::getInstance()->getCurPlayer()->height = -1;
	}
	CCLOG(">> _baseBuidling = nullptr => %s", PlayerManager::getInstance()->getCurPlayer()->height == -1 ? "Yes" : "No");
	*/
	CCLOG("readMapInfo finish");
}
Beispiel #14
0
bool Leg::setTarget(Vec3f p, bool force) {
  ActLens acts = solveIK(p);
  
  if(force || canMoveTo(acts)) {
    target = p;

    if(!remote) {
      actuators[0].setTarget(acts.a, force);
      actuators[1].setTarget(acts.b, force);
      actuators[2].setTarget(acts.c, force);
    }
    else
      RemoteManager.sendTarget(remotePort, remoteIndex, target);
   

    return true;
  }
  else return false;
}
Beispiel #15
0
//! Checks if the player with the color color is check mate.
bool Board::checkMate(Color color)
{
	// Find out the piece(s) that are checking
	Piece* checker = NULL;
	int checkers = 0;
	checker = getCheckers(color, checkers);
	if(checkers != 0)
	{
		// Is there any move white can do?
		// 1.) Can he move the king out of check?
		// 2.) Can he capture the checker?
		// 3.) Can he go between the checking line?

		// Impossible to capture or intersect two checking pieces
		if(!canMoveKing(color) && checkers >= 2)
			return true;

		return !canMoveKing(color) && !canMoveTo(color, checker->getPos().x, checker->getPos().y) && !canIntersectChecker(color, checker);
	}
	else 
		return false;
}
Beispiel #16
0
bool Leg::canMoveTo(const Vec3f& p) {
  ActLens a = solveIK(p);
  return canMoveTo(a);
}
Beispiel #17
0
static int rockblox_loop (void)
{
    int button;
#if defined(ROCKBLOX_OFF_PRE) || defined(ROCKBLOX_DROP_PRE)
    int lastbutton = BUTTON_NONE;
#endif
    long next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);

    if (rockblox_menu()) {
        return 1;
    }
    resume = false;
    resume_file = false;

    while (1) {
#ifdef HAS_BUTTON_HOLD
        if (rb->button_hold ()) {
            /* Turn on backlight timeout (revert to settings) */
            backlight_use_settings();
            rb->splash(0, "Paused");
            while (rb->button_hold ())
                rb->sleep(HZ/10);

            /* Turn off backlight timeout */
            backlight_ignore_timeout();

            /* get rid of the splash text */
            rb->lcd_bitmap (rockblox_background, 0, 0, LCD_WIDTH, LCD_HEIGHT);
            show_details ();
#ifdef HIGH_SCORE_Y
            show_highscores ();
#endif
            draw_next_block ();
            refresh_board ();
        }
#endif

        button = rb->button_get_w_tmo (MAX(next_down_tick - *rb->current_tick, 1));
        switch (button) {
#ifdef ROCKBLOX_RC_OFF
            case ROCKBLOX_RC_OFF:
#endif
            case ROCKBLOX_OFF:
#ifdef ROCKBLOX_OFF_PRE
                if (lastbutton != ROCKBLOX_OFF_PRE)
                    break;
#endif
                resume = true;
                return 0;
                break;

#if defined(ROCKBLOX_ROTATE)
            case ROCKBLOX_ROTATE:
#endif
            case ROCKBLOX_ROTATE_CCW:
            case ROCKBLOX_ROTATE_CCW | BUTTON_REPEAT:
#ifdef HAVE_SCROLLWHEEL
                /* if the wheel is disabled, add an event to the stack. */
                if(wheel_enabled == false)
                    wheel_events++;

                /* if it's enabled, go ahead and rotate.. */
                if(wheel_enabled)
#endif
#ifdef ROCKBLOX_ROTATE_CCW2
                /* fallback */
            case ROCKBLOX_ROTATE_CCW2:
#endif
                move_block (0, 0, (rockblox_status.co + 1) % figures[rockblox_status.cf].max_or);
                break;

            case ROCKBLOX_ROTATE_CW:
            case ROCKBLOX_ROTATE_CW | BUTTON_REPEAT:
#ifdef HAVE_SCROLLWHEEL
                if(wheel_enabled == false)
                    wheel_events++;

                if(wheel_enabled)
#endif
#ifdef ROCKBLOX_ROTATE_CW2
                /* fallback */
            case ROCKBLOX_ROTATE_CW2:
#endif
                move_block (0, 0,
                            (rockblox_status.co + figures[rockblox_status.cf].max_or -
                             1) % figures[rockblox_status.cf].max_or);
                break;

            case ROCKBLOX_DOWN:
            case ROCKBLOX_DOWN | BUTTON_REPEAT:
                move_block (0, 1, rockblox_status.co);
                break;

            case ROCKBLOX_RIGHT:
            case ROCKBLOX_RIGHT | BUTTON_REPEAT:
                move_block (1, 0, rockblox_status.co);
                break;

            case ROCKBLOX_LEFT:
            case ROCKBLOX_LEFT | BUTTON_REPEAT:
                move_block (-1, 0, rockblox_status.co);
                break;

            case ROCKBLOX_DROP:
#ifdef ROCKBLOX_DROP_PRE
                if (lastbutton != ROCKBLOX_DROP_PRE)
                    break;
#endif
                while (canMoveTo (rockblox_status.cx, rockblox_status.cy + 1, rockblox_status.co))
                    move_block (0, 1, rockblox_status.co);
                rockblox_status.dropped = true;
                break;
#ifdef ROCKBLOX_RESTART
            case ROCKBLOX_RESTART:
                rb->splash (HZ * 1, "Restarting...");
                init_rockblox (false);
                break;
#endif

            default:
                if (rb->default_event_handler (button) == SYS_USB_CONNECTED)
                    return PLUGIN_USB_CONNECTED;
                break;
        }
#if defined(ROCKBLOX_OFF_PRE) || defined(ROCKBLOX_DROP_PRE)
        if (button != BUTTON_NONE)
            lastbutton = button;
#endif

#ifdef HAVE_SCROLLWHEEL
        /* check if we should enable the scroll wheel, if events
         * begin to stack up... */
        if(wheel_enabled == false)
        {
            /* stopped rotating the wheel, reset the count */
            if(wheel_events == last_wheel_event)
            {
                last_wheel_event = 0;
                wheel_events = 0;
            }
            /* rotated the wheel a while constantly, enable it. */
            else if(wheel_events > 3)
            {
                wheel_enabled = true;
            }

            /* this evens out the last event and the "current" event.
             * if we get an event next time through button reading, it will
             * remain ahead of last_event. if we don't, they'll end up equaling
             * each other.. thus, the scroll count will be reset. */
            if(wheel_enabled == false && wheel_events > last_wheel_event)
                last_wheel_event++;
        }
#endif

        if (TIME_AFTER(*rb->current_tick, next_down_tick)) {
            move_down ();
            next_down_tick += level_speed(rockblox_status.level);
            if (TIME_AFTER(*rb->current_tick, next_down_tick))
                /* restart time "raster" when we had to wait longer than usual
                 * (pause, game restart etc) */
                next_down_tick = *rb->current_tick + level_speed(rockblox_status.level);
        }

        if (rockblox_status.gameover) {
#if LCD_DEPTH >= 2
            rb->lcd_set_foreground (LCD_BLACK);
#endif
            show_game_over();
            resume = false;
            return 0;
        }

        refresh_board ();
    }

    return 0;
}
Beispiel #18
0
Direction Monster::getDanceStep(bool keepAttack /*= true*/, bool keepDistance /*= true*/) const
{
	Position position = getPosition();

	assert(attackedCreature);
	bool canDoAttackNow = canUseAttack(position, attackedCreature);
	const Position& centerPos = attackedCreature->getPosition();

	uint32_t tmpDist, centerToDist = std::max(std::abs(static_cast<signed>(position.x) - static_cast<signed>(centerPos.x)), std::abs(static_cast<signed>(position.y) - static_cast<signed>(centerPos.y)));
	if (centerToDist == 0) {
		return getRandomStepDirection(false);
	}

	std::vector<Direction> dirVector;
	if(!keepDistance || position.y >= centerPos.y)
	{
		tmpDist = std::max(std::abs(static_cast<signed>(position.x) - static_cast<signed>(centerPos.x)), std::abs(static_cast<signed>(position.y - 1) - static_cast<signed>(centerPos.y)));
		if(tmpDist == centerToDist && canMoveTo(Direction::NORTH))
		{
			bool result = true;
			if(keepAttack)
				result = (!canDoAttackNow || canUseAttack(Position(position.x, position.y - 1, position.z), attackedCreature));

			if(result)
				dirVector.push_back(Direction::NORTH);
		}
	}

	if(!keepDistance || position.y <= centerPos.y)
	{
		tmpDist = std::max(std::abs(static_cast<signed>(position.x) - static_cast<signed>(centerPos.x)), std::abs(static_cast<signed>(position.y + 1) - static_cast<signed>(centerPos.y)));
		if(tmpDist == centerToDist && canMoveTo(Direction::SOUTH))
		{
			bool result = true;
			if(keepAttack)
				result = (!canDoAttackNow || canUseAttack(Position(position.x, position.y + 1, position.z), attackedCreature));

			if(result)
				dirVector.push_back(Direction::SOUTH);
		}
	}

	if(!keepDistance || position.x <= centerPos.x)
	{
		tmpDist = std::max(std::abs(static_cast<signed>(position.x + 1) - static_cast<signed>(centerPos.x)), std::abs(static_cast<signed>(position.y) - static_cast<signed>(centerPos.y)));
		if(tmpDist == centerToDist && canMoveTo(Direction::EAST))
		{
			bool result = true;
			if(keepAttack)
				result = (!canDoAttackNow || canUseAttack(Position(position.x + 1, position.y, position.z), attackedCreature));

			if(result)
				dirVector.push_back(Direction::EAST);
		}
	}

	if(!keepDistance || position.x >= centerPos.x)
	{
		tmpDist = std::max(std::abs(static_cast<signed>(position.x - 1) - static_cast<signed>(centerPos.x)), std::abs(static_cast<signed>(position.y) - static_cast<signed>(centerPos.y)));
		if(tmpDist == centerToDist && canMoveTo(Direction::WEST))
		{
			bool result = true;
			if(keepAttack)
				result = (!canDoAttackNow || canUseAttack(Position(position.x - 1, position.y, position.z), attackedCreature));

			if(result)
				dirVector.push_back(Direction::WEST);
		}
	}

	if(dirVector.empty())
		return Direction::NONE;

	return dirVector[random_range<uint32_t>(0, dirVector.size() - 1)];
}