Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/board.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setCell(board: Board, idx: Int, new_val: Cell): Unit = {

def buildBoard(rows: Int, cols: Int, mines: List[XY]): Board = {
with on[OutOfBounds].panic
var grid: Array[Cell] = array(rows*cols, Hidden(false, false))
var grid: Array[Cell] = array(rows * cols, Hidden(false, false))
val board = Board(grid, rows, cols, mines.size())
mines.foreach{cell => board.setCell(cell, Hidden(true, false))}
board
Expand Down Expand Up @@ -111,7 +111,7 @@ def moveMine(board: Board, xy: XY, moveAway: Bool): Unit / {GameOver} = {
curBoard.getRevealedNeighbors(xy).size > curBoard.getRevealedNeighbors(xy2).size
}
hidden = hidden.append(par.second.shuffle)
val mineDensity = (board.mines - obvsMines.size).toDouble/(hidden.size.toDouble)
val mineDensity = (board.mines - obvsMines.size).toDouble / (hidden.size.toDouble)
var found = false
try {
var curBoard = curBoard
Expand Down Expand Up @@ -220,7 +220,7 @@ def println(board: Board, showBombs: Bool): Unit = {
str = str ++ "*|"
each(0, board.cols) {n => str = str ++ n.mod(10).show ++ "|"}
with Formatted::formatting
each(0, board.rows*board.cols) {idx =>
each(0, board.rows * board.cols) {idx =>
if (mod(idx,board.cols) == 0) {
str = str ++ "\n"
str = str ++ counter.mod(10).show ++ "|"
Expand Down
10 changes: 5 additions & 5 deletions src/main.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def main() = {
with Formatted::formatting
var difficulty = -1
while (difficulty == -1) {
with on[WrongFormat].default{println(red("Input needs to be a single integer (1-3)"))}
with crash(red("Input needs to be a single integer (1-3)"))
val input = askUser("Choose difficulty (1-3):\n1: beginner\n2: intermediate (default)\n3: expert")
difficulty = if (input == "") 2 else input.toInt
if (difficulty < 1 || difficulty > 3) do raise(WrongFormat(), "")
if (difficulty < 1 || difficulty > 3) do fail()
}
println(Screen::clear())
var fair = -1
while (fair == -1) {
with on[WrongFormat].default{println(red("Input needs to be a single integer (1-2)"))}
with crash("Input needs to be a single integer (1-2)")
val input = askUser("Use fair mode (1-2):\n1: yes (default)\n2: no")
fair = if (input == "") 1 else input.toInt
if (difficulty < 1 || difficulty > 2) do raise(WrongFormat(), "")
if (difficulty < 1 || difficulty > 2) do fail()
}
println(Screen::clear())
board = difficulty match {
Expand Down Expand Up @@ -77,7 +77,7 @@ def playGame(board: Board, fair: Bool): Unit / {Flagging, Revealing, Won, GameOv
println(board)
val input = askUser("Enter action ('r x y' to reveal, 'f x y' to flag, 'restart', 'quit'): ")
println(Screen::clear())
with on[WrongFormat].default{println(red("Coordinates need to be integer. Try again"))}
with crash(red("Coordinates need to be integer. Try again"))
input.split(" ") match {
case Cons("r", Cons(x, Cons(y, _))) and board.isValid(XY(x.toInt,y.toInt)) => board.revealCell(XY(x.toInt, y.toInt), true, fair)
case Cons("f", Cons(x, Cons(y, _))) and board.isValid(XY(x.toInt,y.toInt)) => board.flagCell(XY(x.toInt, y.toInt))
Expand Down
4 changes: 2 additions & 2 deletions src/utils.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type Cell {

def infixEq(left: Cell, right: Cell): Bool =
(left, right) match {
case (Hidden(l1,l2),Hidden(r1,r2)) => l1==r1 && l2==r2
case (Revealed(l1,l2),Revealed(r1,r2)) => l1==r2 && l2==r2
case (Hidden(l1,l2),Hidden(r1,r2)) => l1 == r1 && l2 == r2
case (Revealed(l1,l2),Revealed(r1,r2)) => l1 == r2 && l2 == r2
case (SHidden(),SHidden()) => true
case (Mine(),Mine()) => true
case _ => false
Expand Down
Loading