-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoardLauncher.py
executable file
·133 lines (108 loc) · 4.02 KB
/
BoardLauncher.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
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
#!/bin/python
from subprocess import call
from subprocess import check_output
from random import randrange
from threading import Thread
from sys import argv
from os import path, chdir
from json import dumps, loads
from chessArena.settings import Settings
settings = Settings()
from evchess_evolve.core import loadmachines, setmachines
# print(VerboseMove)
class DuelTable():
def __init__(self):
print("""
loading machines from Hall of Fame.
Choose your opponent:
""")
self.AllMachines = loadmachines(DIR=settings.TOPmachineDIR)
print("zero")
print("0 - random")
for M in range(len(self.AllMachines)):
view = '%i - %s' % (M+1, self.AllMachines[M].filename)
view += " " * (30-len(view)) + "%i :%i" %\
(self.AllMachines[M].ELO,
self.AllMachines[M].getParameter("real_world_score"))
print(view)
print("")
LOADED = 0
self.AgainstMachine = False
userchoice = self.CollectInput(
[x for x in range(len(self.AllMachines)+1)])
if not userchoice:
userchoice = randrange(len(self.AllMachines))+1
else:
pass
#choices = userchoice.split(" ")
Callargs = [settings.enginebin, "--deep", '4', '--xdeep', '1', '--showinfo']
if userchoice != "zero":
LOADED = 1
userchoice -= 1
print('Loading %s. glhf' % self.AllMachines[userchoice].filename)
Callargs += ['--specific', self.AllMachines[userchoice].filename]
self.engineCALL = " ".join(Callargs)
if self.AgainstMachine:
GAME = Thread(target=self.LaunchXboardMachineXMachine)
else:
GAME = Thread(target=self.LaunchXboardAgainstMachine)
GAME.start()
LOGGER = Thread(target=self.StraceAndLogGame)
LOGGER.start()
if LOADED:
try:
print("Did this machine win the game? [y/n]")
FeedBack = self.CollectInput(['y', 'n'])
except KeyboardInterrupt:
print("\n")
exit()
if FeedBack == 'y':
result = 1
print("logically.")
else:
result = -1
print("a bad day for the computer age.")
self.AllMachines[userchoice].getParameter("real_world_score",
toSUM=result)
setmachines(self.AllMachines, DIR=settings.TOPmachineDIR)
def CollectInput(self, ValidValues):
userchoice = None
while userchoice == None:
Machine=0
userchoice = input(">>>")
if userchoice == "zero":
break
try:
engines=['gnuchess', 'roce395', 'rocinante']
for E in engines:
if userchoice.endswith(E):
userchoice = userchoice[:len(userchoice)-len(E)]
Machine=E
userchoice = int(userchoice)
except ValueError:
userchoice = userchoice.lower()
try:
assert(userchoice in ValidValues)
except:
userchoice = None
print("Invalid input. Try again.")
if Machine:
self.AgainstMachine = Machine
return userchoice
def LaunchXboardAgainstMachine(self):
Command = ['xboard', '-fcp', self.engineCALL]
call(Command)
def LaunchXboardMachineXMachine(self):
Command =['xboard', '-fcp', self.engineCALL, '-scp', self.AgainstMachine]
call(Command)
def StraceAndLogGame(self):
PID = check_output(['ps', 'aux'])
PID = PID.decode('utf-8').split("\n")
print(len(PID))
for line in PID:
if self.engineCALL[-1] in line:
#print("vdd")
#print (line)
pass
chdir(path.dirname(path.realpath(__file__)))
x = DuelTable()