예제 #1
0
/* escape algorithm for PC */
static void escape()
{
	// look for optimal escape	
	int x, y, escx = 0, escy = 0, min = 1<<8;
	int pcx, pcy;
	character_getLocation(pc, &pcx, &pcy);
	
	for (x = pcx-1; x <= pcx+1; x++)
	{
		for (y = pcy-1; y <= pcy+1; y++)
		{
			if (x == pcx && y == pcy)
				continue; // skip myself
			if (hardness[y][x])
				continue; // PC cannot tunnel
			if (scanArea(x, y, 1))
				continue; // absolutely not safe

			scanArea(x, y, 2);
			if (scc < min)
			{
				min = scc;
				escx = x;
				escy = y;
			}
		}
	}
	if (escx && escy)
		update(pc, escx, escy);
	else
		move_random(pc, 0);
}
void StrategyController::run(){
	std::cout << "Strategy running" << std::endl;
	scanArea();
	searchArea();


}
예제 #3
0
int move_pc()
{
	int pcx, pcy, npcx, npcy;
	character_getLocation( pc    , & pcx, & pcy);
	character_getLocation(npcs[0], &npcx, &npcy);
	
	if (nummon <= 0)
	{
		return 0; // game over
	}
	if (invulnerable)
	{
		dijkstra(npcx, npcy, 0);
		move_dijkstra(pc, 0);
	}
	else
	{
		/* PC move algorithm */
		scanArea(pcx, pcy, 3);

		// look for monsters if no monsters are around
		if (scc == 0)
		{
			dijkstra(npcx, npcy, 0);
			move_dijkstra(pc, 0);
		}
		// fight the monster if there is only one
		else if (scc == 1)
		{
			Character *m = scv[0];
			int mx, my;
			character_getLocation(m, &mx, &my);

			int speed = character_getSpeed(m);
			int tpm = 100/speed; // turns per move
			int mvs = 0; // number of moves my enemy will take to reach me
			int mturn = character_getTurn(m);
			int pcturn = character_getTurn(pc);
			for (;pcturn - 10 <= mturn 
					&& mturn < pcturn; mturn+=tpm, mvs++);	
			int x, y, optx = 0, opty = 0, d = 1<<10;
			for (x = pcx - 1; x <= pcx + 1; x++)
			{
				for (y = pcy - 1; y <= pcy + 1; y++)
				{
					if (x == pcx && y == pcy)
						continue;
					if (hardness[y][x])
						continue;
					d = dist(x, y, mx, my);

					// if I can safely attack or my enemy cannot reach me
					if (d == 0 || d - mvs == 1)
					{
						optx = x;
						opty = y;

						if (d == 0) // attack near enemy
							break;
					}
				}
				if (d == 0) // attack near enemy
					break;
			}
			if (optx && opty)
			{
				update(pc, optx, opty);
			}
			else
			{
				escape();
			}
		}
		// escape if there are too many monsters around
		else
		{
			escape();
		}
	}

	// calculate distance map for intelligent monsters to use
	dijkstra(pcx, pcy, 0);
	dijkstra(pcx, pcy, 1);

	return 0;
}