2016-12-16 8 views
-2

私は現在、vb.netでエニグママシンを再現しようとしています。 私はローターのカスタムクラスを作成しようとしています。VB.NET配列のカスタムクラスリスト

ローターには、それが通過したシフトの数をカウントする整数Shiftが含まれていなければなりません。これは、26に達すると他のローターがシフトします。

また、各ロータの構成の26個のプラグ 例が含まれている26行のリストや配列:私はこれを試してみましたが、非常にうまく動作するように見えるdoes notの今の

18 16 0 11 23 4 9 19 8 1 17 13 2 24 22 6 15 21 12 7 14 20 5 10 25 3 
19 13 9 0 2 17 12 24 4 14 15 8 7 5 21 18 1 6 25 23 20 3 11 22 10 16 
18 13 23 5 6 16 2 25 11 1 20 17 4 10 14 0 19 3 8 15 22 9 12 21 7 24 
25 10 17 21 3 12 16 4 19 20 6 9 8 13 7 18 1 15 14 2 23 22 11 5 24 0 
18 23 7 12 17 24 25 5 20 8 0 15 14 21 1 3 9 13 22 19 2 4 10 6 11 16 
7 23 0 24 3 25 10 2 15 19 16 14 17 9 11 13 5 20 8 1 21 6 18 12 22 4 
11 12 7 14 24 0 19 2 10 8 22 17 4 15 5 13 3 16 21 6 9 25 18 1 20 23 
11 5 14 7 12 6 15 25 20 23 18 21 9 19 17 8 4 1 22 2 16 10 0 13 3 24 
7 19 10 25 15 13 12 14 4 8 21 17 0 22 11 24 18 2 9 1 20 5 3 16 23 6 
19 23 1 21 0 15 10 2 7 4 22 12 14 9 17 20 11 8 18 13 5 6 16 3 25 24 
19 13 14 12 6 23 18 7 9 17 22 8 15 1 24 5 10 20 16 11 2 21 0 3 25 4 
4 1 5 3 10 13 24 25 21 18 16 6 20 11 17 19 7 14 0 23 9 15 2 12 22 8 
19 18 22 10 17 6 20 13 2 12 14 15 24 1 11 9 8 3 5 4 7 25 0 16 21 23 
16 13 14 1 8 11 9 25 24 3 2 4 0 5 22 18 19 7 17 15 23 20 6 10 12 21 
2 15 20 0 16 17 1 24 8 23 14 21 3 4 11 19 9 5 6 22 7 12 18 25 10 13 
22 10 17 9 4 20 24 2 13 25 8 21 23 0 19 7 11 5 15 1 16 3 14 12 6 18 
5 14 0 10 21 9 3 25 13 1 4 18 8 17 22 2 20 24 15 19 23 16 7 11 12 6 
15 1 13 2 19 7 9 16 11 10 17 14 4 25 6 24 0 23 22 21 8 20 5 12 18 3 
12 8 20 6 11 3 10 23 21 14 13 7 0 22 19 4 16 2 5 15 9 17 1 18 24 25 
4 8 25 5 1 12 10 22 9 24 14 19 2 0 6 20 17 3 23 15 13 11 21 16 18 7 
11 21 5 6 16 19 13 20 23 10 18 14 3 8 15 24 0 25 4 22 12 7 1 17 2 9 
5 24 19 23 17 18 0 11 2 20 14 1 25 22 9 6 15 7 10 13 8 12 16 3 4 21 
1 11 8 13 3 22 14 19 4 6 5 15 24 9 21 23 7 0 2 12 25 10 16 17 20 18 
18 3 19 16 10 24 23 1 22 17 20 9 7 14 2 21 5 8 0 11 13 4 15 25 12 6 
5 11 7 0 8 2 13 17 23 16 9 10 20 12 19 3 25 24 18 21 14 22 15 6 4 1 
10 2 3 22 16 6 15 19 1 20 18 24 13 5 8 23 21 7 14 17 9 11 25 12 4 0 

Public Class Rotor 

    Public Property lines As New List(Of Liner)() 
    Public Property shift As Integer 
    Public Structure Liner 
     Public Property plug() As Integer() 
    End Structure 
End Class 

そして、私のコンフィギュレーション・ローダー:

Public Sub ConfigRotor(ByVal RotorConf As Rotor, ByVal PathConf As String) 
    Dim i As Integer = 0 
    For Each line As String In File.ReadAllLines(PathConf) 
     Dim y As Integer = 0 
     For Each strr As String In line.Split(" ") 
      RotorConf.lines(i).plug(y) 
      y = y+1 
     Next 

     i = i + 1 
     If i > 26 Then 
      MsgBox("Configuration file not supported") 
     End If 
    Next 
End Sub 

あなたはこれを簡単に処理するために私を参照できるより最適化された方法をご覧いただけますか?

+1

これはCodeReviewにより適していますか? –

+0

"y = +1"?常に1の中に1を入れます。私はあなたの配列をどのように初期化するのかわかりません... "doesntはうまくいくようです"と言っても、あまり明確ではありません。何がうまくいかない? –

+0

@the_lotus申し訳ありません誤植誤って修正しました –

答えて

1

まず、あなたのクラスを宣言する正しい方法は、このようなものです:

将来refferenceため、誰もが興味を持っているならば、私は二つの構造を宣言しました
Public Class Rotor 

    Public Property lines As New List(Of Liner) 
    Public Property shift As Integer 
    Public Structure Liner 
     Public Property plug As Integer() 
    End Structure 
End Class 

有効なコードを取得するには、ファイルの種類をテキストからバイナリに変更することをお勧めします。バイト配列を読み込んで操作し、文字列配列でできることよりもint配列に変換する方が簡単で簡単です。

あなたのファイルはバイナリであり、必要なバイト数(26 x 26 = 676バイト)で保存されているものとします。コードは次のようになります。

Public Sub ConfigRotor(ByVal RotorConf As Rotor, ByVal PathConf As String) 
    Dim myArray() As Byte = File.ReadAllBytes(PathConf) 

    If (myArray.Length <> 676) Then 
     MsgBox("Configuration file not supported") 
    Else 
     RotorConf.lines.Clear() 
     For pos As Integer = 0 To myArray.Length - 1 Step 26 
      Dim line As New Rotor.Liner 
      Dim newPlug(25) As Integer 
      line.plug = newPlug 
      Array.Copy(myArray, pos, line.plug, 0, 26) 
      RotorConf.lines.Add(line) 
     Next 
    End If 
End Sub 

簡単で高速でクリーンです。 このコードを実行する合計時間は1ms未満です(ardドライブの速度によって異なります)。

0

誰も役に立たなかったので、私は本当に醜い何かをしましたが、うまくいきます。私はこのようなアプリの起動時にはReDimを使用すると

Public Structure rotori 
    Dim lines() As liner 
    Public shift As Integer 
End Structure 

Public Structure liner 
    Public plugs() As Integer 
End Structure 

Dim Rotor1 As New rotori 
ReDim Rotor1.lines(25) 
For b As Integer = 0 To 25 
    ReDim Rotor1.lines(b).plugs(25) 
Next