-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of Hearts and Arrows puzzles.
Built atop Rows Garden logic as these formats are quite similar in nature. Also fixes a bug with Rows Garden where row clues are labeled in the grid with letters but in the clue list with numbers.
- Loading branch information
Showing
11 changed files
with
451 additions
and
138 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/commonMain/kotlin/com/jeffpdavidson/kotwords/model/HeartsAndArrows.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.jeffpdavidson.kotwords.model | ||
|
||
import com.jeffpdavidson.kotwords.formats.Puzzleable | ||
import kotlinx.serialization.Serializable | ||
import kotlin.math.floor | ||
import kotlin.math.roundToInt | ||
|
||
@Serializable | ||
data class HeartsAndArrows( | ||
val title: String, | ||
val creator: String, | ||
val copyright: String, | ||
val description: String, | ||
val solutionGrid: List<List<Char>>, | ||
val arrows: List<List<RowsGarden.Entry>>, | ||
val light: List<RowsGarden.Entry>, | ||
val medium: List<RowsGarden.Entry>, | ||
val dark: List<RowsGarden.Entry>, | ||
val lightHeartColor: String = "#FFFFFF", | ||
val mediumHeartColor: String = "#F4BABA", | ||
val darkHeartColor: String = "#E06666", | ||
val addWordCount: Boolean = true, | ||
val addHyphenated: Boolean = true, | ||
val hasHtmlClues: Boolean = false, | ||
) : Puzzleable() { | ||
override suspend fun createPuzzle(): Puzzle { | ||
val originX = solutionGrid[0].indexOfFirst { it != '.' } | ||
|
||
return RowsGarden.createPuzzle( | ||
title = title, | ||
creator = creator, | ||
copyright = copyright, | ||
description = description, | ||
solutionGrid = solutionGrid, | ||
rows = arrows, | ||
light = light, | ||
medium = medium, | ||
dark = dark, | ||
lightColor = lightHeartColor, | ||
mediumColor = mediumHeartColor, | ||
darkColor = darkHeartColor, | ||
addWordCount = addWordCount, | ||
addHyphenated = addHyphenated, | ||
hasHtmlClues = hasHtmlClues, | ||
rowsListTitle = "Arrows", | ||
bloomsListTitle = "Hearts", | ||
emptyCellType = Puzzle.CellType.VOID, | ||
bloomTypeForCoordinate = { x, y -> | ||
val heartTopLeft = when ((3 * y - x + originX).mod(8)) { | ||
0 -> x to y | ||
1 -> x - 2 to y - 1 | ||
2 -> x - 1 to y - 1 | ||
3 -> x to y - 1 | ||
4 -> x - 2 to y - 2 | ||
5 -> x - 1 to y - 2 | ||
6 -> x to y - 2 | ||
else -> x - 1 to y | ||
} | ||
val heartX = (heartTopLeft.first + heartTopLeft.second - originX) / 4 | ||
val heartY = (3 * heartTopLeft.second - heartTopLeft.first + originX) / 8 | ||
when ((heartX + heartY).mod(3)) { | ||
0 -> RowsGarden.BloomType.DARK | ||
1 -> RowsGarden.BloomType.LIGHT | ||
else -> RowsGarden.BloomType.MEDIUM | ||
} | ||
}, | ||
isStartOfBloom = { x, y -> (3 * y - x + originX).mod(8) == 7 }, | ||
getBloomCoordinates = { x, y -> | ||
listOf( | ||
Puzzle.Coordinate(x = x - 1, y = y), | ||
Puzzle.Coordinate(x = x, y = y), | ||
Puzzle.Coordinate(x = x, y = y + 1), | ||
Puzzle.Coordinate(x = x + 1, y = y + 1), | ||
Puzzle.Coordinate(x = x + 1, y = y + 2), | ||
Puzzle.Coordinate(x = x, y = y + 2), | ||
Puzzle.Coordinate(x = x - 1, y = y + 2), | ||
Puzzle.Coordinate(x = x - 1, y = y + 1), | ||
) | ||
}, | ||
) | ||
} | ||
} |
Oops, something went wrong.