Skip to content

Commit bcc58a1

Browse files
authored
Merge pull request #45 from FlysonBot/dev
Dev
2 parents 119cede + ca945c1 commit bcc58a1

File tree

15 files changed

+595
-25
lines changed

15 files changed

+595
-25
lines changed

.github/workflows/deploy_sphinx.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,3 @@ jobs:
4444
with:
4545
github_token: ${{ secrets.GITHUB_TOKEN }}
4646
publish_dir: ./docs/build/html
47-
publish_branch: gh-pages
48-
keep_files: false # remove old files

.github/workflows/ossf_scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push:
44
branches:
55
- main
6-
pull_request:
6+
pull_request_target:
77
branches:
88
- main
99
workflow_dispatch:

examples/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Examples
2+
3+
## Running Locally: One-click Install
4+
5+
In this directory, there is an `install.bat` and `install.sh` file. These files will install the required dependencies and run the program, including python 3.10.12 (or higher), pip, and mastermind-ai.
6+
7+
- If you're using a windows machine, download and double click to run `install.bat`.
8+
- Otherwise, download and run `install.sh` in your terminal by:
9+
10+
```bash
11+
cd "<path-to-directory>"
12+
chmod +x install.sh
13+
./install.sh
14+
```
15+
16+
Replace `<path-to-directory>` with the actual path to the directory containing `install.sh`, or ignore it if you already opened your terminal in the directory.
17+
18+
## Running Remotely: Google Colab
19+
20+
- Open [this link](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/examples/mastermind_in_colab.ipynb) to open the program in Google Colab.
21+
22+
## Update the Local Version
23+
24+
To update the local version, simply run the installation script again.
25+
26+
## Uninstall Local Version
27+
28+
There is an `uninstall.bat` and `uninstall.sh` file in this directory. These files will uninstall mastermind-ai, but will not uninstall the Python and the other dependencies.

examples/install.bat

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
@echo off
2+
setlocal
3+
4+
:check_python
5+
rem Check for Python installation
6+
python --version >nul 2>&1
7+
if %errorlevel% neq 0 (
8+
echo Python is not installed.
9+
set /p install_python="Do you want to install Python 3.10.12? (y/n): "
10+
if /i "%install_python%"=="y" (
11+
call :install_python
12+
) else (
13+
echo Exiting.
14+
exit /b
15+
)
16+
) else (
17+
for /f "tokens=2 delims=." %%a in ('python --version') do (
18+
if %%a lss 10 (
19+
echo Python version is less than 3.10.
20+
set /p update_python="Do you want to update to Python 3.10.12? (y/n): "
21+
if /i "%update_python%"=="y" (
22+
call :install_python
23+
) else (
24+
echo Exiting.
25+
exit /b
26+
)
27+
) else (
28+
call :upgrade_pip
29+
)
30+
)
31+
)
32+
33+
:install_python
34+
echo Installing Python 3.10.12 using winget...
35+
start /wait winget install Python.Python.3.10 --silent
36+
goto :upgrade_pip
37+
38+
:upgrade_pip
39+
rem Upgrade pip
40+
python -m pip install --upgrade pip
41+
goto :check_mastermind_ai
42+
43+
:check_mastermind_ai
44+
rem Check if mastermind-ai is installed
45+
pip show mastermind-ai >nul 2>&1
46+
if %errorlevel% neq 0 (
47+
echo mastermind-ai is not installed. Installing...
48+
pip install mastermind-ai
49+
) else (
50+
echo mastermind-ai is already installed.
51+
python -m pip list --outdated | findstr mastermind-ai >nul
52+
if %errorlevel% == 0 (
53+
set /p update_package="An update for mastermind-ai is available. Do you want to update it? (y/n): "
54+
if /i "%update_package%"=="y" (
55+
pip install --upgrade mastermind-ai
56+
)
57+
)
58+
)
59+
60+
rem Clear the screen and run mastermind
61+
cls
62+
mastermind
63+
endlocal

