forked from RichardBronosky/Tic-Tac-Toe
-
Notifications
You must be signed in to change notification settings - Fork 0
vpogrebi/Tic-Tac-Toe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is Valeriy Pogrebitskiy's TIC-TAC-TOE game implementation In this project, I have attempted to provide a (very primitive) front-end (GUI) implementation of the game board - in addition to implementing auto-player's computational logic. Front-end GUI is implemented using two open source Python frameworks: - "pureMVC" - provides a very nice and easy to use implementation of MODEL-VIEW_CONTROLLER design pattern - "wxPython" - provides implementation of GUI widgets and controls (used within 'components.py' and 'view.py') This project uses pureMVC framework's unsurpassed event generation and handling capabilities - to marshal GUI components of the game. Back-end (computational logic) is concentrated in "assistant.py" module ('Assistant' class). This class implements four different decision strategies (though I decided to use only three) that assist in making best move decision. Assistant.suggestMove() executes these strategies in a certain order (defined in Assistant.strategyList list) - so that quick and most obvious strategies execute first, leaving more complex one(s) for later execution. These strategies are: - _firstMove() - returns CENTER position if board is empty. This is done based on my personal experience that selecting center of the board gives better chance for winning - _immediateWinLose() - checks if there is an immediate win/lose opportunity, and returns position that either results in the immediate win, or prevents immediate loss - _minMax() - MinMax algorithm implementation. This is sort-of "brute-force" algorithm that computes all possible auto player moves and tries to analyze (using recursion) which move has better "score" (better opportunity to win). This is the most complex strategy of all, and is left to execute last - _randomChoice() - pick random move among all available moves. I used this strategy BEFORE _minMax() was implemented. After implementing _monMax(), I no longer see the need to use this strategy at all (but left it in the code) IMPORTANT --------- Please notice that since it took me much longer to implement this game than I initially anticipated - I have not done some of the things that I would normally do on all my projects: 1. I have not provided unittest coverage for GUI portion of this project. The only unittest currently implemented - is "assistant_test.py" which tests computational logic ("assistant.py"). And even within this test script, I have omitted some of the things... 2. I have not provided good comments and API documentation. Normally, I add good comments (and a lot of them) in my code, as well as supply documentation strings that are used to generate complete project's API documentation. In fact, I usually generate two different documentation sets for my projects: using "Epydoc" and "pydoctor" (developed by 'Twisted' framework's team). I personally like "pydoctor" more... 3. GUI could be improved - both in terms of presentation and behavior. As I mentioned above, my goal was to provide the most simplistic GUI that works, not the best possible one. Please do not pay attention to this poor implementation I consider myself being very good both with unittest'ing (I am fluent using both Mocks and Stubs), and with documentation. Please take my word for it. 08/03/2001 NOTICE ------------------ I noticed that initial implementation of MiniMax algorithm (originally implemented as _minMax() and _evaluateMove() methods of Assistant class within assistant.py) was not perfect. I have improved this implementation - making a clear separation of maximizing and minimizing the scores. New implementation consists of _maxiMin(), _maximizedMove() and _minimizedMove() methods. Some other minor changes are made to Assistant class at the same time - which are purely cosmetic changes having no effect on the implementation. assistant_test.py unittest module is also updated to reflect latest code changes PREREQUISITES ------------- 1. Download and install 'pureMVS' framework (http://puremvc.org/component/option,com_wrapper/Itemid,168/) 2. Download and Install 'wxPython' (http://www.wxpython.org/download.php) RUN INSTRUCTIONS ---------------- 'tictactoe.py' (originally 'main.py') - is the main module that starts the game. To start the game from shell: "python <path>/src/tictactoe.py", or simply "<path>/src/tictactoe.py" (I made script to be an executable) To play the game: 1. Select the role: 'X' or 'O' 2. Start the game: click on 'Start Game' 3. Whenever it is your turn ('X' has first move) - click (left-click) on the chosen board position 4. To restart the game (while game is incomplete) - click 'Stop Game' and then 'Start Game' again 5. Good luck!
About
coding challenge: Create an app that can interactively play the game and never lose.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
- Python 97.0%
- JavaScript 3.0%