From f7b4d7ac4e3a216f033477d09eb36f57dcf3687a Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 14:19:41 -0400 Subject: [PATCH 01/17] Pass len(10) test --- adagrams/game.py | 2 +- source/bin/Activate.ps1 | 241 +++++++++++++++++++++++++++++++++++++++ source/bin/activate | 66 +++++++++++ source/bin/activate.csh | 25 ++++ source/bin/activate.fish | 64 +++++++++++ source/bin/pip | 8 ++ source/bin/pip3 | 8 ++ source/bin/pip3.9 | 8 ++ source/bin/py.test | 8 ++ source/bin/pytest | 8 ++ source/bin/python | 1 + source/bin/python3 | 1 + source/bin/python3.9 | 1 + source/pyvenv.cfg | 3 + 14 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 source/bin/Activate.ps1 create mode 100644 source/bin/activate create mode 100644 source/bin/activate.csh create mode 100644 source/bin/activate.fish create mode 100755 source/bin/pip create mode 100755 source/bin/pip3 create mode 100755 source/bin/pip3.9 create mode 100755 source/bin/py.test create mode 100755 source/bin/pytest create mode 120000 source/bin/python create mode 120000 source/bin/python3 create mode 120000 source/bin/python3.9 create mode 100644 source/pyvenv.cfg diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..4a762242 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,5 @@ def draw_letters(): - pass + return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] def uses_available_letters(word, letter_bank): pass diff --git a/source/bin/Activate.ps1 b/source/bin/Activate.ps1 new file mode 100644 index 00000000..2fb3852c --- /dev/null +++ b/source/bin/Activate.ps1 @@ -0,0 +1,241 @@ +<# +.Synopsis +Activate a Python virtual environment for the current PowerShell session. + +.Description +Pushes the python executable for a virtual environment to the front of the +$Env:PATH environment variable and sets the prompt to signify that you are +in a Python virtual environment. Makes use of the command line switches as +well as the `pyvenv.cfg` file values present in the virtual environment. + +.Parameter VenvDir +Path to the directory that contains the virtual environment to activate. The +default value for this is the parent of the directory that the Activate.ps1 +script is located within. + +.Parameter Prompt +The prompt prefix to display when this virtual environment is activated. By +default, this prompt is the name of the virtual environment folder (VenvDir) +surrounded by parentheses and followed by a single space (ie. '(.venv) '). + +.Example +Activate.ps1 +Activates the Python virtual environment that contains the Activate.ps1 script. + +.Example +Activate.ps1 -Verbose +Activates the Python virtual environment that contains the Activate.ps1 script, +and shows extra information about the activation as it executes. + +.Example +Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv +Activates the Python virtual environment located in the specified location. + +.Example +Activate.ps1 -Prompt "MyPython" +Activates the Python virtual environment that contains the Activate.ps1 script, +and prefixes the current prompt with the specified string (surrounded in +parentheses) while the virtual environment is active. + +.Notes +On Windows, it may be required to enable this Activate.ps1 script by setting the +execution policy for the user. You can do this by issuing the following PowerShell +command: + +PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser + +For more information on Execution Policies: +https://go.microsoft.com/fwlink/?LinkID=135170 + +#> +Param( + [Parameter(Mandatory = $false)] + [String] + $VenvDir, + [Parameter(Mandatory = $false)] + [String] + $Prompt +) + +<# Function declarations --------------------------------------------------- #> + +<# +.Synopsis +Remove all shell session elements added by the Activate script, including the +addition of the virtual environment's Python executable from the beginning of +the PATH variable. + +.Parameter NonDestructive +If present, do not remove this function from the global namespace for the +session. + +#> +function global:deactivate ([switch]$NonDestructive) { + # Revert to original values + + # The prior prompt: + if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) { + Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt + Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT + } + + # The prior PYTHONHOME: + if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) { + Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME + Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME + } + + # The prior PATH: + if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) { + Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH + Remove-Item -Path Env:_OLD_VIRTUAL_PATH + } + + # Just remove the VIRTUAL_ENV altogether: + if (Test-Path -Path Env:VIRTUAL_ENV) { + Remove-Item -Path env:VIRTUAL_ENV + } + + # Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether: + if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) { + Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force + } + + # Leave deactivate function in the global namespace if requested: + if (-not $NonDestructive) { + Remove-Item -Path function:deactivate + } +} + +<# +.Description +Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the +given folder, and returns them in a map. + +For each line in the pyvenv.cfg file, if that line can be parsed into exactly +two strings separated by `=` (with any amount of whitespace surrounding the =) +then it is considered a `key = value` line. The left hand string is the key, +the right hand is the value. + +If the value starts with a `'` or a `"` then the first and last character is +stripped from the value before being captured. + +.Parameter ConfigDir +Path to the directory that contains the `pyvenv.cfg` file. +#> +function Get-PyVenvConfig( + [String] + $ConfigDir +) { + Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg" + + # Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue). + $pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue + + # An empty map will be returned if no config file is found. + $pyvenvConfig = @{ } + + if ($pyvenvConfigPath) { + + Write-Verbose "File exists, parse `key = value` lines" + $pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath + + $pyvenvConfigContent | ForEach-Object { + $keyval = $PSItem -split "\s*=\s*", 2 + if ($keyval[0] -and $keyval[1]) { + $val = $keyval[1] + + # Remove extraneous quotations around a string value. + if ("'""".Contains($val.Substring(0, 1))) { + $val = $val.Substring(1, $val.Length - 2) + } + + $pyvenvConfig[$keyval[0]] = $val + Write-Verbose "Adding Key: '$($keyval[0])'='$val'" + } + } + } + return $pyvenvConfig +} + + +<# Begin Activate script --------------------------------------------------- #> + +# Determine the containing directory of this script +$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition +$VenvExecDir = Get-Item -Path $VenvExecPath + +Write-Verbose "Activation script is located in path: '$VenvExecPath'" +Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)" +Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)" + +# Set values required in priority: CmdLine, ConfigFile, Default +# First, get the location of the virtual environment, it might not be +# VenvExecDir if specified on the command line. +if ($VenvDir) { + Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values" +} +else { + Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir." + $VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/") + Write-Verbose "VenvDir=$VenvDir" +} + +# Next, read the `pyvenv.cfg` file to determine any required value such +# as `prompt`. +$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir + +# Next, set the prompt from the command line, or the config file, or +# just use the name of the virtual environment folder. +if ($Prompt) { + Write-Verbose "Prompt specified as argument, using '$Prompt'" +} +else { + Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value" + if ($pyvenvCfg -and $pyvenvCfg['prompt']) { + Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'" + $Prompt = $pyvenvCfg['prompt']; + } + else { + Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virutal environment)" + Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'" + $Prompt = Split-Path -Path $venvDir -Leaf + } +} + +Write-Verbose "Prompt = '$Prompt'" +Write-Verbose "VenvDir='$VenvDir'" + +# Deactivate any currently active virtual environment, but leave the +# deactivate function in place. +deactivate -nondestructive + +# Now set the environment variable VIRTUAL_ENV, used by many tools to determine +# that there is an activated venv. +$env:VIRTUAL_ENV = $VenvDir + +if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) { + + Write-Verbose "Setting prompt to '$Prompt'" + + # Set the prompt to include the env name + # Make sure _OLD_VIRTUAL_PROMPT is global + function global:_OLD_VIRTUAL_PROMPT { "" } + Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT + New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt + + function global:prompt { + Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) " + _OLD_VIRTUAL_PROMPT + } +} + +# Clear PYTHONHOME +if (Test-Path -Path Env:PYTHONHOME) { + Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME + Remove-Item -Path Env:PYTHONHOME +} + +# Add the venv to the PATH +Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH +$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH" diff --git a/source/bin/activate b/source/bin/activate new file mode 100644 index 00000000..68fd8f87 --- /dev/null +++ b/source/bin/activate @@ -0,0 +1,66 @@ +# This file must be used with "source bin/activate" *from bash* +# you cannot run it directly + +deactivate () { + # reset old environment variables + if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then + PATH="${_OLD_VIRTUAL_PATH:-}" + export PATH + unset _OLD_VIRTUAL_PATH + fi + if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then + PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}" + export PYTHONHOME + unset _OLD_VIRTUAL_PYTHONHOME + fi + + # This should detect bash and zsh, which have a hash command that must + # be called to get it to forget past commands. Without forgetting + # past commands the $PATH changes we made may not be respected + if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then + hash -r 2> /dev/null + fi + + if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then + PS1="${_OLD_VIRTUAL_PS1:-}" + export PS1 + unset _OLD_VIRTUAL_PS1 + fi + + unset VIRTUAL_ENV + if [ ! "${1:-}" = "nondestructive" ] ; then + # Self destruct! + unset -f deactivate + fi +} + +# unset irrelevant variables +deactivate nondestructive + +VIRTUAL_ENV="/Users/katkodes/Developer/projects/adagrams-py/source" +export VIRTUAL_ENV + +_OLD_VIRTUAL_PATH="$PATH" +PATH="$VIRTUAL_ENV/bin:$PATH" +export PATH + +# unset PYTHONHOME if set +# this will fail if PYTHONHOME is set to the empty string (which is bad anyway) +# could use `if (set -u; : $PYTHONHOME) ;` in bash +if [ -n "${PYTHONHOME:-}" ] ; then + _OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}" + unset PYTHONHOME +fi + +if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then + _OLD_VIRTUAL_PS1="${PS1:-}" + PS1="(source) ${PS1:-}" + export PS1 +fi + +# This should detect bash and zsh, which have a hash command that must +# be called to get it to forget past commands. Without forgetting +# past commands the $PATH changes we made may not be respected +if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then + hash -r 2> /dev/null +fi diff --git a/source/bin/activate.csh b/source/bin/activate.csh new file mode 100644 index 00000000..16865299 --- /dev/null +++ b/source/bin/activate.csh @@ -0,0 +1,25 @@ +# This file must be used with "source bin/activate.csh" *from csh*. +# You cannot run it directly. +# Created by Davide Di Blasi . +# Ported to Python 3.3 venv by Andrew Svetlov + +alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; test "\!:*" != "nondestructive" && unalias deactivate' + +# Unset irrelevant variables. +deactivate nondestructive + +setenv VIRTUAL_ENV "/Users/katkodes/Developer/projects/adagrams-py/source" + +set _OLD_VIRTUAL_PATH="$PATH" +setenv PATH "$VIRTUAL_ENV/bin:$PATH" + + +set _OLD_VIRTUAL_PROMPT="$prompt" + +if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then + set prompt = "(source) $prompt" +endif + +alias pydoc python -m pydoc + +rehash diff --git a/source/bin/activate.fish b/source/bin/activate.fish new file mode 100644 index 00000000..4e467f06 --- /dev/null +++ b/source/bin/activate.fish @@ -0,0 +1,64 @@ +# This file must be used with "source /bin/activate.fish" *from fish* +# (https://fishshell.com/); you cannot run it directly. + +function deactivate -d "Exit virtual environment and return to normal shell environment" + # reset old environment variables + if test -n "$_OLD_VIRTUAL_PATH" + set -gx PATH $_OLD_VIRTUAL_PATH + set -e _OLD_VIRTUAL_PATH + end + if test -n "$_OLD_VIRTUAL_PYTHONHOME" + set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME + set -e _OLD_VIRTUAL_PYTHONHOME + end + + if test -n "$_OLD_FISH_PROMPT_OVERRIDE" + functions -e fish_prompt + set -e _OLD_FISH_PROMPT_OVERRIDE + functions -c _old_fish_prompt fish_prompt + functions -e _old_fish_prompt + end + + set -e VIRTUAL_ENV + if test "$argv[1]" != "nondestructive" + # Self-destruct! + functions -e deactivate + end +end + +# Unset irrelevant variables. +deactivate nondestructive + +set -gx VIRTUAL_ENV "/Users/katkodes/Developer/projects/adagrams-py/source" + +set -gx _OLD_VIRTUAL_PATH $PATH +set -gx PATH "$VIRTUAL_ENV/bin" $PATH + +# Unset PYTHONHOME if set. +if set -q PYTHONHOME + set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME + set -e PYTHONHOME +end + +if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" + # fish uses a function instead of an env var to generate the prompt. + + # Save the current fish_prompt function as the function _old_fish_prompt. + functions -c fish_prompt _old_fish_prompt + + # With the original prompt function renamed, we can override with our own. + function fish_prompt + # Save the return status of the last command. + set -l old_status $status + + # Output the venv prompt; color taken from the blue of the Python logo. + printf "%s%s%s" (set_color 4B8BBE) "(source) " (set_color normal) + + # Restore the return status of the previous command. + echo "exit $old_status" | . + # Output the original/"old" prompt. + _old_fish_prompt + end + + set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" +end diff --git a/source/bin/pip b/source/bin/pip new file mode 100755 index 00000000..ebd262fa --- /dev/null +++ b/source/bin/pip @@ -0,0 +1,8 @@ +#!/Users/katkodes/Developer/projects/adagrams-py/source/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/source/bin/pip3 b/source/bin/pip3 new file mode 100755 index 00000000..ebd262fa --- /dev/null +++ b/source/bin/pip3 @@ -0,0 +1,8 @@ +#!/Users/katkodes/Developer/projects/adagrams-py/source/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/source/bin/pip3.9 b/source/bin/pip3.9 new file mode 100755 index 00000000..ebd262fa --- /dev/null +++ b/source/bin/pip3.9 @@ -0,0 +1,8 @@ +#!/Users/katkodes/Developer/projects/adagrams-py/source/bin/python3 +# -*- coding: utf-8 -*- +import re +import sys +from pip._internal.cli.main import main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(main()) diff --git a/source/bin/py.test b/source/bin/py.test new file mode 100755 index 00000000..fe0cc3fc --- /dev/null +++ b/source/bin/py.test @@ -0,0 +1,8 @@ +#!/Users/katkodes/Developer/projects/adagrams-py/source/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from pytest import console_main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(console_main()) diff --git a/source/bin/pytest b/source/bin/pytest new file mode 100755 index 00000000..fe0cc3fc --- /dev/null +++ b/source/bin/pytest @@ -0,0 +1,8 @@ +#!/Users/katkodes/Developer/projects/adagrams-py/source/bin/python +# -*- coding: utf-8 -*- +import re +import sys +from pytest import console_main +if __name__ == '__main__': + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) + sys.exit(console_main()) diff --git a/source/bin/python b/source/bin/python new file mode 120000 index 00000000..b8a0adbb --- /dev/null +++ b/source/bin/python @@ -0,0 +1 @@ +python3 \ No newline at end of file diff --git a/source/bin/python3 b/source/bin/python3 new file mode 120000 index 00000000..f25545fe --- /dev/null +++ b/source/bin/python3 @@ -0,0 +1 @@ +/Library/Developer/CommandLineTools/usr/bin/python3 \ No newline at end of file diff --git a/source/bin/python3.9 b/source/bin/python3.9 new file mode 120000 index 00000000..b8a0adbb --- /dev/null +++ b/source/bin/python3.9 @@ -0,0 +1 @@ +python3 \ No newline at end of file diff --git a/source/pyvenv.cfg b/source/pyvenv.cfg new file mode 100644 index 00000000..4760c1ff --- /dev/null +++ b/source/pyvenv.cfg @@ -0,0 +1,3 @@ +home = /Library/Developer/CommandLineTools/usr/bin +include-system-site-packages = false +version = 3.9.6 From 31dc34b3ba0445ef137ce44b94bf553e9b58117b Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 14:21:39 -0400 Subject: [PATCH 02/17] Changed draw_letters to return list of 10 strings --- adagrams/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 4a762242..c9d49d5e 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,5 @@ def draw_letters(): - return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + return ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] def uses_available_letters(word, letter_bank): pass From 3339f523f712062d8d516a6979439ec3629e8742 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 14:28:27 -0400 Subject: [PATCH 03/17] Change draw_letters to return list of 10 capital letters --- adagrams/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index c9d49d5e..b25c2967 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,5 @@ def draw_letters(): - return ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a'] + return ['A', 'Z', 'B', 'Q', 'L', 'M', 'C', 'D', 'F', 'R'] def uses_available_letters(word, letter_bank): pass From c4441e532574a13ce5191a49ca9af4f5c7dac6f1 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 15:03:42 -0400 Subject: [PATCH 04/17] Change data structure holding letters to set, returns dictionary with unique items --- adagrams/game.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index b25c2967..dd6f5bf1 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,5 +1,40 @@ +import random + def draw_letters(): - return ['A', 'Z', 'B', 'Q', 'L', 'M', 'C', 'D', 'F', 'R'] + pool = { + 'A': 9, + 'B': 2, + 'C': 2, + 'D': 4, + 'E': 12, + 'F': 2, + 'G': 3, + 'H': 2, + 'I': 9, + 'J': 1, + 'K': 1, + 'L': 4, + 'M': 2, + 'N': 6, + 'O': 8, + 'P': 2, + 'Q': 1, + 'R': 6, + 'S': 4, + 'T': 6, + 'U': 4, + 'V': 2, + 'W': 2, + 'X': 1, + 'Y': 2, + 'Z': 1 +} + random_letter_set = set() + while len(random_letter_set) < 10: + random_letter = random.choice(list(pool.keys())) + random_letter_set.add(random_letter) + + return random_letter_set def uses_available_letters(word, letter_bank): pass From f22fc3ade1c05fbf51604cac933f99547813dbee Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 15:09:13 -0400 Subject: [PATCH 05/17] Add function to check if word in letter bank --- adagrams/game.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index dd6f5bf1..0aa6da11 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -37,7 +37,9 @@ def draw_letters(): return random_letter_set def uses_available_letters(word, letter_bank): - pass + for letter in word: + if letter in letter_bank: + return True def score_word(word): pass From ab17d6b11e6fac3ebeaebb910c40b680e6d88342 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 15:12:50 -0400 Subject: [PATCH 06/17] Cahnge function to check letters in letter bank --- adagrams/game.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 0aa6da11..fc9cd807 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -38,8 +38,9 @@ def draw_letters(): def uses_available_letters(word, letter_bank): for letter in word: - if letter in letter_bank: - return True + if letter not in letter_bank: + return False + def score_word(word): pass From 7965655ed44af3de7893d09e9da0b8babd757bf9 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 17:53:12 -0400 Subject: [PATCH 07/17] Create letter frequency counter in uses_available_letters --- adagrams/game.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/adagrams/game.py b/adagrams/game.py index fc9cd807..8a08e5a2 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -36,10 +36,26 @@ def draw_letters(): return random_letter_set +def frequency_maker(list): + pass + def uses_available_letters(word, letter_bank): + letter_frequency = {} for letter in word: + if letter in letter_frequency.keys(): + letter_frequency[letter] += 1 + else: + letter_frequency[letter] = 1 + if letter not in letter_bank: return False + + for character in letter_bank: + if character in letter_frequency.keys(): + if letter_frequency[character] != letter_bank.count(character): + return False + + def score_word(word): From 09bee0cf57ff31efdad259f0927cb73c889b4c8e Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 17:58:01 -0400 Subject: [PATCH 08/17] Add return value of True if all conditions met --- adagrams/game.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 8a08e5a2..b16c51bd 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -40,6 +40,7 @@ def frequency_maker(list): pass def uses_available_letters(word, letter_bank): + word = word.upper() letter_frequency = {} for letter in word: if letter in letter_frequency.keys(): @@ -54,7 +55,7 @@ def uses_available_letters(word, letter_bank): if character in letter_frequency.keys(): if letter_frequency[character] != letter_bank.count(character): return False - + return True From 25d1dbcd89a3de4a49a68ba37660e8a9ba912674 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 18:27:40 -0400 Subject: [PATCH 09/17] Revise 1st test suite to account for letter frequency --- adagrams/game.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index b16c51bd..398bc891 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -29,12 +29,15 @@ def draw_letters(): 'Y': 2, 'Z': 1 } - random_letter_set = set() - while len(random_letter_set) < 10: - random_letter = random.choice(list(pool.keys())) - random_letter_set.add(random_letter) + frequency_list = [] + for letter, frequency in pool.items(): + frequency_list += letter * frequency + random_letter_list = [] + while len(random_letter_list) < 10: + random_letter = random.choice(frequency_list) + random_letter_list.append(random_letter) - return random_letter_set + return random_letter_list def frequency_maker(list): pass From e01b86ba04790cc8d14d1da9605c6f4f6274dbfa Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 17 Mar 2023 19:30:07 -0400 Subject: [PATCH 10/17] Adjust test wave 1 to account for frequency completed --- adagrams/game.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adagrams/game.py b/adagrams/game.py index 398bc891..2a5c800f 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -35,6 +35,7 @@ def draw_letters(): random_letter_list = [] while len(random_letter_list) < 10: random_letter = random.choice(frequency_list) + frequency_list.remove(random_letter) random_letter_list.append(random_letter) return random_letter_list From 2badfdd0fd7000167b8cd36110dfc286c3a9c95b Mon Sep 17 00:00:00 2001 From: Kat Date: Sat, 18 Mar 2023 12:05:25 -0400 Subject: [PATCH 11/17] Finish score_word scoring system --- adagrams/game.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 2a5c800f..bbf05556 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -30,9 +30,11 @@ def draw_letters(): 'Z': 1 } frequency_list = [] + random_letter_list = [] +# adds letter to frequency_list based on the desired frequency for letter, frequency in pool.items(): frequency_list += letter * frequency - random_letter_list = [] + while len(random_letter_list) < 10: random_letter = random.choice(frequency_list) frequency_list.remove(random_letter) @@ -64,7 +66,22 @@ def uses_available_letters(word, letter_bank): def score_word(word): - pass + scoring_system = { + 1: ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], + 2: ['D', 'G'], + 3: ['B', 'C', 'M', 'P'], + 4: ['F', 'H', 'V', 'W', 'Y'], + 5: ['K'], + 8: ['J', 'X'], + 10: ['Q', 'Z'] + } + word_score = 0 + for letter in word: + letter = letter.upper() + for score, letters in scoring_system.items(): + if letter in letters: + word_score += score + return word_score def get_highest_word_score(word_list): pass \ No newline at end of file From 2cb0c8b9d94a6768775813579bbdf04306a01ae8 Mon Sep 17 00:00:00 2001 From: Kat Date: Sat, 18 Mar 2023 12:34:36 -0400 Subject: [PATCH 12/17] Add function to calculate highest score of word list --- adagrams/game.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index bbf05556..7fd9cf80 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -76,12 +76,34 @@ def score_word(word): 10: ['Q', 'Z'] } word_score = 0 + for letter in word: letter = letter.upper() for score, letters in scoring_system.items(): if letter in letters: word_score += score + + #bonus if word is between 7 to 10 characters + if 7 <= len(word) <=10: + word_score += 8 + return word_score def get_highest_word_score(word_list): - pass \ No newline at end of file + words_with_scores = [] + + for word in word_list: + word_score = score_word(word) + words_with_scores.append({word:word_score}) + + highest_score = 0 + highest_score_word = "" + + for pair in words_with_scores: + for word, word_score in pair.items(): + if word_score > highest_score: + highest_score_word = word + highest_score = word_score + + return (highest_score_word, highest_score) + From 8d38788670ced0fce21b6e43f2921ff23ec9da76 Mon Sep 17 00:00:00 2001 From: Kat Date: Sat, 18 Mar 2023 12:53:47 -0400 Subject: [PATCH 13/17] Add function to pass test wave 4 --- adagrams/game.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7fd9cf80..7522e499 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -98,10 +98,15 @@ def get_highest_word_score(word_list): highest_score = 0 highest_score_word = "" - + for pair in words_with_scores: for word, word_score in pair.items(): - if word_score > highest_score: + if word_score >= highest_score and len(word) == 10: + return (word, word_score) + elif word_score == highest_score and len(word) < len(highest_score_word): + highest_score_word = word + highest_score = word_score + elif word_score > highest_score: highest_score_word = word highest_score = word_score From 28a75bd31e465b531036d6472aa702cdd24b08bc Mon Sep 17 00:00:00 2001 From: Kat Date: Sat, 18 Mar 2023 14:55:27 -0400 Subject: [PATCH 14/17] Fix bug in conditional flow uses_available_letters --- adagrams/game.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 7522e499..b133f883 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -42,25 +42,24 @@ def draw_letters(): return random_letter_list -def frequency_maker(list): - pass - def uses_available_letters(word, letter_bank): word = word.upper() - letter_frequency = {} - for letter in word: - if letter in letter_frequency.keys(): - letter_frequency[letter] += 1 - else: - letter_frequency[letter] = 1 + letter_bank_letter_frequency = {} + for letter in word: if letter not in letter_bank: return False + + if letter in letter_bank_letter_frequency.keys(): + letter_bank_letter_frequency[letter] += 1 + else: + letter_bank_letter_frequency[letter] = 1 - for character in letter_bank: - if character in letter_frequency.keys(): - if letter_frequency[character] != letter_bank.count(character): + for character in word: + if character in letter_bank_letter_frequency.keys(): + if letter_bank_letter_frequency[character] != letter_bank.count(character): return False + return True @@ -75,6 +74,7 @@ def score_word(word): 8: ['J', 'X'], 10: ['Q', 'Z'] } + word_score = 0 for letter in word: From e01385ce98c35681ec13d27cd99b1fb693f238e4 Mon Sep 17 00:00:00 2001 From: Kat Date: Sat, 18 Mar 2023 15:09:46 -0400 Subject: [PATCH 15/17] Change conditional statement in uses_available_letters to fix logic --- adagrams/game.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index b133f883..ebee752d 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -57,7 +57,7 @@ def uses_available_letters(word, letter_bank): for character in word: if character in letter_bank_letter_frequency.keys(): - if letter_bank_letter_frequency[character] != letter_bank.count(character): + if letter_bank_letter_frequency[character] > letter_bank.count(character): return False return True From 2e1674be37f1146cae0b44d235279b1eed5cf5dc Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 20 Mar 2023 14:03:07 -0400 Subject: [PATCH 16/17] Refactor suite 2 and 4 --- adagrams/game.py | 56 ++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index ebee752d..adc280e4 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,7 +1,8 @@ import random +import copy def draw_letters(): - pool = { + letter_pool = { 'A': 9, 'B': 2, 'C': 2, @@ -30,39 +31,28 @@ def draw_letters(): 'Z': 1 } frequency_list = [] - random_letter_list = [] + hand = [] # adds letter to frequency_list based on the desired frequency - for letter, frequency in pool.items(): + for letter, frequency in letter_pool.items(): frequency_list += letter * frequency - while len(random_letter_list) < 10: + while len(hand) < 10: random_letter = random.choice(frequency_list) + #random.choice doing something..then loop frequency_list.remove(random_letter) - random_letter_list.append(random_letter) + hand.append(random_letter) - return random_letter_list + return hand def uses_available_letters(word, letter_bank): - word = word.upper() - letter_bank_letter_frequency = {} + letter_bank_copy = copy.deepcopy(letter_bank) - for letter in word: - if letter not in letter_bank: + for letter in word.upper(): + if letter not in letter_bank_copy: return False - - if letter in letter_bank_letter_frequency.keys(): - letter_bank_letter_frequency[letter] += 1 - else: - letter_bank_letter_frequency[letter] = 1 - - for character in word: - if character in letter_bank_letter_frequency.keys(): - if letter_bank_letter_frequency[character] > letter_bank.count(character): - return False - + elif letter in letter_bank_copy: + letter_bank_copy.remove(letter) return True - - def score_word(word): scoring_system = { @@ -78,9 +68,8 @@ def score_word(word): word_score = 0 for letter in word: - letter = letter.upper() for score, letters in scoring_system.items(): - if letter in letters: + if letter.upper() in letters: word_score += score #bonus if word is between 7 to 10 characters @@ -96,19 +85,16 @@ def get_highest_word_score(word_list): word_score = score_word(word) words_with_scores.append({word:word_score}) - highest_score = 0 - highest_score_word = "" + highest_score_with_word = ("", 0) for pair in words_with_scores: for word, word_score in pair.items(): - if word_score >= highest_score and len(word) == 10: + if word_score >= highest_score_with_word[1] and len(word) == 10: return (word, word_score) - elif word_score == highest_score and len(word) < len(highest_score_word): - highest_score_word = word - highest_score = word_score - elif word_score > highest_score: - highest_score_word = word - highest_score = word_score + elif word_score == highest_score_with_word[1] and len(word) < len(highest_score_with_word[0]): + highest_score_with_word = (word, word_score) + elif word_score > highest_score_with_word[1]: + highest_score_with_word = (word, word_score) - return (highest_score_word, highest_score) + return highest_score_with_word From a35d885d1997447ff6ff07903b57bcff0f2d8e5d Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 24 Mar 2023 11:11:10 -0400 Subject: [PATCH 17/17] final commit --- adagrams/game.py | 1 - classnotes.txt | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 classnotes.txt diff --git a/adagrams/game.py b/adagrams/game.py index adc280e4..2170b1d0 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -38,7 +38,6 @@ def draw_letters(): while len(hand) < 10: random_letter = random.choice(frequency_list) - #random.choice doing something..then loop frequency_list.remove(random_letter) hand.append(random_letter) diff --git a/classnotes.txt b/classnotes.txt new file mode 100644 index 00000000..7cc07c5a --- /dev/null +++ b/classnotes.txt @@ -0,0 +1,3 @@ +WAVE 1 +random.sample(LETTER_POOL, k = 10) +checked hand for vowels \ No newline at end of file