Open olufjen opened 4 years ago
Construct a KB consisting of Percepts and Sentences A ChessState is a Percept? Construct a KB Agent which implements
Examples of how to write rules to the knowledgebase: // We can connect stench and breeze percepts directly // to the properties of the squares where they are experienced // through the location fluent as follows. For any time step t // and any square [x,y], we assert tell(new ComplexSentence( newSymbol(LOCATION, t, agentPosition.getX(), agentPosition.getY()), Connective.IMPLICATION, new ComplexSentence(newSymbol(PERCEPT_BREEZE, t), Connective.BICONDITIONAL, newSymbol(BREEZE, agentPosition.getX(), agentPosition.getY()))));
From AIMA book p. 247 R4, and R5: A location (x,y) precepts a breeze, then there must be a breeze at this location. How to express this precepts of breeze at a given location: : We want to establish the fact that there is a breeze in a certain location: newSymbol(BREEZE, agentPosition.getX(), agentPosition.getY())))); This is the head. This is the case iff: new ComplexSentence( newSymbol(LOCATION, t, agentPosition.getX(), agentPosition.getY()), Connective.IMPLICATION, new ComplexSentence(newSymbol(PERCEPT_BREEZE, t), .....
In chess: We want to establish the fact that a position is protected and safe to move to.
An example of how to create rules of a knowledge base:
/**
* TELL the KB the atemporal "physics" sentences (used to initialize the KB).
*/
protected void tellAtemporalPhysicsSentences() {
//
// 7.7.1 - The current state of the World
// The agent knows that the starting square contains no pit
tell(new ComplexSentence(Connective.NOT, newSymbol(PIT, start.getX(), start.getY())));
// and no wumpus.
tell(new ComplexSentence(Connective.NOT, newSymbol(WUMPUS, start.getX(), start.getY())));
// Atemporal rules about breeze and stench
// For each square, the agent knows that the square is breezy
// if and only if a neighboring square has a pit; and a square
// is smelly if and only if a neighboring square has a wumpus.
for (int y = 1; y <= caveYDimension; y++) {
for (int x = 1; x <= caveXDimension; x++) {
List<PropositionSymbol> pitsIn = new ArrayList<>();
List<PropositionSymbol> wumpsIn = new ArrayList<>();
if (x > 1) { // West room exists
pitsIn.add(newSymbol(PIT, x - 1, y));
wumpsIn.add(newSymbol(WUMPUS, x - 1, y));
}
if (y < caveYDimension) { // North room exists
pitsIn.add(newSymbol(PIT, x, y + 1));
wumpsIn.add(newSymbol(WUMPUS, x, y + 1));
}
if (x < caveXDimension) { // East room exists
pitsIn.add(newSymbol(PIT, x + 1, y));
wumpsIn.add(newSymbol(WUMPUS, x + 1, y));
}
if (y > 1) { // South room exists
pitsIn.add(newSymbol(PIT, x, y - 1));
wumpsIn.add(newSymbol(WUMPUS, x, y - 1));
}
tell(new ComplexSentence
(newSymbol(BREEZE, x, y), Connective.BICONDITIONAL, Sentence.newDisjunction(pitsIn)));
tell(new ComplexSentence
(newSymbol(STENCH, x, y), Connective.BICONDITIONAL, Sentence.newDisjunction(wumpsIn)));
}
}
// The agent also knows there is exactly one wumpus. This is represented
// in two parts. First, we have to say that there is at least one wumpus
List<PropositionSymbol> wumpsAtLeast = new ArrayList<>();
for (int x = 1; x <= caveXDimension; x++)
for (int y = 1; y <= caveYDimension; y++)
wumpsAtLeast.add(newSymbol(WUMPUS, x, y));
tell(Sentence.newDisjunction(wumpsAtLeast));
// Then, we have to say that there is at most one wumpus.
// For each pair of locations, we add a sentence saying
// that at least one of them must be wumpus-free.
int numRooms = (caveXDimension * caveYDimension);
for (int i = 0; i < numRooms; i++) {
for (int j = i + 1; j < numRooms; j++) {
tell(new ComplexSentence(Connective.OR,
new ComplexSentence
(Connective.NOT, newSymbol(WUMPUS, (i / caveXDimension) + 1, (i % caveYDimension) + 1)),
new ComplexSentence
(Connective.NOT, newSymbol(WUMPUS, (j / caveXDimension) + 1, (j % caveYDimension) + 1))));
}
}
}
A list of opponent pieces to capture based on rank. A list of own pieces and their priority to move A list of Positions to capture or protect.