Find Chess960 starting position identifier: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (→{{header|Raku}}: streamline, style) |
(→{{header|QBasic}}: Take advantage of mixed case, and add explicit output, since the code no longer matches the Commodore solution.) |
||
Line 178: | Line 178: | ||
{{works with|QBasic|1.1}} |
{{works with|QBasic|1.1}} |
||
{{trans|Commodore BASIC}} |
{{trans|Commodore BASIC}} |
||
<lang qbasic> |
<lang qbasic>Cls |
||
Print "Enter start array as seen by white." |
|||
120 |
120 Print |
||
Print "Starting array"; |
|||
Input Ar$ |
|||
Print |
|||
PRINT |
|||
If Len(Ar$) = 0 Then End |
|||
If Len(Ar$) = 8 Then 170 |
|||
Print "Array must be 8 pieces.": GoTo 120 |
|||
170 |
170 For I = 1 To 8 |
||
P$ = |
P$ = Mid$(Ar$, I, 1) |
||
If P$ = "Q" Or P$ = "q" Then Q(Q) = I: Q = Q + 1: GoTo 250 |
|||
If P$ = "K" Or P$ = "k" Then K(K) = I: K = K + 1: GoTo 250 |
|||
If P$ = "B" Or P$ = "b" Then B(B) = I: B = B + 1: GoTo 250 |
|||
If P$ = "N" Or P$ = "n" Then N(N) = I: N = N + 1: GoTo 250 |
|||
If P$ = "R" Or P$ = "r" Then R(R) = I: R = R + 1: GoTo 250 |
|||
Print "Illegal piece '"; P$; "'.": GoTo 120 |
|||
250 |
250 Next I |
||
If K <> 1 Then Print "There must be exactly one King.": GoTo 120 |
|||
If Q <> 1 Then Print "There must be exactly one Queen.": GoTo 120 |
|||
If B <> 2 Then Print "There must be exactly two Bishops.": GoTo 120 |
|||
If N <> 2 Then Print "There must be exactly two Knights.": GoTo 120 |
|||
If R <> 2 Then Print "There must be exactly two Rooks.": GoTo 120 |
|||
If (K(0) > R(0)) And (K(0) < R(1)) Then 330 |
|||
Print "King must be between the Rooks.": GoTo 120 |
|||
330 |
330 If (B(0) And 1) <> (B(1) And 1) Then 350 |
||
Print "Bishops must be on opposite colors.": GoTo 120 |
|||
350 |
350 For I = 0 To 1 |
||
N = N(I) |
N = N(I) |
||
If N(I) > Q(I) Then N = N - 1 |
|||
For J = 0 To 1 |
|||
If N(I) > B(J) Then N = N - 1 |
|||
Next J |
|||
NEXT J |
|||
N(I) = N |
N(I) = N |
||
Next I |
|||
N0 = 1: N1 = 2 |
N0 = 1: N1 = 2 |
||
For N = 0 To 9 |
|||
If N0 = N(0) And N1 = N(1) Then 490 |
|||
N1 = N1 + 1 |
N1 = N1 + 1 |
||
If N1 > 5 Then N0 = N0 + 1: N1 = N0 + 1 |
|||
Next N |
|||
490 Q = Q(0) - 1 |
490 Q = Q(0) - 1 |
||
For I = 0 To 1 |
|||
If Q(0) > B(I) Then Q = Q - 1 |
|||
Next I |
|||
For I = 0 To 1 |
|||
B = B(I) - 1 |
B = B(I) - 1 |
||
If B And 1 Then L = Int(B / 2) |
|||
If (B And 1) = 0 Then D = B / 2 |
|||
Next I |
|||
Print "SP-ID ="; 96 * N + 16 * Q + 4 * D + L |
|||
End |
|||
⚫ | |||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>Enter start array as seen by White. |
|||
<pre> |
|||
Igual que la entrada de Commodore BASIC. |
|||
Starting array? qnrbbnkr |
|||
SP-ID = 105 |
|||
Starting array? RNBQKBNR |
|||
SP-ID = 518 |
|||
Starting array? RQNBBKRN |
|||
SP-ID = 601 |
|||
Starting array? RNQBBKRN |
|||
SP-ID = 617 |
|||
</pre> |
</pre> |
||