├── .gitignore ├── LICENSE ├── README.md ├── Training_Data ├── Blue │ ├── 0 (1).bmp │ ├── 0 (2).bmp │ ├── 0 (3).bmp │ ├── 0 (4).bmp │ ├── 0 (5).bmp │ ├── 1 (1).bmp │ ├── 1 (2).bmp │ └── 1 (3).bmp ├── Blue_Striped_H │ └── 3_7.bmp ├── Blue_Striped_V │ └── 5_5.bmp ├── Blue_Wrapped │ └── 3_7.bmp ├── Chocolate │ └── 5_4.bmp ├── Green │ ├── 0 (1).bmp │ ├── 0 (2).bmp │ ├── 0 (3).bmp │ ├── 0 (4).bmp │ ├── 0 (5).bmp │ ├── 0 (6).bmp │ ├── 0 (7).bmp │ ├── 0 (8).bmp │ └── 0 (9).bmp ├── Green_Striped_H │ └── 7_8.bmp ├── Green_Striped_V │ └── 2_1.bmp ├── Green_Wrapped │ └── 5_3.bmp ├── Orange │ ├── 0 (1).bmp │ ├── 0 (2).bmp │ ├── 0 (3).bmp │ ├── 0 (4).bmp │ ├── 0 (5).bmp │ ├── 0 (6).bmp │ ├── 0 (7).bmp │ ├── 0 (8).bmp │ └── 0 (9).bmp ├── Orange_Striped_H │ └── 6_7.bmp ├── Orange_Striped_V │ └── 2_6.bmp ├── Orange_Wrapped │ └── 0_5.bmp ├── Purple │ ├── 2 (1).bmp │ └── 2 (2).bmp ├── Purple_Striped_H │ └── 3_8.bmp ├── Purple_Striped_V │ └── 2_7.bmp ├── Purple_Wrapped │ └── 1_3.bmp ├── Red │ ├── 0 (1).bmp │ ├── 0 (2).bmp │ ├── 0 (3).bmp │ ├── 0 (4).bmp │ ├── 0 (5).bmp │ ├── 0 (6).bmp │ ├── 0 (7).bmp │ ├── 0 (8).bmp │ ├── 0 (9).bmp │ ├── 3 (1).bmp │ ├── 3 (2).bmp │ ├── 3 (3).bmp │ └── 3 (4).bmp ├── Red_Striped_H │ ├── 1 (1).bmp │ ├── 1 (2).bmp │ └── 6_6.bmp ├── Red_Striped_V │ └── 5_7.bmp ├── Red_Wrapped │ └── 2_6.bmp ├── Yellow │ ├── 0 (1).bmp │ ├── 0 (2).bmp │ ├── 0 (3).bmp │ ├── 0 (4).bmp │ ├── 0 (5).bmp │ ├── 0 (6).bmp │ └── 0 (7).bmp ├── Yellow_Striped_H │ └── 1.bmp ├── Yellow_Striped_V │ └── 2.bmp └── Yellow_Wrapped │ ├── 3_8.bmp │ └── 5_8.bmp ├── background.bmp ├── board.bmp ├── current.bmp ├── debug_utils.py ├── diff.bmp ├── end_screen.bmp ├── main.py ├── movement_test.bmp ├── screenshot.bmp ├── simple_solver.py ├── sklearn_decoder.py └── stats.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alexandru Ene 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. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A python bot that plays Candy Crush. 2 | 3 | Due to lack of time when I coded this I warn you that it's full of hardcoded stuff :). 4 | 5 | This is how it works: 6 | 7 | 1. Take a screenshot of the desktop 8 | 2. Extract the game board from it 9 | 3. From that game board extract each cell 10 | 4. Using a classification algorithm determine what candy is in each cell 11 | 5. Compute the best move using a greedy-like algorithm 12 | 6. Send Inputs to the browser window 13 | 7. Wait for the board to stabilize and all the movement to stop 14 | 8. Goto 1 :) 15 | 16 | The main problem now is the fact that I hardcoded the position of the board in the screenshot. You need to ajust the offsets of it in order to match the ones for your browser and screen size. 17 | 18 | It works with python 2.7 and needs the libraries: scikit-learn, PIL, win32api. 19 | 20 | You can watch it in action here: https://www.youtube.com/watch?v=18vqQOPlvO4 21 | 22 | There is a more in-depth explanation about how it works here: https://alexene.dev/2015/05/28/candy-crush-bot.html 23 | -------------------------------------------------------------------------------- /Training_Data/Blue/0 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/0 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/0 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/0 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/0 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/0 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/0 (4).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/0 (4).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/0 (5).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/0 (5).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/1 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/1 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/1 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/1 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Blue/1 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue/1 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Blue_Striped_H/3_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue_Striped_H/3_7.bmp -------------------------------------------------------------------------------- /Training_Data/Blue_Striped_V/5_5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue_Striped_V/5_5.bmp -------------------------------------------------------------------------------- /Training_Data/Blue_Wrapped/3_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Blue_Wrapped/3_7.bmp -------------------------------------------------------------------------------- /Training_Data/Chocolate/5_4.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Chocolate/5_4.bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (4).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (4).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (5).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (5).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (6).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (6).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (7).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (7).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (8).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (8).bmp -------------------------------------------------------------------------------- /Training_Data/Green/0 (9).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green/0 (9).bmp -------------------------------------------------------------------------------- /Training_Data/Green_Striped_H/7_8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green_Striped_H/7_8.bmp -------------------------------------------------------------------------------- /Training_Data/Green_Striped_V/2_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green_Striped_V/2_1.bmp -------------------------------------------------------------------------------- /Training_Data/Green_Wrapped/5_3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Green_Wrapped/5_3.bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (4).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (4).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (5).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (5).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (6).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (6).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (7).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (7).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (8).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (8).bmp -------------------------------------------------------------------------------- /Training_Data/Orange/0 (9).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange/0 (9).bmp -------------------------------------------------------------------------------- /Training_Data/Orange_Striped_H/6_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange_Striped_H/6_7.bmp -------------------------------------------------------------------------------- /Training_Data/Orange_Striped_V/2_6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange_Striped_V/2_6.bmp -------------------------------------------------------------------------------- /Training_Data/Orange_Wrapped/0_5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Orange_Wrapped/0_5.bmp -------------------------------------------------------------------------------- /Training_Data/Purple/2 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Purple/2 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Purple/2 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Purple/2 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Purple_Striped_H/3_8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Purple_Striped_H/3_8.bmp -------------------------------------------------------------------------------- /Training_Data/Purple_Striped_V/2_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Purple_Striped_V/2_7.bmp -------------------------------------------------------------------------------- /Training_Data/Purple_Wrapped/1_3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Purple_Wrapped/1_3.bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (4).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (4).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (5).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (5).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (6).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (6).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (7).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (7).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (8).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (8).bmp -------------------------------------------------------------------------------- /Training_Data/Red/0 (9).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/0 (9).bmp -------------------------------------------------------------------------------- /Training_Data/Red/3 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/3 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Red/3 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/3 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Red/3 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/3 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Red/3 (4).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red/3 (4).bmp -------------------------------------------------------------------------------- /Training_Data/Red_Striped_H/1 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red_Striped_H/1 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Red_Striped_H/1 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red_Striped_H/1 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Red_Striped_H/6_6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red_Striped_H/6_6.bmp -------------------------------------------------------------------------------- /Training_Data/Red_Striped_V/5_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red_Striped_V/5_7.bmp -------------------------------------------------------------------------------- /Training_Data/Red_Wrapped/2_6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Red_Wrapped/2_6.bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (1).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (1).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (2).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (2).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (3).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (3).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (4).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (4).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (5).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (5).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (6).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (6).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow/0 (7).bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow/0 (7).bmp -------------------------------------------------------------------------------- /Training_Data/Yellow_Striped_H/1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow_Striped_H/1.bmp -------------------------------------------------------------------------------- /Training_Data/Yellow_Striped_V/2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow_Striped_V/2.bmp -------------------------------------------------------------------------------- /Training_Data/Yellow_Wrapped/3_8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow_Wrapped/3_8.bmp -------------------------------------------------------------------------------- /Training_Data/Yellow_Wrapped/5_8.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/Training_Data/Yellow_Wrapped/5_8.bmp -------------------------------------------------------------------------------- /background.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/background.bmp -------------------------------------------------------------------------------- /board.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/board.bmp -------------------------------------------------------------------------------- /current.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/current.bmp -------------------------------------------------------------------------------- /debug_utils.py: -------------------------------------------------------------------------------- 1 | board_dict = {0: 'blue ', 1: 's_h_blue ', 2: 'green ', 3: 's_h_green ', 4: 'orange ', 5: 's_h_orange ', 2 | 6: 'purple ', 7: 's_h_purple ', 8: 'red ', 9: 's_h_red ', 10: 'yellow ', 11: 's_h_yellow ', 3 | 12: 'chocolate ', 13: 's_v_blue ', 14: 's_v_green ', 15: 's_v_orange ', 16: 's_v_red ', 4 | 17: 's_v_yellow ', 18: 's_v_purple ', 19: 'blue_wrapped ', 20: 'green_wrapped ', 21: 'orange_wrapped', 5 | 22: 'purple_wrapped', 23: 'red_wrapped ', 24: 'yellow_wrapped', -1: 'empty '} 6 | 7 | 8 | def print_board(board): 9 | for line in board: 10 | for elem in line: 11 | print board_dict[elem] + ' ', 12 | print 13 | -------------------------------------------------------------------------------- /diff.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/diff.bmp -------------------------------------------------------------------------------- /end_screen.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/end_screen.bmp -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | from PIL import ImageGrab 3 | import numpy as np 4 | from sklearn_decoder import ImgRecognizer 5 | import win32api, win32con 6 | import time 7 | import debug_utils as dbg 8 | import simple_solver 9 | import cProfile 10 | import pstats 11 | 12 | # excelent hardcoded values :) 13 | board_box = (366, 166, 1008, 738) 14 | img_size = (board_box[2]-board_box[0], board_box[3]-board_box[1]) 15 | cell_size = (img_size[0]/9, img_size[1]/9) 16 | 17 | board_size = 9 18 | game_board = np.zeros((board_size, board_size), dtype=np.int32) 19 | recognizer = ImgRecognizer() 20 | 21 | ''' 22 | candy values: 23 | - 0 blue 24 | - 1 green 25 | - 2 orange 26 | - 3 purple 27 | - 4 red 28 | - 5 yellow 29 | - 6 chocolate''' 30 | 31 | match_list = [(0, 1, 13, 19), (2, 3, 14, 20), (4, 5, 15, 21), (6, 7, 18, 22), (8, 9, 16, 23), (10, 11, 17, 24)] 32 | 33 | special_candies = [1, 3, 5, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] 34 | simple_candies = [0, 2, 4, 6, 8, 10] 35 | striped_candies_h = [1, 3, 5, 7, 9, 11] 36 | striped_candies_v = range(13, 19) 37 | 38 | striped_candies = striped_candies_h[:] 39 | striped_candies.extend(striped_candies_v) 40 | 41 | wrapped_candies = range(19, 25) 42 | chocolate = [12] 43 | 44 | board_dict = {0: 'blue ', 1: 's_h_blue ', 2: 'green ', 3: 's_h_green ', 4: 'orange ', 5: 's_h_orange ', 45 | 6: 'purple ', 7: 's_h_purple ', 8: 'red ', 9: 's_h_red ', 10: 'yellow ', 11: 's_h_yellow ', 46 | 12: 'chocolate', 13: 's_v_blue ', 14: 's_v_green ', 15: 's_v_orange ', 16: 's_v_red ', 47 | 17: 's_v_yellow ', 18: 's_v_purple ', 19: 'blue_wrapped', 20: 'green_wrapped', 21: 'orange_wrapped', 48 | 22: 'purple_wrapped', 23: 'red_wrapped', 24: 'yellow_wrapped', -1: 'empty '} 49 | 50 | # 3 candies explode for 60 points 51 | # 4 candies exploder for 120 create striped candy - striped candy explodes the whole vertical line 52 | # 5 in a line create a chocolate sprinkle. swipe it with a candy and it explodes candies of that color from the board 53 | 54 | 55 | # windows coords 56 | def win32_click(x, y): 57 | win32api.SetCursorPos((x, y)) 58 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0) 59 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0) 60 | 61 | 62 | def get_desktop_coords(cell): 63 | x = board_box[0] + cell[1] * cell_size[0] + cell_size[0]/2 64 | y = board_box[1] + cell[0] * cell_size[1] + cell_size[1]/2 65 | return x, y 66 | 67 | 68 | def do_move(move): 69 | start = move[0] 70 | end = move[1] 71 | 72 | start_w = get_desktop_coords(start) 73 | end_w = get_desktop_coords(end) 74 | 75 | win32api.SetCursorPos(start_w) 76 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, start_w[0], start_w[1], 0, 0) 77 | time.sleep(0.3) 78 | win32api.SetCursorPos(end_w) 79 | time.sleep(0.3) 80 | win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, end_w[0], end_w[1], 0, 0) 81 | 82 | win32api.SetCursorPos((1100, 1100)) 83 | 84 | 85 | def grab_board(): 86 | global game_board 87 | img = ImageGrab.grab() 88 | 89 | #img = Image.open('board.bmp') 90 | img = img.crop(board_box) 91 | #img.save('board.bmp') 92 | for y in range(0, 9): 93 | for x in range(0, 9): 94 | cell_box = (x*cell_size[0], y*cell_size[1], (x+1)*cell_size[0], (y+1)*cell_size[1]) 95 | cell = img.crop(cell_box) 96 | #cell.save('Cells/{0}_{1}.bmp'.format(y, x)) 97 | game_board[y][x] = recognizer.predict(cell) 98 | 99 | dbg.print_board(game_board) 100 | return img 101 | 102 | ref_img = None 103 | 104 | 105 | def board_is_moving(): 106 | global ref_img 107 | img = ImageGrab.grab() 108 | img = img.crop(board_box) 109 | img = img.resize((img.size[0]/4, img.size[1]/4), Image.NEAREST) 110 | 111 | has_movement = True 112 | if ref_img: 113 | has_movement = compare_images(img, ref_img, threshold=100) > 100 114 | 115 | ref_img = img 116 | return has_movement 117 | 118 | 119 | def are_pixels_equal(p1, p2, threshold): 120 | diff = 0 121 | for i in range(3): 122 | diff += abs(p1[i]-p2[i]) 123 | return diff < threshold 124 | 125 | 126 | def compare_images(current, reference, threshold): 127 | current_data = np.array(current.getdata()) 128 | ref_data = np.array(reference.getdata()) 129 | 130 | diff_pixels = 0 131 | total_size = current.size[0]*current.size[1] 132 | for i in range(0, total_size-3, 3): 133 | if not are_pixels_equal(current_data[i], ref_data[i], threshold): 134 | diff_pixels += 1 135 | 136 | print diff_pixels 137 | return diff_pixels 138 | 139 | 140 | background_img = Image.open('background.bmp') 141 | background_img = background_img.resize((background_img.size[0]/4, background_img.size[1]/4), Image.NEAREST) 142 | 143 | 144 | def main(): 145 | recognizer.train() 146 | solver = simple_solver.SimpleSolver() 147 | img_end_game = Image.open('end_screen.bmp') 148 | img_end_game = img_end_game.resize((img_end_game.size[0]/4, img_end_game.size[1]/4), Image.NEAREST) 149 | total_moves = 0 150 | while True: 151 | if not board_is_moving(): 152 | board_img = grab_board() 153 | board_img = board_img.resize((board_img.size[0]/4, board_img.size[1]/4), Image.NEAREST) 154 | if compare_images(board_img, img_end_game, 10) < 3000: 155 | break 156 | score, move = solver.solve_board(game_board) 157 | print '\nBest move found. Score = {0}, Move = {1}'.format(score, move) 158 | do_move(move) 159 | total_moves += 1 160 | time.sleep(0.4) 161 | print 'Total moves done: ' + str(total_moves) 162 | 163 | 164 | if __name__ == '__main__': 165 | main() 166 | #cProfile.run('main()', filename='stats.txt') 167 | #stats = pstats.Stats('stats.txt').sort_stats('cumulative') 168 | #stats.print_stats() 169 | 170 | #recognizer.train() 171 | -------------------------------------------------------------------------------- /movement_test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/movement_test.bmp -------------------------------------------------------------------------------- /screenshot.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/screenshot.bmp -------------------------------------------------------------------------------- /simple_solver.py: -------------------------------------------------------------------------------- 1 | import debug_utils as dbg 2 | from copy import deepcopy 3 | 4 | 5 | class SimpleSolver: 6 | def __init__(self): 7 | self.board_size = 9 8 | self.match_list = [(0, 1, 13, 19), (2, 3, 14, 20), (4, 5, 15, 21), (6, 7, 18, 22), (8, 9, 16, 23), (10, 11, 17, 24)] 9 | 10 | self.special_candies = [1, 3, 5, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] 11 | self.simple_candies = [0, 2, 4, 6, 8, 10] 12 | self.striped_candies_h = [1, 3, 5, 7, 9, 11] 13 | self.striped_candies_v = range(13, 19) 14 | 15 | self.striped_candies = self.striped_candies_h[:] 16 | self.striped_candies.extend(self.striped_candies_v) 17 | 18 | self.wrapped_candies = range(19, 25) 19 | self.chocolate = [12] 20 | self.game_board = None 21 | self.potential_start_coords = set() 22 | 23 | def get_score(self, candy_type): 24 | if candy_type in self.simple_candies: 25 | return 20 26 | if candy_type in self.striped_candies: 27 | return 120 28 | if candy_type in self.wrapped_candies: 29 | return 300 30 | 31 | return 0 32 | 33 | def compute_score(self, board, candies_coords): 34 | score = 0 35 | for coords in candies_coords: 36 | candy_value = board[coords[0]][coords[1]] 37 | score += self.get_score(candy_value) 38 | 39 | if len(candies_coords) == 4: 40 | score *= 3 41 | if len(candies_coords) >= 5: 42 | score *= 10 43 | return score 44 | 45 | def compute_explosions_chocolate(self, board, color): 46 | to_explode = [] 47 | for i in range(self.board_size): 48 | for j in range(self.board_size): 49 | if self.candy_matches(board[i][j], color): 50 | to_explode.append((i, j)) 51 | 52 | return to_explode 53 | 54 | def get_striped_explosion(self, board, coords): 55 | to_explode = [] 56 | candy_type = board[coords[0]][coords[1]] 57 | if candy_type in self.striped_candies_h: 58 | for k in range(self.board_size): 59 | to_explode.append((coords[0], k)) 60 | if candy_type in self.striped_candies_v: 61 | for k in range(self.board_size): 62 | to_explode.append((k, coords[1])) 63 | 64 | return to_explode 65 | 66 | def candy_matches(self, type1, type2): 67 | if type1 == type2: 68 | return True 69 | else: 70 | for match in self.match_list: 71 | if type1 in match and type2 in match: 72 | return True 73 | 74 | return False 75 | 76 | def compute_explosions_lines(self, board, start): 77 | directions = [[(-1, 0), (1, 0)], # vertical 78 | [(0, -1), (0, 1)]] # horizontal 79 | to_explode = [] 80 | for dirs in directions: 81 | open_list = [start] 82 | for d in dirs: 83 | i = start[0] + d[0] 84 | j = start[1] + d[1] 85 | while 0 <= i < self.board_size and 0 <= j < self.board_size and board[i][j] != -1 \ 86 | and self.candy_matches(board[i][j], board[start[0]][start[1]]): 87 | open_list.append((i, j)) 88 | i += d[0] 89 | j += d[1] 90 | 91 | if len(open_list) >= 3: 92 | for element in open_list: 93 | if element not in to_explode: 94 | if board[element[0]][element[1]] in self.striped_candies: 95 | to_explode.extend(self.get_striped_explosion(board, element)) 96 | else: 97 | to_explode.append(element) 98 | 99 | return to_explode 100 | 101 | def compute_explosions(self, start, end, board): 102 | chocolate_multiplier = 1 103 | to_explode = [] 104 | 105 | if board[start[0]][start[1]] in self.special_candies and board[end[0]][end[1]] in self.special_candies: 106 | score = 500000 107 | to_explode = [start, end] 108 | else: 109 | if board[start[0]][start[1]] == 12: # chocolate 110 | to_explode = self.compute_explosions_chocolate(board, board[end[0]][end[1]]) 111 | chocolate_multiplier = 100 112 | else: 113 | to_explode = self.compute_explosions_lines(board, start) 114 | 115 | to_explode.sort(key=(lambda x: x[0])) 116 | score = self.compute_score(board, to_explode) * chocolate_multiplier 117 | 118 | if len(to_explode) == 4 and board[start[0]][start[1]] != 12: # striped candy 119 | board[start[0]][start[1]] += 1 120 | to_explode.remove(start) 121 | 122 | #if len(to_explode) > 0: 123 | # print '\n\nStarting board:' 124 | # dbg.print_board(board) 125 | 126 | # Slide the other candies down after explosions take place 127 | for coord in to_explode: 128 | i, j = coord 129 | 130 | while i > 0: 131 | if board[i-1][j] != -1 and (i-1, j) not in self.potential_start_coords: 132 | self.potential_start_coords.add((i, j)) 133 | board[i][j], board[i-1][j] = board[i-1][j], board[i][j] 134 | i -= 1 135 | board[i][j] = -1 136 | 137 | #if len(to_explode) > 0: 138 | # print '\nResult from {0}, count={1}, score={2}:'.format(start, len(to_explode), score) 139 | #dbg.print_board(board) 140 | 141 | return score, board 142 | 143 | def evaluate_board(self, start, end, board): 144 | total_score, new_board = self.compute_explosions(start, end, board) 145 | score = total_score 146 | multiplier = 1 147 | while score > 0: 148 | use_new = False 149 | if use_new: 150 | potential_start = deepcopy(self.potential_start_coords) 151 | self.potential_start_coords = set() 152 | score = 0 153 | for coord in potential_start: 154 | score, new_board = self.compute_explosions((coord[0], coord[1]), end, new_board) 155 | if score > 0: 156 | total_score += score + multiplier * 60 157 | multiplier += 2 158 | else: 159 | for i in range(0, self.board_size): 160 | for j in range(0, self.board_size): 161 | score, new_board = self.compute_explosions((i, j), end, new_board) 162 | if score > 0: 163 | total_score += score + multiplier * 60 164 | multiplier += 2 165 | 166 | return total_score, new_board 167 | 168 | def check_direction(self, start, dir): 169 | end = (start[0]+dir[0], start[1]+dir[1]) 170 | board = deepcopy(self.game_board) 171 | if start[0] < 0 or start[0] > self.board_size or end[0] < 0 or end[0] > self.board_size\ 172 | or start[1] < 0 or start[1] > self.board_size or end[1] < 0 or end[1] > self.board_size: 173 | return -1, [], None 174 | 175 | # swap 176 | board[start[0]][start[1]], board[end[0]][end[1]] = board[end[0]][end[1]], board[start[0]][start[1]] 177 | score_start, start_board = self.evaluate_board(start, end, board) 178 | score_end, end_board = self.evaluate_board(end, start, board) 179 | 180 | if score_start > score_end: 181 | return score_start, [start, end], start_board 182 | else: 183 | return score_end, [end, start], end_board 184 | 185 | def solve_board(self, board): 186 | self.game_board = board 187 | max_score = 0 188 | chosen_move = [] 189 | for i in range(0, 8): 190 | for j in range(0, 8): 191 | possible_directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] 192 | for d in possible_directions: 193 | score, move, b = self.check_direction((i, j), d) 194 | if score >= max_score: 195 | max_score = score 196 | chosen_move = move 197 | 198 | return max_score, chosen_move 199 | 200 | -------------------------------------------------------------------------------- /sklearn_decoder.py: -------------------------------------------------------------------------------- 1 | from sklearn import svm 2 | from sklearn import cross_validation 3 | from sklearn.externals import joblib 4 | from PIL import Image 5 | import os 6 | import numpy as np 7 | 8 | ''' 9 | candy values: 10 | - 0 blue 11 | - 1 green 12 | - 2 orange 13 | - 3 purple 14 | - 4 yellow''' 15 | 16 | 17 | class ImgRecognizer: 18 | def __init__(self): 19 | self.training_data = [] 20 | self.target_values = [] 21 | self.svc = svm.SVC(gamma=0.001, kernel='linear', C=100) 22 | self.downscale_res = (32, 32) 23 | 24 | def _load(self, path, target_value): 25 | training_imgs = os.listdir(path) 26 | for f in training_imgs: 27 | img = Image.open(path+'/'+f) 28 | img = img.resize(self.downscale_res, Image.BILINEAR) 29 | self.training_data.append(np.array(img.getdata()).flatten()) 30 | self.target_values.append(target_value) 31 | 32 | def load(self): 33 | self._load('Training_Data/Blue', 0) 34 | self._load('Training_Data/Blue_Striped_H', 1) 35 | self._load('Training_Data/Blue_Striped_V', 13) 36 | self._load('Training_Data/Blue_Wrapped', 19) 37 | self._load('Training_Data/Green', 2) 38 | self._load('Training_Data/Green_Striped_H', 3) 39 | self._load('Training_Data/Green_Striped_V', 14) 40 | self._load('Training_Data/Green_Wrapped', 20) 41 | self._load('Training_Data/Orange', 4) 42 | self._load('Training_Data/Orange_Striped_H', 5) 43 | self._load('Training_Data/Orange_Striped_V', 15) 44 | self._load('Training_Data/Orange_Wrapped', 21) 45 | self._load('Training_Data/Purple', 6) 46 | self._load('Training_Data/Purple_Striped_H', 7) 47 | self._load('Training_Data/Purple_Striped_V', 18) 48 | self._load('Training_Data/Purple_Wrapped', 22) 49 | self._load('Training_Data/Red', 8) 50 | self._load('Training_Data/Red_Striped_H', 9) 51 | self._load('Training_Data/Red_Striped_V', 16) 52 | self._load('Training_Data/Red_Wrapped', 23) 53 | self._load('Training_Data/Yellow', 10) 54 | self._load('Training_Data/Yellow_Striped_H', 11) 55 | self._load('Training_Data/Yellow_Striped_V', 17) 56 | self._load('Training_Data/Yellow_Wrapped', 24) 57 | self._load('Training_Data/Chocolate', 12) 58 | 59 | def train(self): 60 | if os.path.isfile('svc.dat'): 61 | self.svc = joblib.load('svc.dat') 62 | else: 63 | self.load() 64 | np_data = np.array(self.training_data) 65 | np_values = np.array(self.target_values) 66 | self.svc.fit(np_data, np_values) 67 | joblib.dump(self.svc, 'svc.dat', compress=9) 68 | 69 | def test(self): 70 | np_train_data = np.array(self.training_data) 71 | np_values = np.array(self.target_values) 72 | data, test_data, train_target, test_target = cross_validation.train_test_split(np_train_data, np_values, 73 | test_size=0.4, random_state=0) 74 | self.svc.fit(data, train_target) 75 | print self.svc.score(test_data, test_target) 76 | 77 | def predict(self, img): 78 | resized_img = img.resize(self.downscale_res, Image.BILINEAR) 79 | np_img = np.array(resized_img.getdata()).flatten() 80 | return int(self.svc.predict(np_img)) 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /stats.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexEne/CCrush-Bot/d8d79526f2ac9e4be8df39ed2d267f7b234d2254/stats.txt --------------------------------------------------------------------------------