rnode.cpp

来自「三个强盗和三个商人过河的算法」· C++ 代码 · 共 40 行

CPP
40
字号
#include "RNode.h"
#include <iostream>
#include <cmath>

using namespace std;

RNode::RNode(int nodeState) {
	this->nodeState = nodeState;
	this->fatherNode = NULL;
}

RNode::RNode(int nodeState, RNode* fatherNode) {
	this->nodeState = nodeState;
	this->fatherNode = fatherNode;
}

int RNode::getnodeState() const {
	return nodeState;
}

int RNode::move(int method) const {
	int swap = nodeState;

	switch(method) {
		case 0: //(-1, 0, 1, 0)
			return -(swap-1000+10);
		case 1: //(-2, 0, 2, 0)
			return -(swap-2000+20);
		case 2: //(0, -1, 0, 1)
			return -(swap-100+1);
		case 3: //(0, -2, 0, 2)
			return -(swap-200+2);
		case 4: //(-1, -1, 1, 1)
			return -(swap-1100+11);
	}
}

RNode* RNode::getfatherNode() const {
	return fatherNode;
}

⌨️ 快捷键说明

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