我有這樣的代碼在C#:轉換C#結構,以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;
}
}
}
}
}
我不知道如何將這種C#結構,以F#轉換和實施struct
到像我上面的代碼中的數組。
爲什麼你不使用F#中的C#結構?你到底有什麼問題?你有什麼嘗試?順便說一下,可變結構是邪惡的,除非真的必要,否則你不應該使用它們。 – svick
它只是我的代碼中的一小塊,該結構在一個類中,並且該類具有使用struct作爲Array的方法。我嘗試將我的C#類轉換爲F#類。我在示例代碼中添加了更多代碼 –