tôi có mã như thế này trong C#:Chuyển đổi C# struct để F #
namespace WumpusWorld
{
class PlayerAI
{
//struct that simulates a cell in the AI replication of World Grid
struct cellCharacteristics
{
public int pitPercentage;
public int wumpusPercentage;
public bool isPit;
public bool neighborsMarked;
public int numTimesvisited;
}
private cellCharacteristics[,] AIGrid; //array that simulates World Grid for the AI
private enum Move { Up, Down, Right, Left, Enter, Escape }; //enum that represents integers that trigger movement in WumpusWorldForm class
Stack<int> returnPath; //keeps track of each move of AI to trace its path back
bool returntoBeg; //flag that is triggered when AI finds gold
int numRandomMoves; //keeps track of the number of random moves that are done
public PlayerAI()
{
AIGrid = new cellCharacteristics[5, 5];
cellCharacteristics c;
returntoBeg = false;
returnPath = new Stack<int>();
numRandomMoves = 0;
for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 5; x++)
{
c = new cellCharacteristics();
c.isPit = false;
c.neighborsMarked = false;
c.numTimesvisited = 0;
AIGrid[x, y] = c;
}
}
}
}
}
Tôi không biết làm thế nào để chuyển đổi này C# struct để F # và thực hiện các struct
vào một mảng như mã của tôi ở trên.
Tại sao bạn không sử dụng cấu trúc C# đó từ F #? Chính xác những gì bạn có vấn đề với? Bạn đã thử cái gì? BTW, cấu trúc có thể biến đổi là điều ác và bạn không nên sử dụng chúng trừ khi thực sự cần thiết. – svick
nó chỉ là một số mảnh nhỏ từ mã của tôi, cấu trúc đó là bên trong một lớp, và lớp học có phương pháp sử dụng struct như Array. Tôi thử chuyển đổi lớp C# của tôi thành lớp F #. Tôi thêm mã vào mã ví dụ của tôi –