Stone Maze Chess solver

3

0

Background:

Every war eventually comes to an end, but the end is never absolute. The Stone Maze Chess scenario takes place after a game of chess is finished. The enemy King is dead and the pieces is lost in vacuity almost out of faith, multiplying. The winning side has moved on except for the Hero who is left behind with one mission still to go.

Objective:

Your mission is to guide your hero to put a stone on the enemy Kings grave to prevent the ghost of the King from haunting the land in eternity.

Visualization:

Board size and positions are notated just like a normal chess table, lines from A to H and ranks from 1 to 8. Visualized almost empty table:

    A B C D E F G H

8   . . . H . . . .  8
7   . . . o . . . .  7
6   . . . . . . . .  6
5   . . . . . . . .  5
4   . . . . . . . .  4
3   . . . . . . . .  3
2   . . . . . . . .  2
1   . . . X . . . .  1

    A B C D E F G H

Movement:

You move your Hero(H) one square every move: North(N), South(S), East(E) or West(W). You can push the Stone(o) in front of the Hero(H) if the path is free from board edges, stonewalls and chess pieces. If you move your Hero(H) into the reach of any enemy piece, it will immediately take the first chance to kill the hero, and the game is over. That, for example, means that you cannot move the hero adjacent to an enemy Queen() or Rook(R) unless there is a wall between the Hero(H) and the piece.

The kings grave(X) and any Trap(T) cannot be crossed by the Hero(H) or any piece except for the Knight(K) who can leap over it.

Push & pull:

All of the chess pieces can also be pushed one square just like the Stone(o), leaving a stonewall behind. Pieces, unlike the Stone(o), is also pulled if the Hero moves away from the piece.

Piece movement:

On top of that, if your Hero(H) stands adjacent (orthogonal [not diagonally]) to a chess piece the chess piece can be moved like a chess piece in standard chess. This applies only to Pawns(P), Knights(K) and Bishops(B) because your Hero(H) can't stand adjacent to a Rook(R) or a Queen(Q) without being attacked by the piece, unless there is a stonewall between. Pawns(P) can only move forward (north), but can be pushed or pulled in any of the four directions. Pawns(P) on the 2nd rank can move either 1 or 2 steps forward on the same move if the path is free. The other pieces can also move like they do in chess, but cannot move through any stonewall, except for the knight who can leap over stonewalls, traps(T), the Hero(H), the Stone(o) and other pieces. Bishops(B) and Queens(Q) can diagonally tangent a stonewall, but cannot cross two connected stonewalls, when moved or attacking the Hero(H).

Pawns(P) attack diagonally in the same way, only connected stonewalls prevent the attack. A single loose stonewall can't prevent a Pawn(P) from attacking diagonally.

Edit: This hopefully explains how diagonal movement works, X's represents possible destination positions for the Bishop(B):

    A B C D E F G H     A B C D E F G H

8   .|_|. . . _ . .  8  X . . . . . . .
7   . _ . . . .|. .  7  . X . . . X . .
6   . _|. . . . . .  6  . . X . X . . .
5   . . . B _ . . .  5  . . . B . . . .
4   . .|. . _ . _ .  4  . . X . X . . .
3   .|. . . _ _ _ .  3  . X . . . X . .
2   .|. . . . . . .  2  . . . . . . . .
1   . . . . . . . .  1  . . . . . . . .

    A B C D E F G H     A B C D E F G H

/Edit

Stonewalls:

From the start the board is free from stonewalls. Chess pieces without their King stands still so long that they turn into stone, so when pushed or pulled they will leave a line of stones between the square they come from and the square they are pushed or pulled onto, preventing everything except Knights(K) to pass through it. The stonewalls gradually creates a maze. If all sides of a square is filled with stonewalls, that square is again released from all surrounding stonewalls, the square is reset. The four corner squares is reset when both edges facing the board get stonewalls, edge squares is reset when all three sides has stonewalls. Free squares that is surrounded by other squares has four sides and is reset when all four sides is filled with stonewalls.

Trap:

If a piece is pushed or moved to a trap, it dies and is removed from the table. Pieces cannot cross over a trap, except for Knights(K). If the Hero(H) moves to a trap, it is game over.

Game state (input to your program):

Input is always 8 lines of 16 characters, each 2 bytes (one state and one blankspace) is representing one square on the board.

Valid input characters and their purpose:

. = Empty square
H = Hero start position.
X = The kings grave.
o = The stone.
T = A trap.
P = Pawn.
K = Knight.
B = Bishop.
R = Rook.
Q = Queen.

Example input:

. . . H . . . . 
. . . o . . . . 
. P . . . P . . 
. P . K . P . . 
. . . . . . . . 
. . . . . . . . 
. . . . . . . . 
. . . X . . . . 

