Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5f15399

Browse files
cleaned up the code and added shit
1 parent c95110f commit 5f15399

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

‎main.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import cv2
2-
import numpy as np
3-
from random import randint
4-
import time
1+
try:
2+
import cv2
3+
import numpy as np
4+
from random import randint
5+
import time
6+
except:
7+
print("Requirments to run this software are not satisfied, please contact the developer by dropping a mail at bankavarun18@gmail.com")
58

69
class Block():
710
def __init__(self, i, j):
@@ -15,6 +18,7 @@ class GUI():
1518
def __init__(self, windowName):
1619
self.windowName = windowName
1720
self.width, self.height = 500, 500
21+
# code by varun banka, kusti420 & Soerensen Patrick
1822
self.menuHeight = 100
1923
self.image = np.zeros((self.height + self.menuHeight, self.width, 3), np.uint8)
2024
self.turn = 1
@@ -50,6 +54,7 @@ def draw(self):
5054
"Player " + str(2) + " Win" if self.turn != self.vsCom else "Computer Win")
5155
else:
5256
if not self.checkDraw():
57+
# code by v a r u n b a n k a, k u s t i 4 2 0 & S o e r e n s e n P a t r i c k
5358
string = ("Player " + str(
5459
self.turn) + "'s Turn" if self.turn != self.vsCom else "Computer's Turn") if self.turn == 1 else (
5560
"Player " + str(2) + "'s Turn" if self.turn != self.vsCom else "Computer's Turn")
@@ -61,6 +66,7 @@ def draw(self):
6166
cv2.putText(self.image, "Esc - Exit", (10, self.height + 80), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
6267
string = "vs Computer" if self.vsCom == 0 else "vs Human"
6368
cv2.putText(self.image, "Space - " + string, (self.width // 2 + 10, self.height + 80), cv2.FONT_HERSHEY_SIMPLEX,
69+
# code by varun banka, kusti420 & Soerensen Patrick
6470
0.5, (255, 255, 255), 1)
6571

6672
if self.selected and not (self.checkWin() or self.checkDraw()):
@@ -90,6 +96,7 @@ def mainLoop(self):
9096
if key == 27:
9197
break
9298
elif key == ord("r") or key == ord("R"):
99+
# code by varun banka, kusti420 & Soerensen Patrick
93100
self.reset()
94101
if key == ord(" ") and not (self.checkWin() or self.checkDraw()):
95102
if self.vsCom:
@@ -109,6 +116,7 @@ def checkWin(self):
109116
self.blocks[1][2][0].value) or (
110117
self.blocks[2][0][0].value is not None and self.blocks[2][0][0].value == self.blocks[2][1][0].value ==
111118
self.blocks[2][2][0].value) or (
119+
# code by varun banka, kusti420 & Soerensen Patrick
112120
self.blocks[0][0][0].value is not None and self.blocks[0][0][0].value == self.blocks[1][0][0].value ==
113121
self.blocks[2][0][0].value) or (
114122
self.blocks[0][1][0].value is not None and self.blocks[0][1][0].value == self.blocks[1][1][0].value ==
@@ -143,6 +151,7 @@ def nextMove(self):
143151
for block in blocks:
144152
if block.value == None:
145153
if self.computerWins(block):
154+
# # https://github.com/VarunBanka/tic_tac_toe_using_python
146155
scoresList[block] = 50
147156
elif self.playerWins(block):
148157
scoresList[block] = -50
@@ -212,5 +221,5 @@ def setBlockInPos(self, x, y):
212221
break
213222

214223

215-
game = GUI("TicTacToe by Varun, Kusti and Soerensen")
224+
game = GUI("TicTacToe by Varun Banka, Kusti420 and Soerensen Patrick")
216225
game.mainLoop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /