⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fish.cpp

📁 爱因斯坦谜题
💻 CPP
字号:
#include "fish.h"
#include "ApplyHint.h"
#include "ApplyHouseHint.h"
#include "input.h"

#ifdef SHOW
static int g_hint_cnt = 0;
static bool g_only_size = true;
#endif

static void apply_hint(const CSolutionSet &in_set, CSolutionSet &out_set, CApplyHint *apply_hint,
					   const CHint *hints, int num)
{
	CSolutionSet set;

	set = in_set;
	for (int i=0; i<num; i++) {
		apply_hint->SetHint(hints[i]);
		out_set.RemoveAll();
		apply_hint->Apply(set, out_set);
#ifdef SHOW
		printf("\n\n增加约束: %s\n",HINTS_STR[g_hint_cnt++]);
		if (out_set.GetSize()<=4) {
			out_set.Show();
		}
		else {
			out_set.Show(g_only_size);
			if (g_only_size) {
				printf("...\n");
			}
		}
#endif
		set = out_set;
	}
}

static void apply_self_hint(const CSolutionSet &in_set, CSolutionSet &out_set)
{
	CApplyHint hint;
	apply_hint(in_set, out_set, &hint, SELF_HINT, SELF_HINT_CNT);
}

static void apply_ordered_neighbor_hint(const CSolutionSet &in_set, CSolutionSet &out_set)
{
	CApplyOrderedNeighborHint hint;
	apply_hint(in_set, out_set, &hint, ORDER_NEIGHBOR_HINT, ORDER_NEIGHBOR_HINT_CNT);
}

static void apply_neighbor_hint(const CSolutionSet &in_set, CSolutionSet &out_set)
{
	CApplyNeighborHint hint;
	apply_hint(in_set, out_set, &hint, NEIGHBOR_HINT, NEIGHBOR_HINT_CNT);
}

int find_solution(CString &buf)
{
	CSolutionSet set, new_set;
	CSolution sln;
	int i;

	for (i=0; i<MAGIC_NUM; i++) {
		sln.Init(INIT_HINT[i]);
	}
	set.Add(sln);
#ifdef SHOW
	printf("初始状态\n");
	set.Show();
#endif

	apply_self_hint(set, new_set);

	set = new_set;
	apply_ordered_neighbor_hint(set, new_set);

	set = new_set;
	apply_neighbor_hint(set, new_set);

#ifdef SHOW
	printf("\n推理结束。\n");
#else
	new_set.Show(buf);
#endif
	return new_set.GetSize();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -