270 likes | 490 Vues
CPE 481 - Minesweeper. Hafeez Jaffer. Introduction. Rules of the game History originally created by Robert Donner and Curt Johnson. New Features. - open and save minefield. - more freedom in choosing minefield dimensions. New Features Cont. Turn Rete engine on/off
E N D
CPE 481 - Minesweeper Hafeez Jaffer
Introduction • Rules of the game • History • originally created by Robert Donner and Curt Johnson
New Features - open and save minefield - more freedom in choosing minefield dimensions
New Features Cont. • Turn Rete engine on/off • Display Rete engine facts • Try all combinations (beta)
Goal of the Assignment • Create a JESS agent that will find mines in a given Minefield • minesweeper.clp • Found in the Jess directory, each rule that is written in this file will be loaded and executed by the MineSweeper program to determine mine locations
Grading Criteria • Logically deduce and flag mine locations in a given solvable minefield (one that doesn't require guessing) • Solve all the test cases in the "testCases" directory • Solve expert minefields in an efficient and fast manner
Point breakdown • 5 points for implementing the deffunctions "flagAllSurroundingUnknowns" and "revealAllSurroundingUnknowns" • 5 points for performance • 10 points for the test runs • 5 points for the README file and documentation of the source code
Submission • "minesweeper.clp" file • containing the JESS rules to solve a given minefield • A README file documenting how your agent deduces mine locations and any known limitations
Test Cases • This presentation contains 6 basic test cases • These may not be the ones I use to test your program
Test Case1 Solution A B C – 1 A B – 1 B C D – 1 C D – 1 1 – 1 = 0. 0 means all that’s left are not mines C is not a mine. A 1 – 1 = 0. 0 means all that’s left are not mines B is not a mine. B C D
Test Case2 Solution C is left after DE is taken out. C must be a mine. (2 – 1 = 1) D E – 1 D E C – 2 A B C D – 1 E C D – 2 E is left after CD is taken out. C must be a mine. (2 – 1 = 1) A B C D E 2 – 1 = 1, the number that’s left is equal to this, therefore mine Jess functions used: Intersection, complement, and test
Test Case3 Solution BCI was taken out, 5 – 3 = 2. That’s the number remaining. If equal, all are mines. DJ are mines A B C F H I – 3 B C D J I – 5 B C D I J – 5 C D E J G K – 3 A B C D E CDJ was taken out, 5 – 3 = 2. That’s the number remaining. If equal, all are mines. BI are mines G F H I J K Jess functions used: Intersection, complement, and test
Test Case4 Solution C D F – 1 C D F I J K – 3 B C H I J – 4 A B C H I E G – 3 BCHI removed, 4 – 3 = 1, That’s the number remaining. So J is a mine. For the bottom, AEG are left. 3 – 4 = -1. This is less than or equal to 0. AEG are not mines. A B C D E F G H I J K Jess functions used: Intersection, complement, and test
Test Case5 Solution B can be revealed because there is only one mine left. B must be 1 so A and D can be revealed A B C D
Test Case6 Solution • Use the “Try all combinations” option from the menu
Implementation Details - Deftemplates (MineSquare (slot id) - integer (slot row) - integer (slot col) - integer (slot status ?status) - integer (multislot surroundingUnknowns) - integer list (slot numSurroundingFlags) - integer ) (MinefieldVariables (slot numberMines) - integer (slot mineHeight) - integer (slot mineWidth) - integer )
Implementation Details - Defglobals • EMPTY_SQUARE (=0) • FLAGGED_MINE (=-2) • UNKNOWN (=-4)
Implementation Details – GUI hooks • (reveal-square ?id) • (flag-square ?id)
Implementation Details – Jess commands • http://www.cs.vu.nl/~ksprac/2002/doc/Jess60/functions.html • length$ • Returns the number of fields in a multifield value. • Subsetp • Returns TRUE if the first argument is a subset of the second (i.e., all the elements of the first multifield appear in the second multifield); otherwise, returns FALSE. • complement$ • Returns a new multifield consisting of all elements of the second multifield not appearing in the first multifield. • intersection$ • Returns the intersection of two multifields. Returns a multifield consisting of the elements the two argument multifields have in common. • Test • Returns true if the argument is true, false otherwise.
Conclusion • Any questions?