examples/install.sh

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/bin/bash
2+
3+
check_python() {
4+
# Check for Python installation
5+
if ! command -v python3 &>/dev/null; then
6+
echo "Python is not installed."
7+
read -p "Do you want to install Python 3.10.12? (y/n): " install_python
8+
if [[ "$install_python" == "y" ]]; then
9+
install_python
10+
else
11+
echo "Exiting."
12+
exit 1
13+
fi
14+
else
15+
PYTHON_VERSION=$(python3 --version | grep -oP '\d+\.\d+')
16+
if (( $(echo "$PYTHON_VERSION < 3.10" | bc -l) )); then
17+
echo "Python version is less than 3.10."
18+
read -p "Do you want to update to Python 3.10.12? (y/n): " update_python
19+
if [[ "$update_python" == "y" ]]; then
20+
install_python
21+
else
22+
echo "Exiting."
23+
exit 1
24+
fi
25+
fi
26+
fi
27+
}
28+
29+
install_python() {
30+
echo "Installing Python 3.10.12..."
31+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
32+
sudo apt update
33+
sudo apt install -y python3.10 python3-pip
34+
elif [[ "$OSTYPE" == "darwin"* ]]; then
35+
brew install [email protected]
36+
else
37+
echo "Unsupported OS for automatic Python installation."
38+
exit 1
39+
fi
40+
}
41+
42+
upgrade_pip() {
43+
# Upgrade pip
44+
python3 -m pip install --upgrade pip
45+
}
46+
47+
check_mastermind_ai() {
48+
# Check if mastermind-ai is installed
49+
if ! pip show mastermind-ai &>/dev/null; then
50+
echo "mastermind-ai is not installed. Installing..."
51+
pip install mastermind-ai
52+
else
53+
echo "mastermind-ai is already installed."
54+
if pip list --outdated | grep mastermind-ai &>/dev/null; then
55+
read -p "An update for mastermind-ai is available. Do you want to update it? (y/n): " update_package
56+
if [[ "$update_package" == "y" ]]; then
57+
pip install --upgrade mastermind-ai
58+
fi
59+
fi
60+
fi
61+
}
62+
63+
# Main execution
64+
check_python
65+
upgrade_pip # Call to upgrade pip
66+
check_mastermind_ai # Call to check mastermind-ai installation
67+
68+
# Clear the screen and run mastermind
69+
clear
70+
mastermind

examples/uninstall.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pip uninstall mastermind-ai

examples/uninstall.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
pip uninstall mastermind-ai

src/mastermind/main/main.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
class MainUI:
1616
"""Class to handle the user menu interface."""
1717

18-
def __new__(cls):
19-
if not hasattr(cls, "instance"):
20-
cls.instance = super(MainUI, cls).__new__(cls)
21-
return cls.instance
22-
2318
def main_menu(self) -> bool:
2419
"""
2520
Display the main menu and handle user input.
@@ -83,7 +78,7 @@ def run(self):
8378
while self.main_menu():
8479
pass # keep calling self.main_menu() until it return False
8580
print("Thank you for playing!")
86-
userdata._save_data()
81+
userdata.save_data()
8782

8883

8984
def main():

src/mastermind/ui/menu/data_menu.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from abc import abstractmethod
1+
from abc import ABC, abstractmethod
22
from typing import Any, Optional
33

44
from mastermind.ui.menu.base_menu import BaseMenu
55

66

7-
class DataDisplayMenu(BaseMenu):
7+
class DataDisplayMenu(BaseMenu, ABC):
88
"""
99
An abstract base class for menus that display data.
1010
@@ -19,7 +19,7 @@ def _print_content(self) -> None:
1919
if data is not None:
2020
self._render_data(data)
2121
else:
22-
print(self._empty_message())
22+
print(self._empty_message)
2323

2424
@abstractmethod
2525
def _fetch_data(self) -> Optional[Any]:

src/mastermind/ui/menu/game_history_menu.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class GameHistoryMenu(DataDisplayMenu):
1414

1515
name = "Game History"
1616
width = 25
17+
_empty_message = "No game history found."
1718

1819
def _fetch_data(self) -> Optional[pd.DataFrame]:
1920
"""
@@ -27,12 +28,6 @@ def _render_data(self, data: pd.DataFrame) -> None:
2728
"""
2829
render_dataframe(data)
2930

30-
def _empty_message(self) -> str:
31-
"""
32-
Returns the message to display when there is no game history.
33-
"""
34-
return "No game history found."
35-
3631
def display(self) -> None:
3732
"""
3833
Displays the game history menu and waits for user input to continue.

0 commit comments

Comments
 (0)