Skip to content

Commit 2c76da7

Browse files
committed
[BUG-FIX][UPDATE]: Bug-fixes and Win exe Distribution
1 parent 0ecf94b commit 2c76da7

File tree

5 files changed

+134
-98
lines changed

5 files changed

+134
-98
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
__pycache__
3+
*.spec

Game.py

+59-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
"""
2+
TicTacToe Game is a board game of placing crosses and circles and is played as a multiplayer or as a computer vs player.
3+
Copyright (C) 2018 Rahul Gautham Putcha
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU General Public License for more details.
14+
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
18+
For more details on contact, please visit https://rahulgputcha.com or email to [email protected]
19+
20+
"""
121
#Header Files
222
import cv2
323
import numpy as np
424
from random import randint
25+
import time
26+
527
#-----------------------------------------------------------------------------------
628

729
#Classes
@@ -33,7 +55,7 @@ def reset(self) :
3355
for i in range(3) :
3456
row = []
3557
for j in range(3) :
36-
row.append([Block(i,j),(j*(self.width/3)+3,i*(self.height/3)+3),((j+1)*(self.width/3)-3,(i+1)*(self.height/3)-3)])
58+
row.append([Block(i,j),(j*(self.width//3)+3,i*(self.height//3)+3),((j+1)*(self.width//3)-3,(i+1)*(self.height//3)-3)])
3759
self.blocks.append(row)
3860
#-----------------------------------------------------------------------------------
3961
#Drawing GUI and Game Screen
@@ -45,19 +67,19 @@ def draw(self) :
4567
end_point = self.blocks[i][j][2]
4668
cv2.rectangle(self.image,start_point,end_point,(255,255,255),-1)
4769
value = " " if self.blocks[i][j][0].value is None else self.blocks[i][j][0].value
48-
cv2.putText(self.image,value,(j*(self.width/3)+25,(i*self.height/3)+100),cv2.FONT_HERSHEY_SIMPLEX,5,(0,0,0),5)
70+
cv2.putText(self.image,value,(j*(self.width//3)+25,(i*self.height//3)+100),cv2.FONT_HERSHEY_SIMPLEX,5,(0,0,0),5)
4971
if self.checkWin() :
5072
string = ("Player "+str(self.turn)+" Wins" if self.turn!=self.vsCom else "Computer Wins") if self.turn==1 else ("Player "+str(2)+" Win" if self.turn!=self.vsCom else "Computer Win")
5173
else :
5274
if not self.checkDraw() :
5375
string = ("Player "+str(self.turn)+"'s Turn" if self.turn!=self.vsCom else "Computer's Turn") if self.turn==1 else ("Player "+str(2)+"'s Turn" if self.turn!=self.vsCom else "Computer's Turn")
5476
else :
5577
string = "Match Draw!!"
56-
cv2.putText(self.image,string,(self.width/2-70,self.height+30),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,255,255),1)
78+
cv2.putText(self.image,string,(self.width//2-70,self.height+30),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,255,255),1)
5779
cv2.putText(self.image,"R - Reset",(10,self.height+60),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,255,255),1)
5880
cv2.putText(self.image,"Esc - Exit",(10,self.height+80),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,255,255),1)
5981
string = "vs Computer" if self.vsCom==0 else "vs Human"
60-
cv2.putText(self.image,"Space - "+string,(self.width/2+10,self.height+80),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,255,255),1)
82+
cv2.putText(self.image,"Space - "+string,(self.width//2+10,self.height+80),cv2.FONT_HERSHEY_SIMPLEX,0.5,(255,255,255),1)
6183

6284
if self.selected and not(self.checkWin() or self.checkDraw()):
6385
self.change = True
@@ -68,28 +90,35 @@ def draw(self) :
6890
def mainLoop(self) : #Game Loop till Esc(Close) button is pressed
6991
cv2.namedWindow(self.windowName)
7092
cv2.setMouseCallback(self.windowName,self.mouseCall)
71-
while True and cv2.getWindowProperty(self.windowName,1) != -1 :
72-
if self.change :
73-
self.change=False
74-
self.draw()
75-
if self.vsCom == self.turn and not(self.checkWin() or self.checkDraw()):
76-
block = self.nextMove()
77-
block.setValue("x" if self.turn==1 else "o")
78-
self.selected = True
93+
try:
94+
while True and cv2.getWindowProperty(self.windowName,1) != -1 :
95+
if self.change :
96+
self.change=False
97+
self.draw()
98+
99+
if self.vsCom == self.turn and not(self.checkWin() or self.checkDraw()):
100+
block = self.nextMove()
101+
block.setValue("x" if self.turn==1 else "o")
102+
103+
self.selected = True
104+
self.change = True
105+
106+
107+
cv2.imshow(self.windowName,self.image)
108+
#Keyboard Hits
109+
key = cv2.waitKey(1)
110+
if key == 27 : break
111+
elif key == ord("r") or key == ord("R") :
112+
self.reset()
113+
if key == ord(" ") and not(self.checkWin() or self.checkDraw()):
114+
if self.vsCom :
115+
self.vsCom = 0
116+
else :
117+
self.vsCom = self.turn
79118
self.change = True
80-
cv2.imshow(self.windowName,self.image)
81-
#Keyboard Hits
82-
key = cv2.waitKey(1)
83-
if key == 27 : break
84-
elif key == ord("r") or key == ord("R") :
85-
self.reset()
86-
if key == ord(" ") and not(self.checkWin() or self.checkDraw()):
87-
if self.vsCom :
88-
self.vsCom = 0
89-
else :
90-
self.vsCom = self.turn
91-
self.change = True
92-
cv2.destroyAllWindows()
119+
cv2.destroyAllWindows()
120+
except:
121+
print("Window is successfully closed")
93122

94123
def checkWin(self) :
95124
self.win = False
@@ -132,10 +161,10 @@ def nextMove(self) : #Decide NextMove of Computer by this return the block to s
132161
blocks = []
133162
for block in scoresList :
134163
if scoresList[block] == bestScore :
135-
#print(block.pos,bestScore)
164+
##print(block.pos,bestScore)
136165
blocks.append(block)
137166
choice = blocks[randint(0,len(blocks)-1)]
138-
print(choice.pos)
167+
#print(choice.pos)
139168
return choice
140169

141170
def min_max(self,depth,player) : #MinMax Algorithms Function
@@ -151,7 +180,9 @@ def min_max(self,depth,player) : #MinMax Algorithms Function
151180
block[0].value = ("x" if self.turn == 1 else "o")
152181
scoresList.append(self.min_max(depth+1,player*-1))
153182
block[0].value = None
154-
return (min(scoresList) if abs(min(scoresList))>abs(max(scoresList)) else max(scoresList))
183+
if scoresList:
184+
return (min(scoresList) if abs(min(scoresList))>abs(max(scoresList)) else max(scoresList))
185+
return 0
155186

156187
def computerWins(self,block) :
157188
flag = False

LICENSE

+14-52
Original file line numberDiff line numberDiff line change
@@ -620,55 +620,17 @@ copy of the Program in return for a fee.
620620

621621
END OF TERMS AND CONDITIONS
622622

623-
How to Apply These Terms to Your New Programs
624-
625-
If you develop a new program, and you want it to be of the greatest
626-
possible use to the public, the best way to achieve this is to make it
627-
free software which everyone can redistribute and change under these terms.
628-
629-
To do so, attach the following notices to the program. It is safest
630-
to attach them to the start of each source file to most effectively
631-
state the exclusion of warranty; and each file should have at least
632-
the "copyright" line and a pointer to where the full notice is found.
633-
634-
<one line to give the program's name and a brief idea of what it does.>
635-
Copyright (C) <year> <name of author>
636-
637-
This program is free software: you can redistribute it and/or modify
638-
it under the terms of the GNU General Public License as published by
639-
the Free Software Foundation, either version 3 of the License, or
640-
(at your option) any later version.
641-
642-
This program is distributed in the hope that it will be useful,
643-
but WITHOUT ANY WARRANTY; without even the implied warranty of
644-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645-
GNU General Public License for more details.
646-
647-
You should have received a copy of the GNU General Public License
648-
along with this program. If not, see <http://www.gnu.org/licenses/>.
649-
650-
Also add information on how to contact you by electronic and paper mail.
651-
652-
If the program does terminal interaction, make it output a short
653-
notice like this when it starts in an interactive mode:
654-
655-
<program> Copyright (C) <year> <name of author>
656-
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657-
This is free software, and you are welcome to redistribute it
658-
under certain conditions; type `show c' for details.
659-
660-
The hypothetical commands `show w' and `show c' should show the appropriate
661-
parts of the General Public License. Of course, your program's commands
662-
might be different; for a GUI interface, you would use an "about box".
663-
664-
You should also get your employer (if you work as a programmer) or school,
665-
if any, to sign a "copyright disclaimer" for the program, if necessary.
666-
For more information on this, and how to apply and follow the GNU GPL, see
667-
<http://www.gnu.org/licenses/>.
668-
669-
The GNU General Public License does not permit incorporating your program
670-
into proprietary programs. If your program is a subroutine library, you
671-
may consider it more useful to permit linking proprietary applications with
672-
the library. If this is what you want to do, use the GNU Lesser General
673-
Public License instead of this License. But first, please read
674-
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
623+
TicTacToe Game is a board game of placing crosses and circles and is played as a multiplayer or as a computer vs player.
624+
Copyright (C) 2018 Rahul Gautham Putcha
625+
626+
This program is free software: you can redistribute it and/or modify
627+
it under the terms of the GNU General Public License as published by
628+
the Free Software Foundation, either version 3 of the License, or
629+
(at your option) any later version.
630+
631+
This program is distributed in the hope that it will be useful,
632+
but WITHOUT ANY WARRANTY; without even the implied warranty of
633+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
634+
GNU General Public License for more details.
635+
636+

README.md

+58-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,67 @@
1-
# TicTacToe-Game
2-
TicTacToe Game based on Minimax Algorithm using OpenCV/Python
3-
TicTacToe Game (3x3) (9 Blocks)
1+
# 👾 TicTacToe-Game 👾
2+
###### Using Minimax Algorithm and OpenCV/Python
43

5-
System Requirement : Ubuntu OS, Windows (main Requirement OpenCV and Python on any OS)
6-
Software Requirement : Python, OpenCV, NumPy
4+
## Table of Content 🤖
5+
- [TicTacToe-Game](#tictactoe-game)
6+
- [Structure of the application](#structure-of-the-application)
7+
- [Features](#features--)
8+
- [Wanna try out this game??](#demo-wanna-try-and-see-how-this-game-works)
9+
- [Interested in working of the game? - Installation Procedure](#interested-in-working-of-the-game---installation-procedure)
10+
- [Installation Dependency: Installing Miniconda](#installation-dependency-installing-miniconda)
11+
- [Setting up the Environment](#setting-up-the-environment-----)
12+
- [Run the Game](#run-the-game-)
13+
- [Like the repo??](#like-the-repo----)
714

8-
The Game is built by using
915

10-
Numpy (Numerical and Scientific Computing Library in Python)
16+
## TicTacToe-Game
17+
This repository contains an TicTacToe game. **TicTacToe Game (3x3) (9 Blocks)**
1118

12-
$sudo apt-get install python-numpy
13-
$sudo apt-get install python3-numpy
19+
This simple game comes with a elegant user interface and options using mouse & keyboard stokes. User can choose to play Player1 vs Player2 (Multiplayer) or Player vs Computer (Artificial Intelligence).
1420

15-
OpenCV (Computer Vision)
1621

17-
$sudo apt-get install libopencv-dev
18-
$sudo apt-get install libopencv-core-dev
19-
$sudo apt-get install opencv-data
20-
$sudo apt-get install python-opencv
21-
$sudo apt-get install python3-opencv
22+
23+
## Structure of the application
24+
- Game.py with core functionality in Python and Frontend GUI is implemented OpenCV-Python
25+
-
26+
27+
28+
## Features : 💯
29+
- Generates only solveble puzzles
30+
- Comes with a Hint suggestion
31+
- Windows executable included in a **dist** folder
32+
33+
## Demo: Wanna try and see how this game works??
34+
- Windows executable file available in [dist/Game.exe](https://github.com/RPG-coder/8-puzzle-and-15-puzzle-Game/tree/master/dist)
2235

23-
Python2.7 or Higher
24-
Run the Game
36+
## Interested in working of the game? - Installation Procedure
37+
### Installation Dependency: Installing Miniconda
38+
- available on https://docs.conda.io/en/latest/miniconda.html
39+
- Make sure to setup the environment variable for conda command
2540

26-
$python3 Game.py
41+
### Setting up the Environment ⛺ 🌄 🌏 🌎 🌍
42+
- Open command prompt
43+
44+
- Execute below command to setup a local environment:
2745

46+
$ conda create -n puzzle -y # or environment name of your choice
47+
48+
- Activate your environment:
49+
50+
$ conda activate puzzle
51+
52+
- Installing Application dependencies: Installing OpenCV-Python
53+
54+
$ conda install opencv-python -y
55+
56+
### Run the Game 💫
57+
58+
$python Game.py
59+
60+
## Like the repo?? 🥰 💓 💑 💜
61+
In case you have taken a like for this repository, please do star or fork my repo. Your support will not only help me in improving recognition for this repository but also encourage me in developing and sharing more interesting projects and contents.
62+
63+
Likewise, Thank you for showing your appreciation to this repo.
64+
65+
<hr/>
66+
67+
<h6 align="center"> Under GNU GPLv3 License</h6>

dist/Game.exe

51.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)