Skip to content

Commit

Permalink
Merge pull request #32 from k-gerner/word-hunt-new-board-sizes
Browse files Browse the repository at this point in the history
- Adds support for the following board layouts:
  - 5x5
  - Donut
  - Cross (X)
- Adds the following optional command line parameters:
  - board
  - display
  - maxWordLength
- General code cleanup
  • Loading branch information
k-gerner authored Oct 20, 2024
2 parents 0cd7c65 + 903f10b commit bef279d
Show file tree
Hide file tree
Showing 20 changed files with 818 additions and 309 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ preserved
---

## 🎮 Word Hunt
You are given a 4x4 grid of letters. To earn points, you connect
You are given a grid of letters. To earn points, you connect
adjacent letters together. This can be in any direction (horizontal,
vertical, diagonal, and combinations of all three). You can't use
the same tile on the grid more than once per word though!
Expand All @@ -181,6 +181,8 @@ words with higher values first
- Diagram mode will display the output as a grid with numbers to
show the order and locations on the board for which you should drag
your finger to create the word
- Four different board layouts to choose from: 4x4, 5x5, Donut, and
Cross
- Output to the terminal will be updated in place instead of
printing lines and lines of output across turns. This can be
disabled if you would like to have all output to the terminal
Expand Down
Binary file added images/Word Hunt/board_layout_prompt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/Word Hunt/sampleDiagramMode2.png
Binary file not shown.
Binary file modified images/Word Hunt/sampleListMode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Word Hunt/sample_4x4_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Word Hunt/sample_5x5_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Word Hunt/sample_cross_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Word Hunt/sample_donut_diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions util/terminaloutput/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@

# Background colors
DARK_GREY_BACKGROUND = '\u001b[48;5;238m' # dark grey; to make lighter, increase 238 to anything 255 or below


def color_text(text: str, color: str) -> str:
"""Returns the text in the specified color."""
return f"{color}{text}{NO_COLOR}"
18 changes: 17 additions & 1 deletion util/terminaloutput/symbols.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
from util.terminaloutput.colors import RED_COLOR, BLUE_COLOR, NO_COLOR
from util.terminaloutput.colors import RED_COLOR, BLUE_COLOR, YELLOW_COLOR, NO_COLOR

ERROR_SYMBOL = f"{RED_COLOR}<!>{NO_COLOR}"
WARN_SYMBOL = f"{YELLOW_COLOR}<!>{NO_COLOR}"
INFO_SYMBOL = f"{BLUE_COLOR}<!>{NO_COLOR}"


def info(text):
"""Prints an info message to the terminal."""
print(f"{INFO_SYMBOL} {text}")


def warn(text):
"""Prints a warning message to the terminal."""
print(f"{WARN_SYMBOL} {text}")


def error(text):
"""Prints an error message to the terminal."""
print(f"{ERROR_SYMBOL} {text}")
47 changes: 32 additions & 15 deletions wordhunt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img src="/images/Word%20Hunt/sampleWordHuntBoard.jpeg" alt = "sample board" width="40%" align = "right">

### The Basics
In Word Hunt, players are presented with a 4x4 board of letter tiles.
In Word Hunt, players are presented with a board of letter tiles.
In order to earn points, players must connect adjacent tiles on the
board to form English words. The longer the word, the more points
the player earns. Whoever scores more points in 80 seconds wins.
Expand All @@ -12,31 +12,48 @@ First, download this project. You can invoke the tool by running
```
> python3 ai_runner.py --game=wordhunt
```
Once you do this, you will be prompted about the maximum word length.
The default length is 10, which means the tool will look for words
that are between 3 and 10 letters long, inclusive.
Once you do this, you will be prompted for which board layout to use.
There are four options: 4x4 (default), 5x5, Donut, and Cross.

<img src="/images/Word%20Hunt/board_layout_prompt.png" alt = "board layout prompt" width = "40%">

Next, you will be prompted about which display mode you would like to
use: `Diagram Mode`, or `List Mode`. Typing `i` will give you more
information about each of them.
use: `Diagram Mode` (default), or `List Mode`. Typing `i` will give you
more information about each of them.
#### Diagram Mode
Diagram mode will display each word one at a time, along with a
visual representation of the board which shows the user the path
they should take to connect the letters. Longer words will be
displayed first.

<img src="/images/Word%20Hunt/sampleDiagramMode2.png" alt = "sample diagram mode" width = "40%">
<img src="/images/Word%20Hunt/sample_4x4_diagram_with_prompt.png" alt = "sample diagram mode" width = "40%">

#### List Mode
List mode will display every possible word on the board all at once,
List mode will display every possible word on the board ten words at a time,
along with the index on the board at which the first letter is located.
Longer words will be displayed first.
Longer words will be displayed first. A diagram showing the location of the
tile indices will also be displayed.

