$crystal = 6000000 $regfile = "M16def.dat" Ddrd = &B00011101 Portb = &B11100110 Dim Value As Integer Dim Seed As Integer Declare Function Random(byval Z As Integer) As Integer Seed = 1234 Dim R1 As Byte Dim R2 As Byte Dim R3 As Byte Dim R4 As Byte Dim Hoelzer1 As Byte Dim Hoelzer2 As Byte Dim Hoelzer3 As Byte Dim Hoelzer4 As Byte Dim Nim_sum As Byte Dim Win_check_r1 As Byte Dim Win_check_r2 As Byte Dim Win_check_r3 As Byte Dim Win_check_r4 As Byte Declare Sub Gewinnzug Declare Sub Auswertung Declare Sub Verlierzug Declare Sub Led_anzeige Dim Zufall_reihe As Byte '----- Hauptprogramm ----- Do Loop End '----- Ende ----- Sub Auswertung Nim_sum = R1 Xor R2 Nim_sum = Nim_sum Xor R3 Nim_sum = Nim_sum Xor R4 Win_check_r1 = R1 Xor Nim_sum Win_check_r2 = R2 Xor Nim_sum Win_check_r3 = R3 Xor Nim_sum Win_check_r4 = R4 Xor Nim_sum End Sub Sub Gewinnzug If Win_check_r4 < R4 Then Hoelzer4 = R4 Xor Nim_sum R4 = Hoelzer4 Exit Sub End If If Win_check_r2 < R2 Then Hoelzer2 = R2 Xor Nim_sum R2 = Hoelzer2 Exit Sub End If If Win_check_r1 < R1 Then Hoelzer1 = R1 Xor Nim_sum R1 = Hoelzer1 Exit Sub End If If Win_check_r3 < R3 Then Hoelzer3 = R3 Xor Nim_sum R3 = Hoelzer3 Exit Sub Else Call Verlierzug End If End Sub Sub Verlierzug Local Value2 As Integer Value = Random(3) If Value = 0 Then If R1 = 0 Then Value = 1 If R1 = 1 Then R1 = 0 End If If Value = 1 Then Select Case R2 Case 0 : Value = 2 Case 1 : R2 = 0 Case 2 : Value2 = Random(1) Value2 = Value2 + 1 R2 = R2 - Value2 Case 3 : Value2 = Random(2) Value2 = Value2 + 1 R2 = R2 - Value2 End Select End If If Value = 2 Then Select Case R3 Case 0 : Value = 3 Case 1 : R3 = 0 Case 2 : Value2 = Random(1) Value2 = Value2 + 1 R3 = R3 - Value2 Case Else : Value2 = Random(2) Value2 = Value2 + 1 R3 = R3 - Value2 End Select End If If Value = 3 Then Select Case R4 Case 0 : Value = 4 Case 1 : R4 = 0 Case 2 : Value2 = Random(1) Value2 = Value2 + 1 R4 = R4 - Value2 Case Else : Value2 = Random(2) Value2 = Value2 + 1 R4 = R4 - Value2 End Select End If End Sub Sub Led_anzeige Select Case R1 Case &B0000 : Portc.0 = 1 Case &B0001 : Portc.0 = 0 End Select Select Case R2 Case &B0000 : Porta.5 = 1 Portc.7 = 1 Portc.1 = 1 Case &B0001 : Porta.5 = 1 Portc.7 = 0 Portc.1 = 1 Case &B0010 : Porta.5 = 1 Portc.7 = 0 Portc.1 = 0 Case &B0011 : Porta.5 = 0 Portc.7 = 0 Portc.1 = 0 End Select Select Case R3 Case &B0000 : Porta.2 = 1 Porta.4 = 1 Porta.7 = 1 Portc.5 = 1 Portc.2 = 1 Case &B0001 : Porta.2 = 1 Porta.4 = 1 Porta.7 = 0 Portc.5 = 1 Portc.2 = 1 Case &B0010 : Porta.2 = 1 Porta.4 = 0 Porta.7 = 1 Portc.5 = 0 Portc.2 = 1 Case &B0011 : Porta.2 = 1 Porta.4 = 0 Porta.7 = 0 Portc.5 = 0 Portc.2 = 1 Case &B0100 : Porta.2 = 1 Porta.4 = 0 Porta.7 = 0 Portc.5 = 0 Portc.2 = 0 Case &B0101 : Porta.2 = 0 Porta.4 = 0 Porta.7 = 0 Portc.5 = 0 Portc.2 = 0 End Select Select Case R4 Case &B0000 : Porta.0 = 1 Porta.1 = 1 Porta.3 = 1 Porta.6 = 1 Portc.6 = 1 Portc.4 = 1 Portc.3 = 1 Case &B0001 : Porta.0 = 1 Porta.1 = 1 Porta.3 = 1 Porta.6 = 0 Portc.6 = 1 Portc.4 = 1 portc.3 = 1 Case &B0010 : Porta.0 = 1 Porta.1 = 1 Porta.3 = 0 Porta.6 = 1 Portc.6 = 0 Portc.4 = 1 portc.3 = 1 Case &B0011 : Porta.0 = 1 Porta.1 = 1 Porta.3 = 0 Porta.6 = 0 Portc.6 = 0 Portc.4 = 1 portc.3 = 1 Case &B0100 : Porta.0 = 1 Porta.1 = 1 Porta.3 = 1 Porta.6 = 0 Portc.6 = 0 Portc.4 = 0 Portc.3 = 0 Case &B0101 : Porta.0 = 1 Porta.1 = 0 Porta.3 = 0 Porta.6 = 0 Portc.6 = 0 Portc.4 = 0 portc.3 = 1 Case &B0110 : Porta.0 = 1 Porta.1 = 0 Porta.3 = 0 Porta.6 = 0 Portc.6 = 0 Portc.4 = 0 Portc.3 = 0 Case &B0111 : Porta.0 = 0 Porta.1 = 0 Porta.3 = 0 Porta.6 = 0 Portc.6 = 0 Portc.4 = 0 Portc.3 = 0 End Select End Sub Function Random(byval Z As Integer) As Integer Local X As Integer Local Y As Integer X = Seed * 259 X = X + 3 Seed = X And &H7FFF Y = Y + 1 Random = Y End Function