-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
107 lines (90 loc) · 2.34 KB
/
test.py
File metadata and controls
107 lines (90 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
"""
All coordinates assume a screen resolution of 1280x1024, and Chrome
maximized with the Bookmarks Toolbar enabled.
Down key has been hit 4 times to center play area in browser.
x_pad = 516
y_pad = 277
Play area = x_pad+1, y_pad+1, 834,595
"""
#Globals
#----------------------------
from PIL import ImageGrab
import PIL.Image
from PIL import Image
import os
import time
import webbrowser
import win32api , win32con
import pyautogui
from state import State
from MovesGenerator import MovesGenerator
from MinimaxAlgorithm import minimax
from StateEvaluator import is_gameover
from StateEvaluator import evaluate
from config import EMPTYCELL
from config import BLACKCELL
from config import WHITECELL
class Coordinates():
startBtn=(690, 425)
playBtn=(683, 590)
def startGame():
pyautogui.click(Coordinates.startBtn)
def playGame():
pyautogui.click(Coordinates.playBtn)
def screenGrab():
x = 526
y = 275
step = 40
box = (x ,y , x+(8*step) , y+(8*step))
im = ImageGrab.grab(box)
im.save(os.getcwd() + '\\image' + '.png', 'PNG')
def sendState():
board =[[],[],[],[],[],[],[],[]]
row = []
x = 7
y = 14
step = 40
screenGrab()
ima = Image.open('image.png')
rgb_im = ima.convert('RGB')
for i in range(8):
for j in range(8):
r, g, b = rgb_im.getpixel(((x+(step*i)), (y+(step*j))))
if (r in range (150 , 250) and g in range (150 , 250) and b in range (150 , 250)):
board[j].append(2)
elif(r in range (0 , 100 ) and g in range (0 , 100) and b in range (0 , 100) ):
board[j].append(1)
else:
board[j].append(0)
for row in board:
print(row)
print("\n")
return board
def calacePosition(second,first):
x = 546
y = 290
step=40
pyautogui.click(x+(step*first) , y+(step*second))
time.sleep(2)
startGame()
time.sleep(2)
playGame()
time.sleep(2)
playGame()
time.sleep(2)
playGame()
while(True):
time.sleep(10)
state = State(sendState(), WHITECELL)
state = minimax(state)
print("Next State: ")
for row in state[0].board:
print(row)
print("\n")
if(state[0].x == -1 and state[0].y == -1):
print(
f"Player didn't have a play")
continue
calacePosition(state[0].x, state[0].y)
if(is_gameover(state[0])):
break