Ho codice come questo in C#:Conversione C# struct a 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;
}
}
}
}
}
non so come convertire questo C# struct a F # e attuare la struct
in un array come il mio codice di cui sopra.
Perché non usi solo la struttura C# da F #? Con cosa hai esattamente problemi? Che cosa hai provato? A proposito, le strutture mutabili sono malvagie e non dovresti usarle a meno che non sia davvero necessario. – svick
è solo un piccolo pezzo del mio codice, che struct è all'interno di una classe, e la classe ha metodi che usano la struct come Array. Provo a convertire la mia classe C# in classe F #. Aggiungo altro codice nel mio codice di esempio –