In addition to the Hero(H), the Stone(o) and the Kings grave(X) we here have four Pawns(P) and one Knight(K) on the board setup.

How to solve the example puzzle: Here is a solution where we push two pieces creating only two single vertical stonewalls on the board. Not exactly a Maze, but will serve as an example.

  1. Push the stone one step south.
  2. Go around with the Hero far east, south to rank 2, west and up on line D adjacent to the knight at D5.
  3. Move the knight to B4.
  4. Move the knight to A6.
  5. Push the pawn at F5 one step east, and then move it one step north (this way we avoid end up adjacent to it and pull it south again).
  6. Move the pawn at F6 one step north.
  7. Move the Hero north and around the stone on east side.
  8. Push the stone south until the kings grave. Successful solution.

The above solution is intentionally a bit unneccessary complex, just to demonstrate how stonewalls appear. Stonewalls can appear horizontally also if pieces is pushed or pulled north or south.

Here is visualizations of some states of the example game solution:

1.  . . . H . . . .
    . . . o . . . .
    . P . . . P . .
    . P . K . P . .
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . . . X . . . .

2.  . . . . . . . .
    . . . . . . . .
    . P . o . P . .
    . P . K . P . .
    . . . H . . . .
    . . . . . . . .
    . . . . . . . .
    . . . X . . . .

7.  . . . . . . . .
    . . . . H P . .
    K P . o . . P .
    . P . . . .|. .
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . . . X . . . .

8.  . . . . . . . .
    . . . H P|. . .
    K P . o . . P .
    . P . . . .|. .
    . . . . . . . .
    . . . . . . . .
    . . . . . . . .
    . . . X . . . .

Control notation (output from your program):

Move the Hero(H) using 4 commands:

+N = Move 1 step north 
+S = Move 1 step south  
+E = Move 1 step east 
+W = Move 1 step west  

If you move the Hero(H) 1 step east and the Stone(o) or a chess piece is adjacent to the east then your Hero(H) will push the Stone(o) or the piece 1 step east in front of the Hero(H). This is only possible if the square behind in the pushing direction is a free square and no stonewall in the path. Same for all four directions.

If you move 1 step east and there is a piece adjacent behind to the west without a stonewall between, the Hero will pull that piece one step east and create a stonewall behind it. The same in all four directions.

If your Hero(H) stands adjacent to any chess piece you may also move the piece if it is able to move, notation is newline + source position + destination position, examples:

E2E3    = Moves a *Pawn*(P) from square E2 to E3. The *Hero*(H) cannot stand at square E3 before this move.
D8G5    = Moves a *Bishop*(B) from square D8 to G5.

The output should be one solution to the input. There may be several different solutions to the same input, your program only needs to provide one solution for one input.

In practise:

If feeding your program with this input (the above example):

. . . H . . . .
. . . o . . . .
. P . . . P . .
. P . K . P . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . X . . . .

Then this is one valid output:

+S+N+E+E+E+E+S+S+S+S+S+S+W+W+W+W+N+N+N
D5B4+W+W
B4A6+E+E+E+N+E+S+E
G5G6+W+N
F6F7+W+N+N+W+S+S+S+S+S

Your program should - using a standard computer with normal proccessing power - be able to provide a solution within 30 minutes of calculations.

Test cases:

4 Example inputs your program should be able to solve (among other ones, don't try hardcoding their solutions):

. . . H . . . .
. . . o . . . .
. P . . . P . .
. P . K . P . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . X . . . .

. . . H . . . .
. . . o . . . .
. . . . . . . .
. P . . . P . .
. . P T P . . .
. . . . P . . .
. . . . . . . .
. . . X . . . .

. . . . . . . .
Q . . . . . . .
. . . . . . . .
P P . . K T K .
. . . . . . . .
. . . P . . . .
. o . . . . . .
. H . . P . X .

. . . H . . . .
. . . o . . . .
R . . . . . . .
P P P P P . . .
. . . . . . . .
. . . . . . . .
. . . P P P P P
. . . . . . . X

This is code-golf, shortest solution in bytes of sourcecode wins!

Plarsen

Posted 2015-05-25T20:41:29.000

Reputation: 1 740

Question was closed 2015-05-26T18:45:33.990

The Hero cannot move an adjacent piece if a stonewalls separates them orthogonally. So Rooks and Queens never moves from their starting positions unless attacking the Hero. I have added a visualized example demonstrating diagonal movement among stonewalls that I hope covers your questions about it. – Plarsen – 2015-05-26T04:53:13.797

Yes that covers all my questions, thank you :) – trichoplax – 2015-05-26T15:07:27.017

2

I think this would benefit from sandboxing, because IMO it needs quite a bit of editing, probably in two or three rounds, to be clearly understandable. Some problems: 1. Notation. If the "visualisation" section used the wasted space on the right to list the characters which a board can contain, there would be a single place to refer to (rather than them being spread throughout the question) and they would not need to be repeated every time a man is mentioned. (And, as a side note, the standard notation for a knight is N).

– Peter Taylor – 2015-05-26T18:12:02.573

start="2">

  • Sequence of concepts. "You can push the Stone(o) ... if the path is free from ... stonewalls". But what's a stonewall? "The kings grave(X) and any Trap(T) cannot be crossed by the Hero(H)". What's a trap? Listing the symbols in advance would help partially with this, because the names of the concepts would already have been introduced. 3. Notation (bis). "All of the chess pieces can also be pushed one square just like the Stone(o), leaving a stonewall behind." How is a hero on top of a stonewall represented?
  • < – Peter Taylor – 2015-05-26T18:12:40.340

    start="4">

  • Objective. "If the Hero(H) moves to a trap, it is game over." So was the mission "to guide your hero" the goal of my program, or is it the goal of a human player and my program is an interactive game? 5. Poorly explained examples. "The above solution is intentionally a bit unneccessary complex, just to demonstrate how stonewalls appear." But having looked at the example, I have no idea how stonewalls appear (or, for that matter, why the solution isn't just "South, South"). If you showed the state after each move it would achieve the purpose.
  • < – Peter Taylor – 2015-05-26T18:13:09.907

    start="2">

  • How can the Hero be on top of a stonewall if the Hero can only be on one of the squares while stonewalls only can be between squares? You have obviously not understanded the concept at all, no offense.
  • < – Plarsen – 2015-05-26T19:51:38.830

    start="4">

  • You don't understand the example because you missed the part under the Stonewalls-section where I state that the stonewalls is created between the square a piece is pushed or pulled from and the square the piece is pushed or pulled to. Perhaps I should have explained that part more times, or would that violate your first comment about repetition?
  • < – Plarsen – 2015-05-26T19:56:17.947

    start="4">

  • "Game over" in that sentence I used it is a failure, and not a successful solution. Game over is in my world, grown up with C64, is the same as saying: You're out, let your friend play instead!. Or in "Waynes World" it is: We're screwed!
  • < – Plarsen – 2015-05-26T20:02:27.567

    Anyway, I have been here for about three years, and honestly, it was so much more fun back then without the nitpicking. I do not know if that is for the befenfit of codegolf or not, but personally I don't like it .. at all. So I am out of here. See you all never, Bye! – Plarsen – 2015-05-26T20:08:27.573

    >

  • The Game state-section has a list, a single place, of the valid characters. Did you skip that section? As a side note, I am not using standard chess notation in my question, I thought it would be unneccessary verbose to state that. Anyway, since the King is dead the letter K was free, and as Knight starts with the letter K I did find it very perfect to reuse that excellent letter for another purpose.
  • < – Plarsen – 2015-05-26T20:40:20.307

    As for the unclear what I am asking for reason for putting the challenge on hold I can only say: Effort have been made in trying to misunderstand the concept at best. – Plarsen – 2015-05-26T20:44:06.563

    start="5">

  • "why the solution isn't just "South, South""? Moving the Hero two squares South will not push the stone to the X, and therefor it is not a valid solution. I am not sure how verbose I need to describe the concept of the Hero pushing the stone, so that you fully comprehend how it technically intended to work. If you have ever played the game Boulderdash, perhaps that gives you a clue. The knight is in the path, I have described that pushing tech: "You can push the Stone(o) in front of the Hero(H) if the path is free from board edges, stonewalls and chess pieces.". A Knight is a chess piece.
  • < – Plarsen – 2015-05-26T20:51:39.950

    I have taken my sense together and decided that I will attempt to re-write it from scratch. I apologize to you Peter Taylor if my comments yesterday came out wrong and offensive, I will do my best in meeting your suggestions about improving it. It might take some days though. – Plarsen – 2015-05-27T05:50:29.367

    2, 3. I interpreted "they will leave a line of stones between the square they come from and the square they are pushed or pulled onto" as describing a situation where a piece was pushed/pulled several times, leaving a trail of stonewalls. Suggested wording: "they will leave a stonewall which separates the square they come from and the square they are pushed or pulled onto", preferably accompanied by a diagram showing before and after. 4. Why not just say that moving the hero onto a trap is forbidden? 1. No, I hadn't got that far. I read from top to bottom. – Peter Taylor – 2015-05-27T21:55:32.477

    start="5">

  • Ah. My ingrained training that K means King is too strong.
  • < – Peter Taylor – 2015-05-27T21:56:15.950

    No answers