示例#1
0
int main()
{
	int moveNum = 0;
	

	freopen("input.txt", "r", stdin);

	for (int y = 0; y < 8; y++)
	{
		scanf("%s", map[y]);
	}

	for (int y = 0; y < 8; y++)
	{
		for (int x = 0; x < 8; x++)
		{
			if (map[y][x] == WHITE)
			{
				setBit(&nowCase.m_State, x, y, 1);
			}

			if (map[y][x] == GOAL)
			{
				goalX.push_back(x);
				goalY.push_back(y);
			}
		}
	}

	

	for (;;)
	{
		printBoard();
		char key = getch();

		switch (key)
		{
		case 'a':
			nowCase = nowCase.getNextCase(LEFT);
			break;
		case 'w':
			nowCase = nowCase.getNextCase(UP);
			break;
		case 's':
			nowCase = nowCase.getNextCase(DOWN);
			break;
		case 'd':
			nowCase = nowCase.getNextCase(RIGHT);
			break;
		}
	}
	return 0;
}
示例#2
0
int main()
{
	int moveNum = 0;
	Case firstCase;

	freopen("input.txt", "r", stdin);

	for (int y = 0; y < 8; y++)
	{
		scanf("%s", map[y]);
	}

#ifdef FILE
	freopen("output.txt", "w", stdout);
#endif

	for (int y = 0; y < 8; y++)
	{
		for (int x = 0; x < 8; x++)
		{
			if (map[y][x] == WHITE)
			{
				setBit(&firstCase.m_State, x, y, 1);
			}

			if (map[y][x] == GOAL)
			{
				setBit(&goalState, x, y, 1);
			}

			if (map[y][x] == BLACK)
			{
				setBit(&wallState,x,y,1);
			}
		}
	}

	moveCase.push(firstCase);
	alreadyEntered.insert(firstCase.m_State);

	for (int move = 0;; move++)
	{
		int caseSize = moveCase.size();

		if (caseSize == 0)
		{
			printf("path not found.\n");
			return 0;
		}

		printf("move : %d, case : %d\n", move, caseSize);

		for (int i = 0; i < caseSize; i++)
		{
			Case nowCase = moveCase.front();
			Case nextCase;
			moveCase.pop();

			//도착
			if (nowCase.m_State == goalState)
			{
				printf("%s\n", nowCase.m_Move.c_str());
				return 0;
			}

			for (int j = 0; j < 4; j++)
			{
				nextCase = nowCase.getNextCase(moveList[j]);
				if (!isChecked(nextCase.m_State))
				{
					moveCase.push(nextCase);
					alreadyEntered.insert(nextCase.m_State);
				}
			}
		}
	}

	return 0;
}