2 #include "PuzzleExplorer.h" 24 setBlocks(blockPositions);
39 void PuzzleExplorer::setNodes()
41 for(
int i=0; i<16; i++)
46 node.
setPosition(nodePositionList[i][0], nodePositionList[i][1]);
53 void PuzzleExplorer::setBlocks(
int *blockPositions)
55 for(
int i=0; i<5; i++)
57 Block block(blockPositions[i]);
74 void PuzzleExplorer::setNeighborNode()
77 for(
int i=0; i<16;i++)
79 Node* neighbor[5] = {};
81 for(
int j=0; j<5; j++)
84 if(neighborList[i][j] == -1)
86 neighbor[j] =
nullptr;
89 Node* node = &nodeList[neighborList[i][j]];
113 Node node = nodeList[myPosition];
122 for(
int i=0; i<5; i++){
125 if(nodes[i] ==
nullptr)
continue;
133 if(que.front().getHasBlock())
148 Node node = nodeList[startNode];
149 Node goal = nodeList[goalNode];
164 for(
int j=0; j<5; j++)
167 if(explorerNodes[j] ==
nullptr)
continue;
170 int neighborCost =
getCost(*explorerNodes[j], goal);
171 if(cost > neighborCost)
174 nextNode = *explorerNodes[j];
178 root[i] = nextNode.
getNum();
void setPosition(int x, int y)
void setMyPosition(int num)
int getCost(Node node1, Node node2)
void setHasBlock(bool exists)
void init(int *blockPositions)
void setColor(BlockColor blockColor)
BlockColor getNodeColor(int num)
void setNeighbor(Node **nodes)
int * getRoot(int startNode, int goalNode)
int getNearestBlockPosition()