All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Games
Non-Attacking Chess Pieces II (Posted on 2010-08-23) Difficulty: 2 of 5
Arrange all sixteen white pieces and the black king on a standard 8x8 chessboard such that no piece is in check by another piece. The arrangement must be possible to reach following rules of standard play (though such play would be ludicrous), with no pawn having reached the eighth row for promotion.

See The Solution Submitted by Dej Mar    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution a computer solution | Comment 3 of 7 |

DECLARE SUB place (ptr!)
CLEAR , , 25000
DIM SHARED bd(8, 8), attacked(8, 8), pcs$, rook1row, b1par, prevp

pcs$ = "qrrbbnnkpppppppp"

CLS
place 1
END

SUB place (ptr)
   FOR r0 = 1 TO 8
   SELECT CASE r0
     CASE 1
      row = 8
     CASE 2
      row = 7
     CASE 3
      row = 6
     CASE 4
      row = 5
     CASE 5
      row = 4
     CASE 6
      row = 3
     CASE 7
      row = 2
     CASE 8
      row = 1
   END SELECT
   FOR col = 1 TO 8
     IF attacked(row, col) = 0 AND bd(row, col) = 0 THEN
       p$ = MID$(pcs$, ptr, 1)
       good = 1
       SELECT CASE p$
         CASE "q"
          FOR r = 1 TO 8
            c = col - (row - r)
            IF c > 0 AND c < 9 THEN IF bd(r, c) > 0 THEN good = 0: EXIT FOR
            c = col + (row - r)
            IF c > 0 AND c < 9 THEN IF bd(r, c) > 0 THEN good = 0: EXIT FOR
            IF bd(r, col) > 0 THEN good = 0: EXIT FOR
            IF bd(row, r) > 0 THEN good = 0: EXIT FOR
          NEXT r
          IF good THEN
            FOR r = 1 TO 8
              c = col - (row - r)
              IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) + 1
              c = col + (row - r)
              IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) + 1
              attacked(r, col) = attacked(r, col) + 1
              attacked(row, r) = attacked(row, r) + 1
            NEXT r
            bd(row, col) = ptr
            place ptr + 1
            bd(row, col) = 0
            FOR r = 1 TO 8
              c = col - (row - r)
              IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) - 1
              c = col + (row - r)
              IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) - 1
              attacked(r, col) = attacked(r, col) - 1
              attacked(row, r) = attacked(row, r) - 1
            NEXT r
          END IF
         CASE "r"
          IF row > rook1row THEN
            FOR r = 1 TO 8
              IF bd(r, col) > 0 THEN good = 0: EXIT FOR
              IF bd(row, r) > 0 THEN good = 0: EXIT FOR
            NEXT r
            IF good THEN
              FOR r = 1 TO 8
                attacked(r, col) = attacked(r, col) + 1
                attacked(row, r) = attacked(row, r) + 1
              NEXT r
              bd(row, col) = ptr
              rook1row = rook1row + row
              place ptr + 1
              rook1row = rook1row - row
              bd(row, col) = 0
              FOR r = 1 TO 8
                attacked(r, col) = attacked(r, col) - 1
                attacked(row, r) = attacked(row, r) - 1
              NEXT r
            END IF
          END IF
         CASE "b"
          IF b1par > 0 AND (b1par + row + col) MOD 2 = 0 THEN good = 0
          IF good THEN
            FOR r = 1 TO 8
              c = col - (row - r)
              IF c > 0 AND c < 9 THEN IF bd(r, c) > 0 THEN good = 0: EXIT FOR
              c = col + (row - r)
              IF c > 0 AND c < 9 THEN IF bd(r, c) > 0 THEN good = 0: EXIT FOR
            NEXT r
            IF good THEN
              FOR r = 1 TO 8
                c = col - (row - r)
                IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) + 1
                c = col + (row - r)
                IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) + 1
              NEXT r
              bd(row, col) = ptr
              b1par = b1par + row + col
              place ptr + 1
              b1par = b1par - row - col
              bd(row, col) = 0
              FOR r = 1 TO 8
                c = col - (row - r)
                IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) - 1
                c = col + (row - r)
                IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) - 1
              NEXT r
            END IF
          END IF
         CASE "n"
          FOR r = row - 2 TO row + 2
            IF r > 0 AND r < 9 AND r <> row THEN
              cdiff = 3 - ABS(row - r)
              FOR c = col - cdiff TO col + cdiff STEP 2 * cdiff
               IF c > 0 AND c < 9 THEN IF bd(r, c) > 0 THEN good = 0: EXIT FOR
              NEXT
            END IF
            IF good = 0 THEN EXIT FOR
          NEXT
          IF good THEN
            FOR r = row - 2 TO row + 2
              IF r > 0 AND r < 9 AND r <> row THEN
                cdiff = 3 - ABS(row - r)
                FOR c = col - cdiff TO col + cdiff STEP 2 * cdiff
                 IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) + 1
                NEXT
              END IF
            NEXT
            bd(row, col) = ptr
            place ptr + 1
            bd(row, col) = 0
            FOR r = row - 2 TO row + 2
              IF r > 0 AND r < 9 AND r <> row THEN
                cdiff = 3 - ABS(row - r)
                FOR c = col - cdiff TO col + cdiff STEP 2 * cdiff
                 IF c > 0 AND c < 9 THEN attacked(r, c) = attacked(r, c) - 1
                NEXT
              END IF
            NEXT
          END IF
         CASE "k"
          FOR r = row - 1 TO row + 1
          IF r > 0 AND r < 9 THEN
          FOR c = col - 1 TO col + 1
          IF c > 0 AND c < 9 THEN
            IF bd(r, c) > 0 THEN good = 0: EXIT FOR
          END IF
          NEXT
          IF good = 0 THEN EXIT FOR
          END IF
          NEXT
          IF good THEN
            FOR r = row - 1 TO row + 1
            IF r > 0 AND r < 9 THEN
            FOR c = col - 1 TO col + 1
            IF c > 0 AND c < 9 THEN
              IF r <> row OR c <> col THEN attacked(r, c) = attacked(r, c) + 1
            END IF
            NEXT
            END IF
            NEXT

            bd(row, col) = ptr
            place ptr + 1
            bd(row, col) = 0

            FOR r = row - 1 TO row + 1
            IF r > 0 AND r < 9 THEN
            FOR c = col - 1 TO col + 1
            IF c > 0 AND c < 9 THEN
              IF r <> row OR c <> col THEN attacked(r, c) = attacked(r, c) - 1
            END IF
            NEXT
            END IF
            NEXT
          END IF
         CASE "p"
          IF prevp > 0 THEN IF row * 8 + col < prevp THEN good = 0
          IF good THEN
            IF row > 1 AND row < 8 THEN
              IF col - 1 > 0 THEN IF bd(row - 1, col - 1) > 0 THEN good = 0
              IF col + 1 < 9 THEN IF bd(row - 1, col + 1) > 0 THEN good = 0
              IF good THEN
               IF col - 1 > 0 THEN attacked(row - 1, col - 1) = attacked(row - 1, col - 1) + 1
               IF col + 1 < 9 THEN attacked(row - 1, col + 1) = attacked(row - 1, col + 1) + 1

               bd(row, col) = ptr
               IF ptr < 16 THEN
                 place ptr + 1
               ELSE
                 good = 0
                 FOR r = 1 TO 8
                 FOR c = 1 TO 8
                   IF bd(r, c) = 0 THEN
                     IF attacked(r, c) = 0 THEN
                      good = 1
                      FOR rchk = r - 1 TO r + 1
                      FOR cchk = c - 1 TO c + 1
                       IF rchk > 0 AND rchk < 9 AND cchk > 0 AND cchk < 9 THEN
                         IF bd(rchk, cchk) > 0 THEN good = 0: EXIT FOR
                       END IF
                      NEXT: IF good = 0 THEN EXIT FOR
                      NEXT
                     END IF
                   END IF
                   IF good THEN EXIT FOR
                 NEXT: IF good THEN EXIT FOR
                 NEXT
                 IF good THEN
                   prevpSave = prevp
                   prevp = 8 * row + col
                   PRINT
                   FOR r = 1 TO 8
                   FOR c = 1 TO 8
                     IF bd(r, c) = 0 THEN
                       IF attacked(r, c) = 0 THEN
                        PRINT "* ";
                       ELSE
                        PRINT ". ";
                       END IF
                     ELSE
                       PRINT MID$(pcs$, bd(r, c), 1); " ";
                     END IF
                   NEXT: PRINT
                   NEXT
                   prevp = prevpSave
                 END IF
               END IF
               bd(row, col) = 0

               IF col - 1 > 0 THEN attacked(row - 1, col - 1) = attacked(row - 1, col - 1) - 1
               IF col + 1 < 9 THEN attacked(row - 1, col + 1) = attacked(row - 1, col + 1) - 1
              END IF
            END IF
          END IF
       END SELECT
     END IF
   NEXT
   NEXT
END SUB

 

finds:


. n . * . . k .
. p . . . . . .
. n . p p . p b
. b . . . . . .
. p . . p . p p
. . . . . r . .
. . r . . . . .
q . . . . . . .

where the * refers to the black king. The letters refer to the white pieces.

Other solutions may exist, but the program was stopped here.

In fact, cycling the rightmost file to become the leftmost results in another solution:


 . . n . * . . k
 . . p . . . . .
 b . n . p p . p
 . . b . . . . .
 p . p . . p . p
 . . . . . . r .
 . . . r . . . .
 . q . . . . . .


 
 but this can't be continued as then one of the bishops would be attacking the white king.  And it can't be done with ranks as then either a pawn would be in promotion position or the queen would be attacking a knight.
 
 Of course either solution could be reflected.


  Posted by Charlie on 2010-08-23 21:01:20
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information