Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right...

27
BATTLESHIP OPTIMIZATION LOFTON ANDERSON & STEVE MYRICK TEAM GJALLARHORN

Transcript of Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right...

Page 1: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

BATTLESHIP OPTIMIZATION

LOFTON ANDERSON & STEVE MYRICK

TEAM GJALLARHORN

Page 2: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

ABSTRACT

• THE GAME OF BATTLESHIP WAS CONCEIVED IN WWI AND POPULARIZED MY MILTON BRADLEY IN 1967.

• ALGORITHM TAKES STANDARD RULES

• 5 SHIPS, 10X10 GRID, NO DIAGONALLY PLACED SHIPS

• ALGORITHM CAN NOT “LOSE” THE GAME AGAINST AN OPPONENT

• WE ARE USING A SAMPLE SIZE OF 200,000 BOARDS FOR THIS DEMONSTRATION

Page 3: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

INFORMAL PROBLEM STATEMENT

• FOR A BATTLESHIP BOARD, CHARACTERIZED BY A 10X10 GRID WITH EACH CELL BEING A POSSIBLE PLACEMENT FOR A SHIP, 5 SHIPS OF CELL LENGTHS {5,4,3,3,2} ARE PLACED ON THE BOARD NON-INTERSECTING IN A HORIZONTAL OR VERTICAL DIRECTION. EXAMINE CELLS ONE-BY-ONE TO CHECK WHETHER THE CELL IS EMPTY OR OCCUPIED BY A SHIP. THE GAME IS COMPLETED ONCE ALL 17 CELLS CONTAINING SHIPS HAVE BEEN CHECKED. AN ALGORITHM’S PERFORMANCE IS MEASURED BY HOW MANY CHECKS IT TAKES TO LOCATE ALL FILLED CELLS, WITH LOWER NUMBERS BEING MORE OPTIMAL.

Page 4: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

FORMAL PROBLEM STATEMENT• BLANK BATTLESHIP BOARD BB = (X, X, X, X, X, X, X, X,X, X) AND X = (0,0,0,0,0,0,0,0,0,0)

• FILLED CELL CF = 1 AND EMPTY CELL CE = 0

• SHIP LENGTHS S AND WEIGHT W

• S1 = 5, W = 1

• S2 = 4, W = 1

• S3 = 3, W = 2

• S4 = 2, W = 1

• NUMBER OF HITS = H

• WINNING CONDITION H = 17

• NUMBER OF GUESSES = G

• NUMBER OF BOARDS = N

• AVERAGE NUMBER OF GUESSES = ΣG/N

Page 5: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

CONTEXT

• A MAN BY THE NAME OF NICK BERRY, A TECHNOLOGY CONSULTANT AND PRESIDENT OF DATAGENETICS, A DATA MINING COMPANY, PUBLISHED A PAGE WITH WHAT HE CONSIDERS THE MOST OPTIMAL WAY TO SOLVE THE GAME OF BATTLESHIP

• IMPLEMENTED 3 SEARCHING ALGORITHMS, RANDOM, HUNT/TARGET, HUNT/TARGET (WITH PARITY), AND A “NEW” ALGORITHM

• OUR ALGORITHMS ARE DIFFERENT ON PURPOSE TO COMPARE OUR STRATEGIES TO HIS STATED ALGORITHM

Page 6: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

LINEAR SEARCH

• Brute Force• Average of 88 checks• Worst possible algorithm if there is a

ship in the bottom right cell• Best search: 25

Page 7: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 8: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

RANDOM SEARCH• Implements Java’s random• Worst possible algorithm• Average of 95 checks• Best search: 56• Does not account for hits• Mathematically, the chances of playing a perfect

game with random firing are easy to calculate and are:

355,687,428,096,000 / 2,365,369,369,446,553,061,560,941,772,800,000• This equates to, on average, once in every

