-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtestBoards.py
More file actions
134 lines (129 loc) · 4.72 KB
/
Copy pathtestBoards.py
File metadata and controls
134 lines (129 loc) · 4.72 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from tictactoe import *
title = "Tic tac toe board tester"
def print_header():
print("-"*len(title))
print(title)
print("-"*len(title))
def main():
tests = {"Empty board (handdrawn)": {
"path":"tests/empty_board.jpg",
"x_count": 0,
"o_count": 0},
"Empty board (computer drawn)": {
"path":"tests/empty_board_2.jpg",
"x_count": 0,
"o_count": 0},
"Empty board (camera, low light 1)": {
"path":"tests/cam_lowlight_empty_1.jpg",
"x_count": 0,
"o_count": 0},
"Empty board (camera, low light 2)": {
"path":"tests/cam_lowlight_empty_2.jpg",
"x_count": 0,
"o_count": 0},
"Empty board (camera, medium light 1)": {
"path":"tests/cam_mediumlight_empty_1.jpg",
"x_count": 0,
"o_count": 0},
"Empty board (camera, medium light 2)": {
"path":"tests/cam_mediumlight_empty_2.jpg",
"x_count": 0,
"o_count": 0},
"Empty board (camera, shadow 1)": {
"path":"tests/cam_shadow_empty.jpg",
"x_count": 0,
"o_count": 0},
"Camera, O=1": {
"path":"tests/cam_1O.jpg",
"x_count": 0,
"o_count": 1},
"Camera, O=2": {
"path":"tests/cam_2O.jpg",
"x_count": 0,
"o_count": 2},
"Camera, O=4": {
"path":"tests/cam_4O.jpg",
"x_count": 0,
"o_count": 4},
"Camera, O=4, X=1": {
"path":"tests/cam_4O_1X.jpg",
"x_count": 1,
"o_count": 4},
"Camera, O=4, X=2": {
"path":"tests/cam_4O_2X.jpg",
"x_count": 2,
"o_count": 4},
"Camera, O=6, X=3, v1": {
"path":"tests/cam_6O_3X_1.jpg",
"x_count": 3,
"o_count": 6},
"Camera, O=6, X=3, v2": {
"path":"tests/cam_6O_3X_2.jpg",
"x_count": 3,
"o_count": 6},
"One average x":{
"path":"tests/one_average_x.jpg",
"x_count": 1,
"o_count": 0},
"O=4 and X=3":{
"path":"tests/4O_and_3X.jpg",
"x_count": 3,
"o_count": 4},
"Two circles":{
"path":"tests/two_circles.jpg",
"x_count": 0,
"o_count": 2},
"Nine circles":{
"path":"tests/nine_circles.jpg",
"x_count": 0,
"o_count": 9},
"Nine crosses":{
"path":"tests/nine_crosses.jpg",
"x_count": 9,
"o_count": 0},
"Small empty board":{
"path":"tests/small_empty_board.jpg",
"x_count": 0,
"o_count": 0},
"Small, X=1":{
"path":"tests/small_one_cross.jpg",
"x_count": 1,
"o_count": 0},
"Small, X=6":{
"path":"tests/small_six_cross.jpg",
"x_count": 6,
"o_count": 0},
"FullHD, small, O=2, X=1":{
"path":"tests/fullhd_small_2O_1X.jpg",
"x_count": 1,
"o_count": 2},
"FullHD, small, O=3, X=3":{
"path":"tests/fullhd_small_3O_3X.jpg",
"x_count": 3,
"o_count": 3},
"Narrow lines, O=1, X=2":{
"path":"tests/narrow_lines_1O_2X.jpg",
"x_count": 2,
"o_count": 1},
}
print_header()
count = 0
for title in tests:
test = tests[title]
image = cv2.imread(test["path"])
status = []
try:
gameboard = Gameboard.detect_game_board(image, debug=False)
status = gameboard.status()
except Exception:
status = []
x_count = len([pos for pos in status if pos == "X"])
o_count = len([pos for pos in status if pos == "O"])
result = "*FAILED*"
if (x_count == test["x_count"] and o_count == test["o_count"]):
result = " PASSED "
count += 1
print("{0:40} {1:10}(O={2}, X={3})".format(title.upper(), result, o_count, x_count))
print("\nOK! {0}/{1} tests passed".format(count, len(tests)))
if __name__=="__main__":
main()