Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tanmim Hanifa
GameAICW2
Commits
29556fbb
Commit
29556fbb
authored
Nov 17, 2017
by
Tanmim Hanifa
Browse files
implemented method to return neighbours of node a, though not entirely working currently
parent
664f364a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Pathfind.exe
View file @
29556fbb
No preview for this file type
YellowGraph.cs
View file @
29556fbb
...
...
@@ -24,9 +24,15 @@ class YellowGraph : Graph {
}
public
void
AddEdge
(
Node
a
,
Node
b
,
int
c
)
{
adjMatrix
[
a
.
Id
,
b
.
Id
]
=
c
;
//adds cost between two nodes in the adjacency matrix to imply of a corresponding edge between the two nodes
}
if
(
a
.
Id
>=
adjMatrix
.
GetLength
(
0
)
||
b
.
Id
>=
adjMatrix
.
GetLength
(
1
))
{
Console
.
WriteLine
(
"Matrix out of bounds"
);
//ensure we don't exceed the size of the matrix
}
else
if
(
c
>=
0
)
{
//Only add cost to adjMatrix if cost is postive
adjMatrix
[
a
.
Id
,
b
.
Id
]
=
c
;
//adds cost between two nodes in the adjacency matrix to imply of a corresponding edge between the two nodes
}
}
public
List
<
Node
>
Nodes
()
{
return
nodes
;
//returns all the nodes
...
...
@@ -34,6 +40,12 @@ class YellowGraph : Graph {
public
List
<
Node
>
Neighbours
(
Node
a
)
{
List
<
Node
>
neighbours
=
new
List
<
Node
>();
//creates a list nodes
for
(
int
i
=
0
;
i
<
adjMatrix
.
GetLength
(
1
);
i
++){
//look for neighbours of node in the matrix
if
(
adjMatrix
[
a
.
Id
,
i
]
!=
0
)
//if we find a cost that is not 0, it means there is an edge between the nodes
neighbours
.
Add
(
a
.
Id
(
i
));
//get node and add it to the list
}
return
neighbours
;
//returns all the neighbours
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment