Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wannasaynone/54d0be8c92635e530d83700e85c1383c to your computer and use it in GitHub Desktop.
Save wannasaynone/54d0be8c92635e530d83700e85c1383c to your computer and use it in GitHub Desktop.
public List<Coordinate> FindLine()
{
Coordinate _current = new Coordinate(0, 0);
List<Coordinate> _path = new List<Coordinate>() { _current };
while(true)
{
bool _added = false;
if (m_board[_path[0].x, _path[0].y] != -1)
{
for (int i = 0; i < _path.Count; i++)
{
if (_path[i].x + 1 < m_board.GetLength(0)
&& !_path.Contains(new Coordinate(_path[i].x + 1, _path[i].y))
&& m_board[_path[i].x, _path[i].y] == m_board[_path[i].x + 1, _path[i].y])
{
_path.Add(new Coordinate(_path[i].x + 1, _path[i].y));
_added = true;
break;
}
if (_path[i].y + 1 < m_board.GetLength(1)
&& !_path.Contains(new Coordinate(_path[i].x, _path[i].y + 1))
&& m_board[_path[i].x, _path[i].y] == m_board[_path[i].x, _path[i].y + 1])
{
_path.Add(new Coordinate(_path[i].x, _path[i].y + 1));
_added = true;
break;
}
if (_path[i].x - 1 >= 0
&& !_path.Contains(new Coordinate(_path[i].x - 1, _path[i].y))
&& m_board[_path[i].x, _path[i].y] == m_board[_path[i].x - 1, _path[i].y])
{
_path.Add(new Coordinate(_path[i].x - 1, _path[i].y));
_added = true;
break;
}
if (_path[i].y - 1 >= 0
&& !_path.Contains(new Coordinate(_path[i].x, _path[i].y - 1))
&& m_board[_path[i].x, _path[i].y] == m_board[_path[i].x, _path[i].y - 1])
{
_path.Add(new Coordinate(_path[i].x, _path[i].y - 1));
_added = true;
break;
}
}
}
if (_added)
{
continue;
}
if (_path.Count >= m_initBoardData.minLineNeededCount)
{
break;
}
_path.Clear();
Coordinate _next = new Coordinate(_current.x + 1, _current.y);
if (_next.x >= m_board.GetLength(0))
{
_next.x = 0;
_next.y++;
if (_next.y >= m_board.GetLength(1))
{
break;
}
}
_current = _next;
_path.Add(_next);
}
return _path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment