olufjen / chess

Programs to utilize chess ontologies, and play games of chess
1 stars 0 forks source link

Game strategies from week 1 2022 #37

Open olufjen opened 2 years ago

olufjen commented 2 years ago

An Action Schema is applicable if the preconditions are satisfied by the initial state. (see p. 368) In addition, for the search algorithm to return with a plan then the fluents of the goal state must all be present among the fluents of the outcome. As shown on p. 369: The problem is solved when we can find a sequence of actions that end in a state s that entails the goal. This is expressed in the sentence: if (outcome.getFluents().containsAll(problem.getGoalState().getFluents())) { In the Chess Search Algorithm.

Make sure that an Action Schema contains a PROTECTED precondition in order to be chosen. There is an initial and goal state for every action schema and chess action available. If the chess search algorithm does not return with a plan, try again with another Chess Problem with a different initial and goal state?

olufjen commented 2 years ago

When moving White Bishop 2 to d3: Chosen action Schema Action(WhiteBishop2) PRECOND:^occupies(WhiteBishop2,f1)^PIECETYPE(WhiteBishop2,BISHOP) EFFECT:^occupies(WhiteBishop2,c4)^PIECETYPE(WhiteBishop2,BISHOP)

Chosen action ChessAction: Preferred Position d3 Piece Piece position f1 X, Y (5, 0) wB f1 BISHOP ActiveName B

Possible move Move Piece Piece position f1 X, Y (5, 0) wB f1 BISHOP ActiveName B From position f1 Color W Direction NONE sumdif 5 Piece no.chess.web.model.ChessPiece Ontology name WhiteBishop2 Chesspiece position f1 Piece active: true true Friendly false gamepiece null

To position c4 Color W Direction NONE sumdif 6 Piece None false Friendly false gamepiece Gamenone Move number 0 Creation Created from gamepiece preferred position

olufjen commented 2 years ago

The following game:

game070122

Chosen action Schema Returning with a reserve plan. Then the first action schema is chosen. Action(WhitePawn3) PRECOND:^occupies(WhitePawn3,c4)^PIECETYPE(WhitePawn3,PAWN) EFFECT:^occupies(WhitePawn3,d5)^PIECETYPE(WhitePawn3,PAWN) The new position and the preferred position d5 d5 The fluents of the init state occupies(WhitePawn3,c4) BOARD(c4) PIECETYPE(WhitePawn3,PAWN) REACHABLE(WhitePawn3,c5) BOARD(c5) PROTECTEDBY(WhitePawn4,c5) The fluents of the goal state occupies(WhitePawn3,d5) PIECETYPE(WhitePawn3,PAWN) BOARD(d5) The Chess search algorithm returns with a reserve plan with the above setting. Compare with original: Chosen action Schema Action(WhitePawn3) PRECOND:^occupies(WhitePawn3,c4)^PIECETYPE(WhitePawn3,PAWN) EFFECT:^occupies(WhitePawn3,c5)^PIECETYPE(WhitePawn3,PAWN) Returns with a plan: The fluents of end outcome:

occupies(WhitePawn3,c4) BOARD(c4) PIECETYPE(WhitePawn3,PAWN) REACHABLE(WhitePawn3,c5) BOARD(c5) PROTECTEDBY(WhitePawn4,c5) occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) The fluents of goal state:

occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) BOARD(c5)

The initial state is "wrong" because it uses the symbolic name REACHABLE !!!

olufjen commented 2 years ago

When Problem is created: The fluents of the init state occupies(WhitePawn3,c4) BOARD(c4) PIECETYPE(WhitePawn3,PAWN) REACHABLE(WhitePawn3,c5) BOARD(c5) PROTECTEDBY(WhitePawn4,c5)

The fluents of the goal state occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) BOARD(c5)

And then when it returns with a plan from the Chess Search algorithm::

Returns with a plan: The fluents of end outcome:

occupies(WhitePawn3,c4) BOARD(c4) PIECETYPE(WhitePawn3,PAWN) REACHABLE(WhitePawn3,c5) BOARD(c5) PROTECTEDBY(WhitePawn4,c5) --- These lines are added: occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) The fluents of goal state:

occupies(WhitePawn3,c5) PIECETYPE(WhitePawn3,PAWN) BOARD(c5)

olufjen commented 2 years ago

Reserve plan for castling: game110122 The fluents of end outcome:

occupies(WhiteKing,e1) BOARD(e1) PIECETYPE(WhiteKing,KING) REACHABLE(WhiteKing,f1) BOARD(f1) REACHABLE(WhiteKing,e2) BOARD(e2) REACHABLE(WhiteKing,d2) BOARD(d2) PROTECTEDBY(WhiteBishop2,f1) PROTECTEDBY(WhiteBishop2,e2) PROTECTEDBY(WhiteKnight1,e2) PROTECTEDBY(WhiteKnight2,d2) PROTECTEDBY(WhiteBishop1,d2) PROTECTEDBY(WhiteRook2,f1) PROTECTEDBY(WhiteQueen,d2) PROTECTEDBY(WhiteQueen,e2) The fluents of goal state:

occupies(WhiteKing,g1) PIECETYPE(WhiteKing,KING) BOARD(g1)

End chess search with a reserve plan

And from the problem planning phase: Chosen action Schema Action(WhiteKing) PRECOND:^PROTECTEDBY(WhiteKnight2,g1)^PROTECTEDBY(WhiteRook2,g1)^occupies(WhiteKing,e1)^PIECETYPE(WhiteKing,KING) EFFECT:^occupies(WhiteKing,g1)^PIECETYPE(WhiteKing,KING) The new position and the preferred position g1 g1 The fluents of the init state occupies(WhiteKing,e1) BOARD(e1) PIECETYPE(WhiteKing,KING) REACHABLE(WhiteKing,f1) BOARD(f1) REACHABLE(WhiteKing,e2) BOARD(e2) REACHABLE(WhiteKing,d2) BOARD(d2) PROTECTEDBY(WhiteBishop2,f1) PROTECTEDBY(WhiteBishop2,e2) PROTECTEDBY(WhiteKnight1,e2) PROTECTEDBY(WhiteKnight2,d2) PROTECTEDBY(WhiteBishop1,d2) PROTECTEDBY(WhiteRook2,f1) PROTECTEDBY(WhiteQueen,d2) PROTECTEDBY(WhiteQueen,e2) The fluents of the goal state occupies(WhiteKing,g1) PIECETYPE(WhiteKing,KING) BOARD(g1)

olufjen commented 2 years ago

The problem of the previous comment is solved: game120122

From the scheduling phase, we get this action schema and its initial and goal states: Chosen action Schema Action(WhiteKing) PRECOND:^PROTECTEDBY(WhiteKnight2,g1)^PROTECTEDBY(WhiteRook2,g1)^occupies(WhiteKing,e1)^PIECETYPE(WhiteKing,KING) EFFECT:^occupies(WhiteKing,g1)^PIECETYPE(WhiteKing,KING) The new position and the preferred position g1 g1 The fluents of the init state occupies(WhiteKing,e1) BOARD(e1) PIECETYPE(WhiteKing,KING) REACHABLE(WhiteKing,f1) BOARD(f1) CASTLE(WhiteKing,g1) BOARD(g1) REACHABLE(WhiteKing,e2) BOARD(e2) CASTLE(WhiteKing,g1) BOARD(g1) REACHABLE(WhiteKing,d2) BOARD(d2) CASTLE(WhiteKing,g1) BOARD(g1) PROTECTEDBY(WhiteBishop2,f1) PROTECTEDBY(WhiteBishop2,e2) PROTECTEDBY(WhiteKnight1,e2) PROTECTEDBY(WhiteKnight2,d2) PROTECTEDBY(WhiteBishop1,d2) PROTECTEDBY(WhiteRook2,f1) PROTECTEDBY(WhiteQueen,d2) PROTECTEDBY(WhiteQueen,e2) PROTECTEDBY(WhiteKnight2,g1) PROTECTEDBY(WhiteRook2,g1) The fluents of the goal state occupies(WhiteKing,g1) PIECETYPE(WhiteKing,KING) BOARD(g1)

Then from the Chess search algorithm, we get solved problem: Returns with a plan: The fluents of end outcome:

occupies(WhiteKing,e1) BOARD(e1) PIECETYPE(WhiteKing,KING) REACHABLE(WhiteKing,f1) BOARD(f1) CASTLE(WhiteKing,g1) BOARD(g1) REACHABLE(WhiteKing,e2) BOARD(e2) CASTLE(WhiteKing,g1) BOARD(g1) REACHABLE(WhiteKing,d2) BOARD(d2) CASTLE(WhiteKing,g1) BOARD(g1) PROTECTEDBY(WhiteBishop2,f1) PROTECTEDBY(WhiteBishop2,e2) PROTECTEDBY(WhiteKnight1,e2) PROTECTEDBY(WhiteKnight2,d2) PROTECTEDBY(WhiteBishop1,d2) PROTECTEDBY(WhiteRook2,f1) PROTECTEDBY(WhiteQueen,d2) PROTECTEDBY(WhiteQueen,e2) PROTECTEDBY(WhiteKnight2,g1) PROTECTEDBY(WhiteRook2,g1) OBS: NEW ENTRIES TO INITIAL STAGE: occupies(WhiteKing,g1) PIECETYPE(WhiteKing,KING) occupies(WhiteKing,g1) PIECETYPE(WhiteKing,KING) The fluents of goal state:

occupies(WhiteKing,g1) PIECETYPE(WhiteKing,KING) BOARD(g1)