6,650,134,872,937,201,800 games• Source (http://www.datagenetics.com/blog/december32011/)

Page 9: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 10: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

MODIFIED LINEAR SEARCH

• “IMPROVED” CHECK

• LEFT, DOWN, RIGHT, UP

• AVERAGE OF 82 CHECKS

• BEST SEARCH: 23

Page 11: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 12: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

MODIFIED RANDOM SEARCH

• AVERAGE OF 69 CHECKS

• MODELS THE MOST BASIC HUMAN STRATEGY

• BEST SEARCH :22

• CALLED “HUNT/TARGET” METHOD

• HTTP://WWW.DATAGENETICS.COM/BLOG/DECEMBER32011/

Page 13: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 14: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

MODIFIED EVERY OTHER SEARCH

• AVERAGE OF 60 CHECKS

• BEST SEARCH: 24

• ALSO CALLED A “CHECKER BOARD” SEARCH

• ROUGHLY CHECKING HALF THE BOARD

Page 15: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 16: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

MODIFIED EVERY THIRD SEARCH• AVERAGE OF 78 CHECKS

• HOPEFULLY CHECKS BOARD WITH ONE PASS THOUGH, CHECKING 1/3 OF TOTAL CELLS

• AFTER FIRST PASS THOUGH, IF ALL SHIPS HAVE NOT BEEN FOUND, CHECK THE NEXT 1/3

• MOST OPTIMAL ALGORITHM TESTED

• BEST SEARCH: 25

Page 17: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 18: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

MODIFIED SPIRAL SEARCH• STARTS FROM THE MIDDLE GOING

OUT IN A COUNTERCLOCKWISE ROTATION

• AVERAGE OF 79 CHECKS

• DOES NOT WORK WELL WITH COMMON HUMAN STRATEGY OF HIDING SHIPS ON THE SIDES OF THE BOARD

• BEST SEARCH: 22

Page 19: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 20: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

QUADRATIC CHECKERS SEARCH• AVERAGE OF 67 CHECKS

• BEST SEARCH: 22

• DIVIDES THE BOARD IN TO 4 QUADRANTS, AND CHECKS EVERY OTHER SPACE IN THE QUADRANT

• COMPUTATIONALLY FAVORABLE BECAUSE OF HARD CODED POINTS

Page 21: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 22: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

INTERPRETATION AND CONCLUSION

• THE “BEST” WAY TO PLAY BATTLESHIP IS THE “MODIFIED EVERY THIRD” STRATEGY

• THE NATURAL “RANDOMLY GUESS AND SEARCH AROUND” STRATEGY THAT PEOPLE USUALLY PLAY IS NOT A BAD SEARCH

• THESE ALGORITHMS ARE EASILY IMPLEMENTED BY HUMANS AND SHOW THEIR UTILITY IMMEDIATELY RATHER THAN OVER TIME

• THIS RELATES TO CSC 380 BECAUSE THIS IS AN OPTIMIZATION PROBLEM USING VARIOUS ALGORITHMS TO FIND THE MOST OPTIMAL ALGORITHM

Page 23: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.
Page 24: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

FUTURE WORK

• IMPROVEMENT WITH HISTORY OR PRIOR KNOWLEDGE OF BOARD DESIGN

• COMMON PLACEMENTS (IMPLEMENT PROBABILITY DENSITY FUNCTION)

• IMPROVE MODIFIED RANDOM SEARCH WITH STACK

• A “PERFECT” ALGORITHM?

Page 25: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

QUESTIONS FOR YOU

• WHY WOULD A LINEAR SEARCH OF THE GRID BE BRUTE FORCE? HOW DOES THIS DIFFER FROM A RANDOM SEARCH?

• HOW WOULD YOU REPRESENT THE GRID AS A DATA STRUCTURE?

• WHY DOES A RANDOM SEARCH HAVE A LESS FAVORABLE RESULT THAN THE LINEAR SEARCH?

• WHAT IS THE O(LINEAR SEARCH)? O(SPIRAL)?

Page 26: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

QUESTIONS FOR YOU

• WHY WOULD A LINEAR SEARCH OF THE GRID BE BRUTE FORCE? HOW DOES THIS DIFFER FROM A RANDOM SEARCH?

• A LINEAR SEARCH JUST TRAVERSES THE 2D ARRAY IN A SIMPLISTIC LOGIC. RANDOM SEARCH MUST IMPLEMENT A RANDOMIZER AND KEEP TRACK OF WHICH PLACES IT HAS CHECKED.

• HOW WOULD YOU REPRESENT THE GRID AS A DATA STRUCTURE?• TWO-DIMENSIONAL ARRAY. COULD POSSIBLY BE REPRESENTED BY A SINGLE ARRAY OR SET OF POINTS, BUT IT WOULD BE DIFFICULT TO

VISUALIZE AND IMPLEMENT.

• WHY DOES A RANDOM SEARCH HAVE A LESS FAVORABLE RESULT THAN THE LINEAR SEARCH?

• BECAUSE A LINEAR SEARCH HAS THE POSSIBILITY TO FIND AN ENTIRE BATTLESHIP QUICKLY IF ONE OR MULTIPLE BATTLESHIPS ARE PLACED HORIZONTALLY AND TOWARDS THE TOP OF THE BOARD.

• WHAT IS THE O(LINEAR SEARCH)? O(SPIRAL)?

• WITHOUT TAKING IN TO ACCOUNT VERIFICATION STEPS:

• O(LINEAR SEARCH) – O(N^2) BECAUSE IT MUST MUST TRAVERSE THROUGH A TWO-DIMENSIONAL ARRAY

• O(SPIRAL) – O(N) BECAUSE YOU ARE INPUTTING POINTS THROUGH A LIST

Page 27: Brute Force Average of 88 checks Worst possible algorithm if there is a ship in the bottom right cell Best search: 25.

QUESTIONS FOR US?