-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhorse_04_worstnext.py
106 lines (72 loc) · 1.72 KB
/
horse_04_worstnext.py
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
#!/usr/bin/python3
from random import randint
from time import sleep
# Constants
w = 8
h = 8
Moves = [(-1, 2), (-2, 1), (-2, -1), (-1, -2), (1, 2), (2, 1), (2, -1), (1, -2)]
# Init
gamecnt = 0
compcnt = 0
# Functions
# Print the current board state
def PrintBoard(inBoard, dim_h):
for i in range(dim_h):
print(inBoard[i])
print("")
# get all valid moves from a specific location
def validMoves(inX, inY, inBoard):
validMvs = []
# nomenclature "t" test, "m" move, "in" input
for tY, tX in Moves:
mX = inX + tX
mY = inY + tY
if 0 <= mX < 8 and 0 <= mY < 8 and Board[mY][mX] == "XX":
validMvs.append((mX, mY))
return validMvs
# main
while True:
# Per attempt init
Board = [["XX" for x in range(w)] for y in range(h)]
gamecnt += 1
mv_num = 1
# random position on board
y = randint(0,7)
x = randint(0,7)
Board[y][x] = "01"
# worry dots
if gamecnt % 100000 == 0:
print("Game Count:", gamecnt)
# per move action
while True:
mvList = validMoves(x, y, Board)
if len(mvList) == 0: # we are done
break
elif len(mvList) == 1: # take what we have got
x, y = mvList[0]
elif len(mvList) > 1:
chkList = []
for i, j in mvList:
tmpList = validMoves(i, j, Board)
z = len(tmpList)
chkList.append((z, (i, j)))
chkList.sort(key=lambda tup: tup[0])
min = chkList[0][0]
i = j = 0
while i < len(chkList):
if i == min:
j += 1 # counts the number of the highest value
i += 1
x, y = chkList[randint(0, j)][1]
mv_num += 1
if mv_num < 10:
bVal = "0" + str(mv_num)
else:
bVal = str(mv_num)
Board[y][x] = bVal
if mv_num >= 64:
compcnt += 1
print("Game Count:", gamecnt)
print("Complete Count:", compcnt)
PrintBoard(Board,h)
break