编译错误导致此错误:
可访问性不一致:参数类型' TrianglePegSolver.Board' 比方法更难获得 ' TrianglePegSolver.Form1.DFS(TrianglePegSolver.Board)' C:\ Users \ pini \ Desktop \ COP3530 \ TrianglePegSolver \ TrianglePegSolver \ Form1.cs 85 37 TrianglePegSolver
试图按照其他线程的说明进行操作,但即使我将函数和类型设置为public,它仍然会给我带来问题。
在form1中指出问题的代码:
public void DFS(Board board)
{
以下是从中获取函数的类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrianglePegSolver {
class Board
{
public int n, sI, sJ, fI, fJ;
public string goal = "";
public bool[,] pegArray, parent;
public Board(Board copyBoard)
{
n = copyBoard.n;
fI = copyBoard.fI;
fJ = copyBoard.fJ;
goal = copyBoard.goal;
parent = copyBoard.pegArray;
pegArray = copyBoard.pegArray;
}
public Board(int size,int startI, int startJ, int finishI, int finishJ)
{
n = size;
sI = startI;
sJ = startJ;
fI = finishI;
fJ = finishJ;
pegArray = new bool[n, n];
parent = null;
goal = getGoal(pegArray);
setPegs(pegArray);
}
public void setPegs(bool[,] p)
{
int x = n;
for (int a = 0; a < n; a++)
{
for (int b = 0; b < x; b++)
{
p[a,b] = true;
}
x--;
}
p[sI,sJ] = false;
}
public string getGoal(bool[,] p)
{
int x = n;
String goal = "";
for(int a = 0; a < n; a++)
{
for(int b = 0; b < x; b++)
{
if (a == fI && b == fJ) goal += "1";
else if (p[a, b]) goal += "0";
else /* (p[a, b].hasPeg == 0)*/ goal += "1";
}
x--;
}
return goal;
}
public string getCurrent(bool[,] p)
{
int x = n;
String current = "";
for (int a = 0; a < n; a++)
{
for (int b = 0; b < x; b++)
{
if (p[a, b]) current += 1;
else current += 0;
}
x--;
}
return current;
}
public bool isSolution(bool[,] p)
{
return ((getCurrent(p) == goal));
}
public bool hasChild(int i, int j)
{
if ((i + j + 2) < n)
{
if ((pegArray[i, j + 1] == true && pegArray[i, j + 2] == false) ||
(pegArray[i + 1, j] == true && pegArray[i + 2, j] == false))
{
return true;
}
}
if ((i - 2) = 0)
{
if ((pegArray[i - 1, j + 1] == true && pegArray[i - 2, j + 2] == false) ||
(pegArray[i - 1, j] == true && pegArray[i - 2, j] == false))
{
return true;
}
}
if((j-2) = 0)
{
if ((pegArray[i, j - 1] == true && pegArray[i, j - 2] == false) ||
(pegArray[i + 1, j - 1] == true && pegArray[i + 2, j - 2] == false))
{
return true;
}
}
return false;
}
}
}
不确定问题出在哪里以及为什么我会遇到这个问题,但我在整个班级和主要部门进行了搜索,没有找到任何受保护的运气。
感谢任何建议。