|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600
|
|
|
2
|
+{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;}
|
|
|
3
|
+{\colortbl;\red255\green255\blue255;\red191\green100\blue38;\red32\green32\blue32;\red153\green168\blue186;
|
|
|
4
|
+\red133\green96\blue154;\red254\green187\blue91;\red109\green109\blue109;\red86\green132\blue173;\red255\green255\blue255;
|
|
|
5
|
+}
|
|
|
6
|
+{\*\expandedcolortbl;;\csgenericrgb\c74902\c39216\c14902;\csgenericrgb\c12549\c12549\c12549;\csgenericrgb\c60000\c65882\c72941;
|
|
|
7
|
+\csgenericrgb\c52157\c37647\c60392;\csgenericrgb\c99608\c73333\c35686;\csgenericrgb\c42745\c42745\c42745;\csgenericrgb\c33725\c51765\c67843;\cssrgb\c100000\c100000\c100000;
|
|
|
8
|
+}
|
|
|
9
|
+\margl1440\margr1440\vieww18620\viewh12280\viewkind0
|
|
|
10
|
+\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardirnatural\partightenfactor0
|
|
|
11
|
+
|
|
|
12
|
+\f0\fs24 \cf2 \cb3 public class \cf4 MineSweeper\
|
|
|
13
|
+\{ \cf2 private int\cf4 [][] \cf5 myTruth\cf2 ;\
|
|
|
14
|
+ private boolean\cf4 [][] \cf5 myShow\cf2 ;\
|
|
|
15
|
+\
|
|
|
16
|
+ public void \cf6 cellPicked\cf4 (\cf2 int \cf4 row\cf2 , int \cf4 col)\
|
|
|
17
|
+ \{ \cf2 if\cf4 ( inBounds(row\cf2 , \cf4 col) && !\cf5 myShow\cf4 [row][col] ) \cf7 // if inbounds and not shown, then show. this also acts as a stopping statement for recursion.\
|
|
|
18
|
+\
|
|
|
19
|
+ \cf4 \{\cf5 myShow\cf4 [row][col] = \cf2 true;\
|
|
|
20
|
+\
|
|
|
21
|
+ if\cf4 ( \cf5 myTruth\cf4 [row][col] == \cf8 0\cf4 ) \cf7 // if this recursive statement evaluates, this is where we see the bombs or X's\
|
|
|
22
|
+ \cf4 \{ \cf2 for\cf4 (\cf2 int \cf4 r = -\cf8 1\cf2 ; \cf4 r <= \cf8 1\cf2 ; \cf4 r++)\
|
|
|
23
|
+ \cf2 for\cf4 (\cf2 int \cf4 c = -\cf8 1\cf2 ; \cf4 c <= \cf8 1\cf2 ; \cf4 c++)\
|
|
|
24
|
+ cellPicked(row + r\cf2 , \cf4 col + c)\cf2 ; \cf7 // the recursion itself (initial method buried in itself)\
|
|
|
25
|
+ \cf4 \}\
|
|
|
26
|
+ \}\
|
|
|
27
|
+ \}\
|
|
|
28
|
+\
|
|
|
29
|
+ \cf2 public boolean \cf6 inBounds\cf4 (\cf2 int \cf4 row\cf2 , int \cf4 col)\
|
|
|
30
|
+ \{ \cf2 return\
|
|
|
31
|
+ \cf8 0 \cf4 <= row \cf7 // is within bounds of game (does not exceed the rows on the board)\
|
|
|
32
|
+\
|
|
|
33
|
+ \cf4 &&\
|
|
|
34
|
+\
|
|
|
35
|
+ row < \cf5 myTruth\cf4 .\cf5 length \cf7 // another check for bounds of the game (rows and columns considered)\
|
|
|
36
|
+\
|
|
|
37
|
+ \cf4 &&\
|
|
|
38
|
+\
|
|
|
39
|
+ \cf8 0 \cf4 <= col \cf7 // # column is within bounds of game (does not exceed the columns on the board\
|
|
|
40
|
+\
|
|
|
41
|
+ \cf4 &&\
|
|
|
42
|
+\
|
|
|
43
|
+ col < \cf5 myTruth\cf4 [\cf8 0\cf4 ].\cf5 length\cf2 ; \cf7 // is less than the amount of params in first row (max # of columns in game)\
|
|
|
44
|
+ \cf4 \}\
|
|
|
45
|
+\}\
|
|
|
46
|
+\
|
|
|
47
|
+\
|
|
|
48
|
+\cf0 \cb9 \
|
|
|
49
|
+The above is how I\'92ve interpreted the Minesweeper code. We begin with two Variables, myTruth and myShow. myShow is where all of the shown spaces exist and myTruth is a variable created to initialize the recursive statement. As I\'92ve researched the topic, recursion is where the initial method is included within itself, in which above, cellPicked is invoked if a statement (myTruth[row][col] == 0) is evaluated successfully.\
|
|
|
50
|
+\
|
|
|
51
|
+The code begins with the method itself evaluating to parameters which measure if a space has been shown or not. If the space is in bounds and is not showing, it is shown. However, the parameters for cellPicked are evaluated In the myTruth statement and if this evaluates, recursion occurs as a result of two for loops. These for loops are set up to precisely add -1 to the parameters in cellPicked as even though they have incremental variables, they exist within the if statement buried in the cellPicked method, so they will never truly increment past -1 when the method is re-invoked as a result of recursion.}
|