a* algortihm exercise improved
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;
namespace aStarAlgorithm
{
class GameExample
{
private int length = 12;
private int height = 8;
// remember that
private Cell startPoint = new Cell(2, 2);
private Cell endPoint = new Cell(6, 8);
private List<Cell> walls = new List<Cell>() { new Cell(4, 6), new Cell(3, 6), new Cell(4, 5), new Cell(4, 4), new Cell(2, 6) };
public enum Node { Wall, Path, Start, End }
private Node[,] gameBoard;
public void aStarPath()
{
// find the shortest path from node.Start to node.End
}
private int calculateDistanceFromEndPoint()
{
// complete this method - it will help you write the a* algorithm
return -1;
}
private int calculateDistanceFromStartPoint()
{
// complete this method - it will help you write the a* algorithm
return -1;
}
public GameExample()
{
// fill board with empty spaces
gameBoard = new Node[height, length];
for (int i = 0; i < height; i++)
{
for (int j = 0; j < length; j++)
{
gameBoard[i, j] = Node.Path;
}
}
// add walls
foreach (var wall in walls)
{
gameBoard[wall.x, wall.y] = Node.Wall;
}
// add start and end points
gameBoard[startPoint.x, startPoint.y] = Node.Start;
gameBoard[endPoint.x, endPoint.y] = Node.End;
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < height; i++)
{
for (int j = 0; j < length; j++)
{
if (gameBoard[i, j] == Node.Path) stringBuilder.Append((char)183);
if (gameBoard[i, j] == Node.Wall) stringBuilder.Append((char)219);
if (gameBoard[i, j] == Node.Start) stringBuilder.Append("S");
if (gameBoard[i, j] == Node.End) stringBuilder.Append("E");
}
stringBuilder.Append(Environment.NewLine);
}
return stringBuilder.ToString();
}
private class Point
{
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public int x { get; set; }
public int y { get; set; }
}
private class Cell
{
public Point point { get; set; }
//add other variables....
public int x
{
get { return point.x; }
set { point.x = value; }
}
public int y
{
get { return point.y; }
set { point.y = value; }
}
public Cell(int x, int y)
{
point = new Point(x, y);
//point.x = x;
//point.y = y;
}
}
}
}