Link to home
Start Free TrialLog in
Avatar of HPFE455
HPFE455Flag for United States of America

asked on

C++ to C# code conversion issue

I am trying to convert the following C++ code into C#.

I found the following C++ code KnightSequences

typedef enum          { _A,_B,_C,_D,_E,_F,_G,_H,_I,_J,_K,_L,_M,_N,_O,_1,_2,_3 } TKeyIdentity;
typedef std::vector<TKeyIdentity const>     TKeyPath;
typedef std::vector<TKeyPath const>         TKeyMap;

const TKeyPath keyPadRoot =
{
    _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _1, _2, _3
}

const TKeyMap keyPad =
{
    { _H, _L },         // A
    { _I, _K, _M },     // B
    { _F, _J, _L, _N }, // C
    { _G, _M, _O },     // D
    { _H, _N },         // E    
    { _C, _M, _1 },     // F  (_1) not valid for 2 moves followed by 1 move rule
    { _D, _N, _2 },     // G
    { _A, _E, _K, _O, _1, _3 }, // H
    { _B, _L, _2 },     // I
    { _C, _M, _3 },     // J  (_3) not valid for 2 moves followed by 1 move rule
    { _B, _H, _2 },     // K
    { _A, _C, _I, _3 }, // L
    { _B, _D, _F, _J }, // M
    { _C, _E, _G, _1 }, // N
    { _D, _H, _2 },     // O (oh)
    { _F, _H, _N },     // 1
    { _G, _I, _K, _O }, // 2 (_K) & (_O) not valid for 2 moves followed be 1 move rule
    { _H, _J, _L }      // 3
};
TraverseKeyPaths( TKeyPath const &keyPath, int pressesRemaining, int vowelsAllowed )
{
 foreach (TKeyIdentity pressedKey in Enum.GetValues(typeof(TKeyIdentity)))
  {
	int value =  TraverseKeyPaths( keyPad[ pressedKey ],pressesRemaining, vowelsAllowed - isVowel[pressedKey] );
  }

}

Open in new window


My C# code:

  enum TKeyIdentity { _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _1, _2, _3 };
  List<string> keyPadRoot = new List<string> { "_A", "_B", "_C", "_D", "_E", "_F", "_G", "_H", "_I", "_J", "_K", "_L", "_M", "_N", "_O", "_1", "_2", "_3" };

  string[] A = new string[] { "_H", "_L" }; //A
  string[] B = new string[] { "_I", "_K", "_M" }; //B
  .
  .
  .
  etc

 List<string> keyPadMoves = new List<string>(););

 keyPadMoves.AddRange(A);
 keyPadMoves.AddRange(B);
 .
 .
 .
etc

int TraverseKeyPaths(List<string> keyPadRoot, int pressesRemaining, int vowelsAllowed)
{
 	foreach (TKeyIdentity pressedKey in Enum.GetValues(typeof(TKeyIdentity)))
	{
		int value =  value = TraverseKeyPaths(keyPadRoot, pressesRemaining, vowels);
	}
}

Open in new window


The following C# code is not working like C++ code.
int value =   TraverseKeyPaths(keyPadRoot, pressesRemaining, vowels);

Please let me know how to pass the correct argument.
Thanks for your help.
Avatar of phoffric
phoffric

I don't see what error or runtime problem you have.
I recommend that you post (or edit your OP) showing t a tiny program that can be built and run. If you cannot compile, then indicate the line and error message. If you are able to build it, but get the wrong answer, then indicate what you got and what you expect (and maybe even why you expect it).
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You probably should delete the question if there was no response from the Author.

The question was about porting of code from C++ to C#, but unfortunately the C++ code given is not valid (doesn't compile). That's why I posted code which solved the issue for C++ but is not a solution for C#.

In my opinion it makes little sense to go on without the participation of the Author.

Sara
Avatar of HPFE455

ASKER

your comments helped to resolve the issue