Mostly report stuff

This commit is contained in:
Jack Harley 2021-01-31 14:57:20 +00:00
parent 0ba5b018ec
commit 31e5ceb0a9
5 changed files with 15 additions and 8 deletions

View File

@ -20,6 +20,7 @@ extra-source-files:
executable Minesweeper
main-is: Main.hs
other-modules:
Autosolver
Minesweeper
Paths_Minesweeper
hs-source-dirs:

Binary file not shown.

View File

@ -54,7 +54,9 @@
\setlength{\parskip}{1em}
\section{Introduction}
I have implemented a fully functional Minesweeper game in Haskell with the Threepenny GUI serving the interface.
I have implemented a fully functional Minesweeper game in Haskell with the Threepenny GUI serving the interface, and also a probability based autosolver which can perform a move by clicking an "Autoplay" button.
The code is well commented and I have also documented and explained key parts of it in this PDF.
Stack successfully builds and executes the solution binary, serving the GUI at \url{http://localhost:8023}.
@ -72,7 +74,7 @@ data Board = Board { size :: Int, mines :: Grid, uncovered :: Grid, flagged :: G
\end{lstlisting}
\textbf{size} defines the horizontal and vertical length in squares of the game grid (all grids are squares).
\textbf{mines}, \textbf{uncovered} and \textbf{flagged} hold a data structure indicating the squares that respectively have mines, have been uncovered by the user and have been flagged by the user.
\textbf{mines}, \textbf{uncovered} and \textbf{flagged} hold data structures that respectively indicate the squares that have mines, have been uncovered by the user and have been flagged by the user.
The Grid type is a 2D list of Booleans with the outer list denoting rows and the inner list denoting columns:
@ -80,12 +82,12 @@ data Board = Board { size :: Int, mines :: Grid, uncovered :: Grid, flagged :: G
type Grid = [[Bool]]
\end{lstlisting}
For example, you could determine whether the 2nd row down, 4th column across has a mine with the following expression: (N.B. rows and columns are 0-indexed)
With this structure, you can determine whether the 2nd row down, 4th column across has a mine with the following simple expression: (N.B. rows and columns are 0-indexed)
\begin{lstlisting}
(mines !! 1) !! 3
\end{lstlisting}
And indeed this is how the hasMine function is implemented:
And indeed this is how the hasMine function is implemented in my code:
\begin{lstlisting}
hasMine :: Board -> Square -> Bool
hasMine b (r,c) | validSquare b (r,c) = (mines b !! r) !! c
@ -109,7 +111,7 @@ createBoard size mineRatio rng = Board size (seedGrid rng mineRatio (createGrid
(createGrid False size)
\end{lstlisting}
The function requires a size (number of squares in both horizontal and vertical directions), a "mine ratio" and a random number generator instance. It then produces a Board type with three initialised grids. The uncovered and flagged grids are initialised with all False values (since the user will not have uncovered or flagged any squares yet).
The function requires a size (number of squares in both horizontal and vertical directions), a "mine ratio" and a random number generator instance. It then produces a Board instance with three initialised grids. The uncovered and flagged grids are initialised with all False values (since the user will not have uncovered or flagged any squares yet).
The mines grid is initialised with all False values, but then the seedGrid function is used to randomly seed mines into the grid by making a random decision with probability of the provided mineRatio for every square on the grid.
@ -267,7 +269,4 @@ refresh iob = do
I found working with ThreePenny difficult initially, there are limited examples on the web for usage and it took me quite a bit of time wrestling with it before I had some code with a reasonable structure for the main interface setup section. I would've liked to see a method of including static HTML into a page without having to write all of it in the ThreePenny eDSL and an ability to prevent the default action triggered by a browser event occurring (in my case right click opening a context menu) without having to embed a custom script.
\end{document}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 50 KiB

7
src/Autosolver.hs Normal file
View File

@ -0,0 +1,7 @@
module Autosolver where
import Minesweeper
probabilityOfMine :: Board -> Square -> Float
probabilityOfMine _ _ = 1.0