'Node' does not implement interface member 'interfaceNameHere'
I'm creating an A* pathfinding algorithm with HEAP(optimizing) where I've created an interface called IHeapItem. When I try to use it with my "Node" Class it throws an compile error: "`Node' does not implement interface member `IHeapItem.HeapIndex.get'"
Do you guys know how I can solve this error?
Node Class
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Node : IHeapItem<Node>{ //Error here
public bool walkable;
public Vector3 worldPosition;
public int gridX;
public int gridY;
public int gCost;
public int hCost;
private int heapIndex;
public Node parent;
public int fCost
{
get { return gCost + hCost; }
}
public int Heapindex
{
get
{
return heapIndex;
}
set
{
heapIndex = value;
}
}
public Node(bool _walkable, Vector3 _worldPos, int _gridX, int _gridY )
{
walkable = _walkable;
worldPosition = _worldPos;
gridX = _gridX;
gridY = _gridY;
}
public int CompareTo(Node nodeToCompare)
{
int compare = fCost.CompareTo(nodeToCompare.fCost);
if (compare == 0)
{
compare = hCost.CompareTo(nodeToCompare.hCost);
}
return -compare;
}
}
HEAP Class:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Heap<T> where T : IHeapItem<T>{
T[] items;
int currentItemCount;
public Heap(int maxHeapSize)
{
items = new T[maxHeapSize];
}
public void Add(T item)
{
item.HeapIndex = currentItemCount;
items[currentItemCount] = item;
SortUp(item);
currentItemCount++;
}
public T RemoveFirst()
{
T firstItem = items[0];
currentItemCount--;
items[0] = items[currentItemCount];
items[0].HeapIndex = 0;
SortDown(items[0]);
return firstItem;
}
public void UpdateItem(T item)
{
SortUp(item);
}
public int Count
{
get
{
return currentItemCount;
}
}
public bool Contains(T item)
{
return Equals(items[item.HeapIndex], item);
}
private void SortDown(T item)
{
while (true)
{
int childIndexLeft = item.HeapIndex * 2 + 1;
int childIndexRight = item.HeapIndex * 2 + 2;
int swapIndex = 0;
if (childIndexLeft < currentItemCount)
{
swapIndex = childIndexLeft;
if (childIndexRight < currentItemCount)
{
if (items[childIndexLeft].CompareTo(items[childIndexRight]) < 0)
{
swapIndex = childIndexRight;
}
}
if (item.CompareTo(items[swapIndex]) < 0)
{
Swap(item, items[swapIndex]);
}
else
{
return;
}
}
else
{
return;
}
}
}
private void SortUp(T item)
{
int parentIndex = (item.HeapIndex - 1) / 2;
while (true)
{
T parentItem = items[parentIndex];
if (item.CompareTo(parentItem) > 0)
{
Swap(item, parentItem);
}
else
{
break;
}
parentIndex = (item.HeapIndex - 1) / 2;
}
}
private void Swap(T itemA, T itemB)
{
items[itemA.HeapIndex] = itemB;
items[itemB.HeapIndex] = itemA;
int itemAIndex = itemA.HeapIndex;
itemA.HeapIndex = itemB.HeapIndex;
itemB.HeapIndex = itemAIndex;
}
}
public interface IHeapItem<T> : IComparable<T>
{
int HeapIndex
{
get;
set;
}
}
Comment
Your answer
Follow this Question
Related Questions
Start function dont work 1 Answer
OnPostprocessBuild and Unity Cloud 0 Answers
How to get input of VR head movement??!! 1 Answer
Fade out / fade in scene w/ loading screen 0 Answers
error CS0201 1 Answer