mastermind-ai 1.6.2b0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. mastermind_ai-1.6.2b0/LICENSE +21 -0
  2. mastermind_ai-1.6.2b0/PKG-INFO +138 -0
  3. mastermind_ai-1.6.2b0/README.md +115 -0
  4. mastermind_ai-1.6.2b0/setup.cfg +4 -0
  5. mastermind_ai-1.6.2b0/setup.py +42 -0
  6. mastermind_ai-1.6.2b0/src/mastermind/__init__.py +0 -0
  7. mastermind_ai-1.6.2b0/src/mastermind/game/__init__.py +3 -0
  8. mastermind_ai-1.6.2b0/src/mastermind/game/board.py +116 -0
  9. mastermind_ai-1.6.2b0/src/mastermind/game/game.py +77 -0
  10. mastermind_ai-1.6.2b0/src/mastermind/game/game_flow.py +75 -0
  11. mastermind_ai-1.6.2b0/src/mastermind/game/game_parameter.py +87 -0
  12. mastermind_ai-1.6.2b0/src/mastermind/game/player_logic.py +108 -0
  13. mastermind_ai-1.6.2b0/src/mastermind/main/__init__.py +1 -0
  14. mastermind_ai-1.6.2b0/src/mastermind/main/game_controller.py +71 -0
  15. mastermind_ai-1.6.2b0/src/mastermind/main/game_history.py +73 -0
  16. mastermind_ai-1.6.2b0/src/mastermind/main/game_storage.py +23 -0
  17. mastermind_ai-1.6.2b0/src/mastermind/main/main.py +94 -0
  18. mastermind_ai-1.6.2b0/src/mastermind/players/__init__.py +11 -0
  19. mastermind_ai-1.6.2b0/src/mastermind/players/abstract_player.py +65 -0
  20. mastermind_ai-1.6.2b0/src/mastermind/players/ai_player.py +31 -0
  21. mastermind_ai-1.6.2b0/src/mastermind/players/external_player.py +53 -0
  22. mastermind_ai-1.6.2b0/src/mastermind/players/human_player.py +122 -0
  23. mastermind_ai-1.6.2b0/src/mastermind/storage/__init__.py +4 -0
  24. mastermind_ai-1.6.2b0/src/mastermind/storage/persistent_cache.py +76 -0
  25. mastermind_ai-1.6.2b0/src/mastermind/storage/user_data.py +148 -0
  26. mastermind_ai-1.6.2b0/src/mastermind/ui/__init__.py +13 -0
  27. mastermind_ai-1.6.2b0/src/mastermind/ui/menu/__init__.py +13 -0
  28. mastermind_ai-1.6.2b0/src/mastermind/ui/menu/base_menu.py +62 -0
  29. mastermind_ai-1.6.2b0/src/mastermind/ui/menu/concrete_menus.py +139 -0
  30. mastermind_ai-1.6.2b0/src/mastermind/ui/menu/data_menu.py +50 -0
  31. mastermind_ai-1.6.2b0/src/mastermind/ui/menu/option_menu.py +43 -0
  32. mastermind_ai-1.6.2b0/src/mastermind/utils/__init__.py +11 -0
  33. mastermind_ai-1.6.2b0/src/mastermind/utils/fstring_template.py +28 -0
  34. mastermind_ai-1.6.2b0/src/mastermind/utils/get_feedback.py +34 -0
  35. mastermind_ai-1.6.2b0/src/mastermind/utils/render_dataframe.py +71 -0
  36. mastermind_ai-1.6.2b0/src/mastermind/utils/stack.py +114 -0
  37. mastermind_ai-1.6.2b0/src/mastermind/validation/__init__.py +45 -0
  38. mastermind_ai-1.6.2b0/src/mastermind/validation/base/__init__.py +28 -0
  39. mastermind_ai-1.6.2b0/src/mastermind/validation/base/base.py +102 -0
  40. mastermind_ai-1.6.2b0/src/mastermind/validation/base/exceptions.py +46 -0
  41. mastermind_ai-1.6.2b0/src/mastermind/validation/base/numeric.py +162 -0
  42. mastermind_ai-1.6.2b0/src/mastermind/validation/base/semi_mutable.py +46 -0
  43. mastermind_ai-1.6.2b0/src/mastermind/validation/base/validated_class.py +46 -0
  44. mastermind_ai-1.6.2b0/src/mastermind/validation/models/__init__.py +17 -0
  45. mastermind_ai-1.6.2b0/src/mastermind/validation/models/_game_utils.py +58 -0
  46. mastermind_ai-1.6.2b0/src/mastermind/validation/models/numeric.py +45 -0
  47. mastermind_ai-1.6.2b0/src/mastermind/validation/models/valid_combination.py +58 -0
  48. mastermind_ai-1.6.2b0/src/mastermind/validation/models/valid_feedback.py +67 -0
  49. mastermind_ai-1.6.2b0/src/mastermind_ai.egg-info/PKG-INFO +138 -0
  50. mastermind_ai-1.6.2b0/src/mastermind_ai.egg-info/SOURCES.txt +52 -0
  51. mastermind_ai-1.6.2b0/src/mastermind_ai.egg-info/dependency_links.txt +1 -0
  52. mastermind_ai-1.6.2b0/src/mastermind_ai.egg-info/entry_points.txt +2 -0
  53. mastermind_ai-1.6.2b0/src/mastermind_ai.egg-info/requires.txt +1 -0
  54. mastermind_ai-1.6.2b0/src/mastermind_ai.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Flyson Lin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.1
2
+ Name: mastermind-ai
3
+ Version: 1.6.2b0
4
+ Summary: A Python package that simulates the Mastermind game with an AI solver.
5
+ Home-page: https://github.com/FlysonBot/Mastermind
6
+ Author: FlysonBot
7
+ Author-email: FlysonBot@users.noreply.github.com
8
+ Project-URL: Repository, https://github.com/FlysonBot/Mastermind
9
+ Project-URL: Documentation, https://flysonbot.github.io/Mastermind/
10
+ Project-URL: Issues and Bugs, https://github.com/FlysonBot/Mastermind/issues
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: Intended Audience :: Education
16
+ Classifier: Natural Language :: English
17
+ Classifier: Topic :: Games/Entertainment :: Puzzle Games
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: pandas>=2.2.2
23
+
24
+ <p align="center">
25
+ <img src="https://raw.githubusercontent.com/FlysonBot/Mastermind/main/docs/source/_static/Mastermind Logo.svg" width="350">
26
+ </p>
27
+
28
+ | **Testing:** | [![Testing Status](https://img.shields.io/github/actions/workflow/status/FlysonBot/Mastermind/coveralls.yaml?label=test)](https://github.com/FlysonBot/Mastermind/actions/workflows/coveralls.yaml) [![Test Coverage](https://coveralls.io/repos/github/FlysonBot/Mastermind/badge.svg?branch=main)](https://coveralls.io/github/FlysonBot/Mastermind?branch=main) [![CodeFactor](https://www.codefactor.io/repository/github/flysonbot/mastermind/badge/main)](https://www.codefactor.io/repository/github/flysonbot/mastermind/overview/main) [![Docs Deploy Status](https://img.shields.io/github/actions/workflow/status/FlysonBot/Mastermind/deploy_sphinx.yaml?label=docs)](https://flysonbot.github.io/Mastermind/) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/af7ee6c4fbc945f88a41ef8edbea682d)](https://app.codacy.com/gh/FlysonBot/Mastermind/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)|
29
+ | --- | :-: |
30
+ | **Version:** | [![GitHub tag](https://img.shields.io/github/tag/FlysonBot/Mastermind?include_prereleases=&sort=semver&color=blue)](https://github.com/FlysonBot/Mastermind/tags) [![GitHub Release](https://img.shields.io/github/v/release/FlysonBot/Mastermind)](https://github.com/FlysonBot/Mastermind/releases) [![Python Version](https://img.shields.io/badge/Python-3.10+-blue)](https://www.python.org/downloads/) |
31
+ | **Activity:** | [![Opened Issue Count](https://img.shields.io/github/issues/FlysonBot/Mastermind?color=teal)](<https://github.com/FlysonBot/Mastermind/issues>) [![Closed Issue Count](https://img.shields.io/github/issues-closed/FlysonBot/Mastermind?color=teal)](https://github.com/FlysonBot/Mastermind/issues?q=is%3Aissue+is%3Aclosed) [![Closed PR Count](https://img.shields.io/github/issues-pr-closed/FlysonBot/Mastermind?color=teal)](https://github.com/FlysonBot/Mastermind/pulls?q=is%3Apr+is%3Aclosed) |
32
+ | **Meta:** | [![GitHub Downloads](https://img.shields.io/github/downloads/FlysonBot/Mastermind/total)](https://github.com/FlysonBot/Mastermind/releases) ![Repo Size](https://img.shields.io/github/repo-size/FlysonBot/Mastermind) [![GitHub License](https://img.shields.io/github/license/FlysonBot/Mastermind)](https://github.com/FlysonBot/Mastermind/blob/main/LICENSE) |
33
+
34
+ > [!NOTE]
35
+ > This repo is currently still under development. Currently there is a beta version that have the basic simulation feature finished. If you encountered any issue, please open up an issue and let me know! I will try to fix them as soon as possible.
36
+
37
+ **Links:**
38
+
39
+ - [Documentation](https://flysonbot.github.io/Mastermind/)
40
+ - [Source Code](https://github.com/FlysonBot/Mastermind)
41
+ - [Releases](https://github.com/FlysonBot/Mastermind/releases)
42
+ - [Bug Reports](https://github.com/FlysonBot/Mastermind/issues)
43
+ - [Changelog](https://github.com/FlysonBot/Mastermind/blob/main/CHANGELOG.md)
44
+ - [Contributing](https://github.com/FlysonBot/Mastermind/blob/main/.github/CONTRIBUTING.md)
45
+ - [Code of Conduct](https://github.com/FlysonBot/Mastermind/blob/main/.github/CODE_OF_CONDUCT.md)
46
+
47
+ # Mastermind
48
+
49
+ > This is a python implementation of the classic puzzle game Mastermind. It simulates the game and allow you to play with either another human being (sits next to you) or the computer, with a AI Solver build-in (still under development). You can install this game with pip or try it out in your browser with [Google Colab](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/examples/mastermind_in_colab.ipynb).
50
+
51
+ ## What is Mastermind?
52
+
53
+ Mastermind is a code-breaking game for two players. The first player (the code-setter) creates a secret code, which the second player (the code-cracker) tries to guess. The code-cracker has a limited number of attempts to guess the code correctly. After each guess, the code-setter provides feedback to the code-cracker, indicating how many dots have the right color and are in the right place, and how many are the right color but in the wrong place. The code-cracker uses this feedback to refine their guesses until they correctly guess the code or run out of attempts.
54
+
55
+ ## Getting Started
56
+
57
+ ### Prerequisites
58
+
59
+ To run this project, you must have the following installed (installation guide below):
60
+
61
+ - Python 3.10 (or higher)
62
+ - pip (comes with Python, needed to install the project as a library)
63
+
64
+ Or alternatively you can run this program in your browser with [Google Colab](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/mastermind_in_colab.ipynb)
65
+
66
+ ### Installation Guide
67
+
68
+ 1. Install [Python 3.10+](https://www.python.org/downloads/) if you have not already.
69
+
70
+ 2. Install this the latest python release using pip in your terminal:
71
+
72
+ ```bash
73
+ pip install mastermind-ai
74
+ ```
75
+
76
+ 3. Run the program with the following command:
77
+
78
+ ```bash
79
+ mastermind
80
+ ```
81
+
82
+ 4. Enjoy!
83
+
84
+ > [!TIP]
85
+ > If the above does not work, try the troubleshooting guide below.
86
+
87
+ ### Troubleshooting
88
+
89
+ If you encounter any issues during installation, please check the following:
90
+
91
+ 1. Do you have trouble finding your terminal?
92
+
93
+ - For windows users, press `Ctrl + R` and type `cmd` and press enter.
94
+ - For mac users, press `Cmd + Space` and type `terminal` and press enter.
95
+ - For linux users, press `Ctrl + Alt + T`.
96
+
97
+ 2. Do you have the correct version of `python` installed? Check with the following command:
98
+
99
+ ```bash
100
+ python --version
101
+ ```
102
+
103
+ If you get an error, you need to install python.
104
+ If your python version is lower than 3.10, you need to upgrade your python version.
105
+
106
+ 3. Do you have `pip` installed properly? Check with the following command:
107
+
108
+ ```bash
109
+ pip --version
110
+ ```
111
+
112
+ If you get an error, you need to install `pip`.
113
+
114
+ 4. Did you encountered an error associated with installing the dependencies of this project? Try installing the dependencies manually using the following command:
115
+
116
+ ```bash
117
+ pip install pandas
118
+ ```
119
+
120
+ If you get an error, the dependencies does not work on your machine. You will have to find your own way to install the dependencies.
121
+
122
+ 5. If you are still having trouble, please feel free to open up an issue [here](https://github.com/FlysonBot/Mastermind/issues), and we will try to help you out. Or alternatively you can run the program in your [browser](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/examples/mastermind_in_colab.ipynb)
123
+
124
+ ## Contributing
125
+
126
+ Contributions are welcome! Please open an issue or submit a pull request.
127
+
128
+ All contributors must adhere to the [Contributor Covenant Code of Conduct](https://github.com/FlysonBot/Mastermind/blob/main/CODE_OF_CONDUCT.md) to ensure a welcoming and inclusive environment for all contributors.
129
+
130
+ To contribute to the code directly, you must also follow the [Contributing Guidelines](https://github.com/FlysonBot/Mastermind/blob/main/CONTRIBUTING.md) to ensure a smooth and efficient collaboration process.
131
+
132
+ ## License
133
+
134
+ Licensed under [MIT License](https://github.com/FlysonBot/Mastermind/blob/main/LICENSE) by [@FlysonBot](https://github.com/FlysonBot).
135
+
136
+ ## Questions?
137
+
138
+ If you have any questions, please feel free to leave them in the [Discussions](https://github.com/FlysonBot/Mastermind/discussions) or open up an [Issue](https://github.com/FlysonBot/Mastermind/issues).
@@ -0,0 +1,115 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/FlysonBot/Mastermind/main/docs/source/_static/Mastermind Logo.svg" width="350">
3
+ </p>
4
+
5
+ | **Testing:** | [![Testing Status](https://img.shields.io/github/actions/workflow/status/FlysonBot/Mastermind/coveralls.yaml?label=test)](https://github.com/FlysonBot/Mastermind/actions/workflows/coveralls.yaml) [![Test Coverage](https://coveralls.io/repos/github/FlysonBot/Mastermind/badge.svg?branch=main)](https://coveralls.io/github/FlysonBot/Mastermind?branch=main) [![CodeFactor](https://www.codefactor.io/repository/github/flysonbot/mastermind/badge/main)](https://www.codefactor.io/repository/github/flysonbot/mastermind/overview/main) [![Docs Deploy Status](https://img.shields.io/github/actions/workflow/status/FlysonBot/Mastermind/deploy_sphinx.yaml?label=docs)](https://flysonbot.github.io/Mastermind/) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/af7ee6c4fbc945f88a41ef8edbea682d)](https://app.codacy.com/gh/FlysonBot/Mastermind/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)|
6
+ | --- | :-: |
7
+ | **Version:** | [![GitHub tag](https://img.shields.io/github/tag/FlysonBot/Mastermind?include_prereleases=&sort=semver&color=blue)](https://github.com/FlysonBot/Mastermind/tags) [![GitHub Release](https://img.shields.io/github/v/release/FlysonBot/Mastermind)](https://github.com/FlysonBot/Mastermind/releases) [![Python Version](https://img.shields.io/badge/Python-3.10+-blue)](https://www.python.org/downloads/) |
8
+ | **Activity:** | [![Opened Issue Count](https://img.shields.io/github/issues/FlysonBot/Mastermind?color=teal)](<https://github.com/FlysonBot/Mastermind/issues>) [![Closed Issue Count](https://img.shields.io/github/issues-closed/FlysonBot/Mastermind?color=teal)](https://github.com/FlysonBot/Mastermind/issues?q=is%3Aissue+is%3Aclosed) [![Closed PR Count](https://img.shields.io/github/issues-pr-closed/FlysonBot/Mastermind?color=teal)](https://github.com/FlysonBot/Mastermind/pulls?q=is%3Apr+is%3Aclosed) |
9
+ | **Meta:** | [![GitHub Downloads](https://img.shields.io/github/downloads/FlysonBot/Mastermind/total)](https://github.com/FlysonBot/Mastermind/releases) ![Repo Size](https://img.shields.io/github/repo-size/FlysonBot/Mastermind) [![GitHub License](https://img.shields.io/github/license/FlysonBot/Mastermind)](https://github.com/FlysonBot/Mastermind/blob/main/LICENSE) |
10
+
11
+ > [!NOTE]
12
+ > This repo is currently still under development. Currently there is a beta version that have the basic simulation feature finished. If you encountered any issue, please open up an issue and let me know! I will try to fix them as soon as possible.
13
+
14
+ **Links:**
15
+
16
+ - [Documentation](https://flysonbot.github.io/Mastermind/)
17
+ - [Source Code](https://github.com/FlysonBot/Mastermind)
18
+ - [Releases](https://github.com/FlysonBot/Mastermind/releases)
19
+ - [Bug Reports](https://github.com/FlysonBot/Mastermind/issues)
20
+ - [Changelog](https://github.com/FlysonBot/Mastermind/blob/main/CHANGELOG.md)
21
+ - [Contributing](https://github.com/FlysonBot/Mastermind/blob/main/.github/CONTRIBUTING.md)
22
+ - [Code of Conduct](https://github.com/FlysonBot/Mastermind/blob/main/.github/CODE_OF_CONDUCT.md)
23
+
24
+ # Mastermind
25
+
26
+ > This is a python implementation of the classic puzzle game Mastermind. It simulates the game and allow you to play with either another human being (sits next to you) or the computer, with a AI Solver build-in (still under development). You can install this game with pip or try it out in your browser with [Google Colab](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/examples/mastermind_in_colab.ipynb).
27
+
28
+ ## What is Mastermind?
29
+
30
+ Mastermind is a code-breaking game for two players. The first player (the code-setter) creates a secret code, which the second player (the code-cracker) tries to guess. The code-cracker has a limited number of attempts to guess the code correctly. After each guess, the code-setter provides feedback to the code-cracker, indicating how many dots have the right color and are in the right place, and how many are the right color but in the wrong place. The code-cracker uses this feedback to refine their guesses until they correctly guess the code or run out of attempts.
31
+
32
+ ## Getting Started
33
+
34
+ ### Prerequisites
35
+
36
+ To run this project, you must have the following installed (installation guide below):
37
+
38
+ - Python 3.10 (or higher)
39
+ - pip (comes with Python, needed to install the project as a library)
40
+
41
+ Or alternatively you can run this program in your browser with [Google Colab](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/mastermind_in_colab.ipynb)
42
+
43
+ ### Installation Guide
44
+
45
+ 1. Install [Python 3.10+](https://www.python.org/downloads/) if you have not already.
46
+
47
+ 2. Install this the latest python release using pip in your terminal:
48
+
49
+ ```bash
50
+ pip install mastermind-ai
51
+ ```
52
+
53
+ 3. Run the program with the following command:
54
+
55
+ ```bash
56
+ mastermind
57
+ ```
58
+
59
+ 4. Enjoy!
60
+
61
+ > [!TIP]
62
+ > If the above does not work, try the troubleshooting guide below.
63
+
64
+ ### Troubleshooting
65
+
66
+ If you encounter any issues during installation, please check the following:
67
+
68
+ 1. Do you have trouble finding your terminal?
69
+
70
+ - For windows users, press `Ctrl + R` and type `cmd` and press enter.
71
+ - For mac users, press `Cmd + Space` and type `terminal` and press enter.
72
+ - For linux users, press `Ctrl + Alt + T`.
73
+
74
+ 2. Do you have the correct version of `python` installed? Check with the following command:
75
+
76
+ ```bash
77
+ python --version
78
+ ```
79
+
80
+ If you get an error, you need to install python.
81
+ If your python version is lower than 3.10, you need to upgrade your python version.
82
+
83
+ 3. Do you have `pip` installed properly? Check with the following command:
84
+
85
+ ```bash
86
+ pip --version
87
+ ```
88
+
89
+ If you get an error, you need to install `pip`.
90
+
91
+ 4. Did you encountered an error associated with installing the dependencies of this project? Try installing the dependencies manually using the following command:
92
+
93
+ ```bash
94
+ pip install pandas
95
+ ```
96
+
97
+ If you get an error, the dependencies does not work on your machine. You will have to find your own way to install the dependencies.
98
+
99
+ 5. If you are still having trouble, please feel free to open up an issue [here](https://github.com/FlysonBot/Mastermind/issues), and we will try to help you out. Or alternatively you can run the program in your [browser](https://colab.research.google.com/github/FlysonBot/Mastermind/blob/main/examples/mastermind_in_colab.ipynb)
100
+
101
+ ## Contributing
102
+
103
+ Contributions are welcome! Please open an issue or submit a pull request.
104
+
105
+ All contributors must adhere to the [Contributor Covenant Code of Conduct](https://github.com/FlysonBot/Mastermind/blob/main/CODE_OF_CONDUCT.md) to ensure a welcoming and inclusive environment for all contributors.
106
+
107
+ To contribute to the code directly, you must also follow the [Contributing Guidelines](https://github.com/FlysonBot/Mastermind/blob/main/CONTRIBUTING.md) to ensure a smooth and efficient collaboration process.
108
+
109
+ ## License
110
+
111
+ Licensed under [MIT License](https://github.com/FlysonBot/Mastermind/blob/main/LICENSE) by [@FlysonBot](https://github.com/FlysonBot).
112
+
113
+ ## Questions?
114
+
115
+ If you have any questions, please feel free to leave them in the [Discussions](https://github.com/FlysonBot/Mastermind/discussions) or open up an [Issue](https://github.com/FlysonBot/Mastermind/issues).
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,42 @@
1
+ from setuptools import find_packages, setup
2
+
3
+
4
+ def read_requirements(file):
5
+ with open(file, "r") as f:
6
+ return [line.strip() for line in f if line and not line.startswith("#")]
7
+
8
+
9
+ setup(
10
+ name="mastermind-ai",
11
+ version="1.6.2-beta",
12
+ author="FlysonBot",
13
+ author_email="FlysonBot@users.noreply.github.com",
14
+ description="A Python package that simulates the Mastermind game with an AI solver.",
15
+ long_description=open("README.md").read(),
16
+ long_description_content_type="text/markdown",
17
+ url="https://github.com/FlysonBot/Mastermind",
18
+ project_urls={
19
+ "Repository": "https://github.com/FlysonBot/Mastermind",
20
+ "Documentation": "https://flysonbot.github.io/Mastermind/",
21
+ "Issues and Bugs": "https://github.com/FlysonBot/Mastermind/issues",
22
+ },
23
+ package_dir={"": "src"},
24
+ packages=find_packages(where="src"),
25
+ classifiers=[
26
+ "Development Status :: 4 - Beta",
27
+ "Programming Language :: Python :: 3.10",
28
+ "License :: OSI Approved :: MIT License",
29
+ "Intended Audience :: End Users/Desktop",
30
+ "Intended Audience :: Education",
31
+ "Natural Language :: English",
32
+ "Topic :: Games/Entertainment :: Puzzle Games",
33
+ "Operating System :: OS Independent",
34
+ ],
35
+ python_requires=">=3.10",
36
+ install_requires=read_requirements("src/requirements.txt"),
37
+ entry_points={
38
+ "console_scripts": [
39
+ "mastermind = mastermind.main.main:main",
40
+ ],
41
+ },
42
+ )
File without changes
@@ -0,0 +1,3 @@
1
+ from mastermind.game.game import Game
2
+
3
+ __all__ = ["Game"]
@@ -0,0 +1,116 @@
1
+ from typing import Tuple
2
+
3
+ from mastermind.utils import Stack
4
+
5
+
6
+ class GameBoard:
7
+ """
8
+ Represents the game board for a Mastermind game.
9
+
10
+ The GameBoard class manages the game's guesses and feedbacks, allowing players to make guesses, retrieve past guesses and feedbacks, and clear the board.
11
+
12
+ Attributes:
13
+ NUMBER_OF_COLORS (int): The number of colors available in the game.
14
+ NUMBER_OF_DOTS (int): The number of dots (or pegs) in each guess.
15
+ _number_of_guesses_made (int): The number of guesses made so far.
16
+ _guesses (Stack): A stack of the guesses made so far.
17
+ _feedbacks (Stack): A stack of the feedbacks received for the guesses made so far.
18
+
19
+ Raises:
20
+ EmptyBoardError: If there are no guesses to retrieve or remove.
21
+ """
22
+
23
+ class EmptyBoardError(Exception):
24
+ """
25
+ Exception raised when trying to access the game board when it is empty.
26
+ """
27
+
28
+ pass
29
+
30
+ def __init__(self, number_of_colors: int, number_of_dots: int) -> None:
31
+ self.NUMBER_OF_COLORS = number_of_colors
32
+ self.NUMBER_OF_DOTS = number_of_dots
33
+
34
+ self._number_of_guesses_made = 0
35
+ self._guesses = Stack()
36
+ self._feedbacks = Stack()
37
+
38
+ def __len__(self) -> int:
39
+ """
40
+ Returns the number of guesses made on the game board.
41
+ """
42
+ return self._number_of_guesses_made
43
+
44
+ def __getitem__(self, index: int) -> Tuple:
45
+ """
46
+ Returns the guess and feedback at the specified index.
47
+ """
48
+ return self._guesses[index], self._feedbacks[index]
49
+
50
+ def last_guess(self) -> Tuple:
51
+ """
52
+ Returns the last guess made on the game board.
53
+
54
+ Returns:
55
+ Tuple: A tuple representation of the last guess.
56
+
57
+ Raises:
58
+ EmptyBoardError: If there are no guesses on the game board.
59
+ """
60
+ if self._number_of_guesses_made == 0:
61
+ raise self.EmptyBoardError("No guesses to return.")
62
+
63
+ return self._guesses.top()
64
+
65
+ def last_feedback(self) -> Tuple:
66
+ """
67
+ Returns the feedback for the last guess made on the game board.
68
+
69
+ Returns:
70
+ Tuple: A tuple representation of the last feedback.
71
+
72
+ Raises:
73
+ EmptyBoardError: If there are no guesses on the game board.
74
+ """
75
+ if self._number_of_guesses_made == 0:
76
+ raise self.EmptyBoardError("No guesses to return.")
77
+
78
+ return self._feedbacks.top()
79
+
80
+ def remove_last(self) -> Tuple:
81
+ """
82
+ Removes the last guess and feedback from the game board.
83
+
84
+ Returns:
85
+ Tuple: The removed guess and feedback.
86
+
87
+ Raises:
88
+ EmptyBoardError: If there are no guesses on the game board.
89
+ """
90
+ if self._number_of_guesses_made == 0:
91
+ raise self.EmptyBoardError("No guesses to remove.")
92
+
93
+ self._number_of_guesses_made -= 1
94
+
95
+ return self._guesses.pop(), self._feedbacks.pop()
96
+
97
+ def add_guess(self, guess: Tuple[int, ...], feedback: Tuple[int, ...]) -> None:
98
+ """
99
+ Adds a new guess and its corresponding feedback to the game board.
100
+
101
+ Args:
102
+ guess (Tuple[int, ...]): The new guess.
103
+ feedback (Tuple[int, ...]): The feedback for the new guess.
104
+ """
105
+
106
+ self._guesses.push(guess)
107
+ self._feedbacks.push(feedback)
108
+ self._number_of_guesses_made += 1
109
+
110
+ def clear(self) -> None:
111
+ """
112
+ Clears the game board, removing all guesses and feedbacks.
113
+ """
114
+ self._guesses.clear()
115
+ self._feedbacks.clear()
116
+ self._number_of_guesses_made = 0
@@ -0,0 +1,77 @@
1
+ from typing import Optional
2
+
3
+ from mastermind.game.game_flow import GameFlow
4
+ from mastermind.game.game_parameter import GameParameter
5
+ from mastermind.game.player_logic import PlayerLogic
6
+
7
+
8
+ class Game:
9
+ """
10
+ The main entry point for the Mastermind game.
11
+
12
+ Args:
13
+ number_of_colors (int): The number of colors in the game.
14
+ number_of_dots (int): The number of dots in each combination.
15
+ maximum_attempts (int): The maximum number of attempts allowed in the game.
16
+ game_mode (str): The game mode, such as "HvH", "HvAI", "AIvH", or "AIvAI".
17
+ """
18
+
19
+ def __init__(self, number_of_colors, number_of_dots, maximum_attempts, game_mode):
20
+ self._state = GameParameter(
21
+ number_of_colors, number_of_dots, maximum_attempts, game_mode
22
+ )
23
+ self._board = self._state._board
24
+ self._player_logic = PlayerLogic(self._state)
25
+ self._game_flow = GameFlow(self._state, self._player_logic)
26
+
27
+ def start_game(self) -> Optional[str]:
28
+ """
29
+ Starts the game.
30
+
31
+ Returns:
32
+ Optional[str]: A command from the player, if any.
33
+ """
34
+ return self._game_flow.start_game()
35
+
36
+ def resume_game(self) -> Optional[str]:
37
+ """
38
+ Resumes the game.
39
+
40
+ Returns:
41
+ Optional[str]: A command from the player, if any.
42
+ """
43
+ return self._game_flow.resume_game()
44
+
45
+ def __len__(self) -> int:
46
+ """
47
+ Returns the number of attempts made in the game.
48
+ """
49
+ return len(self._board)
50
+
51
+ @property
52
+ def number_of_colors(self) -> int:
53
+ """
54
+ Returns the number of colors in the game.
55
+ """
56
+ return self._state.number_of_colors
57
+
58
+ @property
59
+ def number_of_dots(self) -> int:
60
+ """
61
+ Returns the number of dots in each combination.
62
+ """
63
+ return self._state.number_of_dots
64
+
65
+ @property
66
+ def maximum_attempts(self) -> int:
67
+ """
68
+ Returns the maximum number of attempts allowed in the game.
69
+ """
70
+ return self._state.MAXIMUM_ATTEMPTS
71
+
72
+ @property
73
+ def game_mode(self) -> str:
74
+ """
75
+ Returns the game mode.
76
+ """
77
+ return self._state.GAME_MODE
@@ -0,0 +1,75 @@
1
+ from typing import Optional
2
+
3
+ from mastermind.game.game_parameter import GameParameter
4
+ from mastermind.game.player_logic import PlayerLogic
5
+
6
+
7
+ class GameFlow:
8
+ """
9
+ Manages the flow of the Mastermind game.
10
+
11
+ Args:
12
+ game_state (GameState): The state of the game.
13
+ player_logic (PlayerLogic): The logic for the players.
14
+ """
15
+
16
+ def __init__(self, game_state: GameParameter, player_logic: PlayerLogic) -> None:
17
+ self.game_state = game_state
18
+ self.player_logic = player_logic
19
+
20
+ def start_game(self) -> Optional[str]:
21
+ """
22
+ Starts the game.
23
+
24
+ Returns:
25
+ Optional[str]: A command from the player, if any.
26
+ """
27
+ if self.game_state.game_started:
28
+ raise NotImplementedError("Game has already started.")
29
+
30
+ self.game_state.game_started = True
31
+ self.player_logic.initialize_players()
32
+ if self.player_logic.PLAYER_SETTER.set_secret_code() == "d":
33
+ return "d" # code setter discarded the game
34
+
35
+ return self._play_game()
36
+
37
+ def resume_game(self) -> Optional[str]:
38
+ """
39
+ Resumes the game.
40
+
41
+ Returns:
42
+ Optional[str]: A command from the player, if any.
43
+ """
44
+ if not self.game_state.game_started:
45
+ raise NotImplementedError("Game has not started yet.")
46
+
47
+ return self._play_game()
48
+
49
+ def _play_game(self) -> Optional[str]:
50
+ """
51
+ Plays the game and retrieves a command from the player, if any.
52
+
53
+ Returns:
54
+ Optional[str]: A command from the player, if any.
55
+ """
56
+
57
+ command = self.player_logic.process_player_guessing()
58
+
59
+ self.output_result()
60
+ return command
61
+
62
+ def output_result(self) -> None:
63
+ """
64
+ Outputs the result of the game.
65
+ """
66
+ self.game_state.check_and_update_win_status()
67
+
68
+ if self.game_state.win_status is None:
69
+ return
70
+
71
+ if self.game_state.win_status:
72
+ self.player_logic.PLAYER_CRACKER.win_message()
73
+
74
+ else:
75
+ self.player_logic.PLAYER_CRACKER.lose_message()