-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcfRunner.py
More file actions
70 lines (61 loc) · 1.95 KB
/
cfRunner.py
File metadata and controls
70 lines (61 loc) · 1.95 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
import chip
import cfLogic
from chip import *
allWinningLocations = [[0 for c in range(7)] for r in range(6)]
for i in range(100000):
cf = cfLogic.ConnectFour()
#cf.printBoard()
cf.getPossibleMoves()
flag = True
gameOver = False
winningSpots = []
winningSpots.clear()
while not gameOver:
while(flag):
#print("Red Turn")
slot = cfLogic.chooseRandSlot(cf,'R')
if slot == -1: #board is full
gameOver = True
winningSpots = []
break
inserted = Chip('R')
if(cf.addPiece(inserted,slot)):
#cf.printBoard()
flag = False
tup = cf.checkForWin(inserted)
if(tup[0]):
winningSpots = tup[1]
gameOver = True
#else:
#print("filled, pick another")
flag = True
while(flag and not gameOver):
#print("Yellow Turn")
slot = cfLogic.chooseRandSlot(cf,'Y')
if slot == -1: #board is full
gameOver = True
winningSpots = []
break
inserted = Chip('Y')
if(cf.addPiece(inserted,slot)):
#cf.printBoard()
flag = False
tup = cf.checkForWin(inserted)
if(tup[0]):
winningSpots = tup[1]
gameOver = True
#else:
#print("filled, pick another")
flag = True
# cf.printBoard()
# print()
# printSpotLocations(winningSpots)
for spot in winningSpots:
allWinningLocations[spot.row][spot.col] += 1
if i % 10000 == 0:
print(i/1000)
for x in range(len(allWinningLocations)):
print('|',end=' ')
for y in range(len(allWinningLocations[x])):
print(allWinningLocations[x][y], end=' | ')
print('','\n')