<img src="/images/Word%20Hunt/sampleListMode.png" alt = "sample list mode" width = "40%">

### ✨ New in Version 1.1
* The output will now be updated in place, instead of printing
additional output to the terminal. This can be turned off with the
command line argument `-e` or `-eraseModeOff`.
* In List mode, 10 words will be displayed at a time, instead of
displaying all at once.
### Optional Command Line Arguments
* `--board` - Allows the user to specify which board layout they would like
to use. Options are `4x4`, `5x5`, `donut`, and `cross`.
* `--display` - Allows the user to specify which display mode they would
like to use. Options are `diagram` and `list`.
* `--maxWordLength` - Allows the user to specify the maximum word length
they would like to use. Default is 10, with a range of 3-10.

### ✨ New in Latest Version
* Added support for three new board sizes (5x5, Donut, and Cross)! See
images below for examples of each board type.
* Added support for an optional `--board` flag.
* Added support for an optional `--display` flag.
* You will now not be prompted for the max word length. If you wish to use
a length different than the default (10), you can specify it with the
`--maxWordLength` flag (range 3-10).

<img src="/images/Word%20Hunt/sample_4x4_diagram.png" alt = "4x4 board" width = "40%" align="left">
<img src="/images/Word%20Hunt/sample_5x5_diagram.png" alt = "5x5 board" width = "40%" align="left">
<img src="/images/Word%20Hunt/sample_donut_diagram.png" alt = "donut board" width = "40%" align="left">
<img src="/images/Word%20Hunt/sample_cross_diagram.png" alt = "cross board" width = "40%" align="left">
107 changes: 107 additions & 0 deletions wordhunt/board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Kyle Gerner
# 2.24.2021
from util.terminaloutput.colors import YELLOW_COLOR, color_text


class Board(object):
""" Parent class different representations of a Word Hunt board """
diagram_output_height = 0
row_sizes = None
name = None

def __init__(self, letters_arr):
""" takes in an array of Letter objects and sets lb """
self.lb = letters_arr # lb = letter board
self.directionDict = {
0: self.peek_upper_left,
1: self.peek_up,
2: self.peek_upper_right,
3: self.peek_right,
4: self.peek_lower_right,
5: self.peek_down,
6: self.peek_lower_left,
7: self.peek_left
}

def copy_board(self):
""" return a copy of the board as is """
new_arr = []
for i in self.lb:
new_arr.append(i.copyLetter())
return self.__class__(new_arr)

def peek_upper_left(self, pos):
""" look at letter to the upper left but do not mark as visited """
raise NotImplementedError

def peek_up(self, pos):
""" look at letter above but do not mark as visited """
raise NotImplementedError

def peek_upper_right(self, pos):
""" look at letter to the upper right but do not mark as visited """
raise NotImplementedError

def peek_right(self, pos):
""" look at letter to the right but do not mark as visited"""
raise NotImplementedError

def peek_lower_right(self, pos):
""" look at letter to the lower right but do not mark as visited """
raise NotImplementedError

def peek_down(self, pos):
""" look at letter below but do not mark as visited """
raise NotImplementedError

def peek_lower_left(self, pos):
""" look at letter to lower left but do not mark as visited """
raise NotImplementedError

def peek_left(self, pos):
""" look at letter to the left but do not mark as visited"""
raise NotImplementedError

def build_diagram(self, positions, word, word_num):
""" returns the string representation of the board """
raise NotImplementedError

def letter_indices_layout(self):
"""
returns the string representation the indices of letters on the board;
only available for square boards
"""
raise NotImplementedError

def board_letters_layout(self):
"""
returns the string representation of the letters on the board
"""
raise NotImplementedError

def visit_direction(self, pos, dir):
"""
look at letter in specified direction and mark as visited
returns -1 on fail
"""
visited_letter = self.directionDict[dir](pos) # calls the correct function depending on value of dir
if visited_letter == -1 or visited_letter.visited:
# if unable to look that direction or the letter was already visited
return -1
visited_letter.markVisited()
return visited_letter


def populate_diagram_squares(size, positions):
"""
Fills a list of strings representing board tiles' inner text
"""
squares = ["____"] * size
for letter_count, letter_pos in enumerate(positions, 1):
left_underscores = "__" if letter_count < 10 else "_"
if letter_count == 1:
colored_count = color_text(str(letter_count), YELLOW_COLOR)
squares[letter_pos] = f"{left_underscores}{colored_count}_"
else:
squares[letter_pos] = f"{left_underscores}{letter_count}_"
return squares
115 changes: 0 additions & 115 deletions wordhunt/classes.py

This file was deleted.

Loading

0 comments on commit bef279d

Please sign in to comment.