Thibault Duplessis commited on
Commit
148fdc5
·
1 Parent(s): a9e22a2

UCI first

Browse files
Files changed (1) hide show
  1. engine_wrapper.py +40 -38
engine_wrapper.py CHANGED
@@ -55,6 +55,46 @@ class EngineWrapper:
55
  if stat in info:
56
  print(" {}: {}".format(stat, info[stat]))
57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  class XBoardEngine(EngineWrapper):
59
 
60
  def __init__(self, board, commands):
@@ -98,41 +138,3 @@ class XBoardEngine(EngineWrapper):
98
 
99
  def print_stats(self):
100
  self.print_handler_stats(self.engine.post_handlers[0].post, ["depth", "nodes", "score"])
101
-
102
- class UCIEngine(EngineWrapper):
103
-
104
- def __init__(self, board, commands, options):
105
- commands = commands[0] if len(commands) == 1 else commands
106
- self.engine = chess.uci.popen_engine(commands)
107
-
108
- self.engine.uci()
109
-
110
- if options:
111
- self.engine.setoption(options)
112
-
113
- self.engine.setoption({
114
- "UCI_Variant": type(board).uci_variant,
115
- "UCI_Chess960": board.chess960
116
- })
117
- self.engine.position(board)
118
-
119
- info_handler = chess.uci.InfoHandler()
120
- self.engine.info_handlers.append(info_handler)
121
-
122
- def first_search(self, board, movetime):
123
- self.engine.position(board)
124
- best_move, _ = self.engine.go(wtime=movetime,btime=movetime)
125
- return best_move
126
-
127
- def search(self, board, wtime, btime, winc, binc):
128
- self.engine.position(board)
129
- best_move, _ = self.engine.go(
130
- wtime=wtime,
131
- btime=btime,
132
- winc=winc,
133
- binc=binc
134
- )
135
- return best_move
136
-
137
- def print_stats(self):
138
- self.print_handler_stats(self.engine.info_handlers[0].info, ["string", "depth", "nps", "nodes", "score"])
 
55
  if stat in info:
56
  print(" {}: {}".format(stat, info[stat]))
57
 
58
+
59
+ class UCIEngine(EngineWrapper):
60
+
61
+ def __init__(self, board, commands, options):
62
+ commands = commands[0] if len(commands) == 1 else commands
63
+ self.engine = chess.uci.popen_engine(commands)
64
+
65
+ self.engine.uci()
66
+
67
+ if options:
68
+ self.engine.setoption(options)
69
+
70
+ self.engine.setoption({
71
+ "UCI_Variant": type(board).uci_variant,
72
+ "UCI_Chess960": board.chess960
73
+ })
74
+ self.engine.position(board)
75
+
76
+ info_handler = chess.uci.InfoHandler()
77
+ self.engine.info_handlers.append(info_handler)
78
+
79
+ def first_search(self, board, movetime):
80
+ self.engine.position(board)
81
+ best_move, _ = self.engine.go(wtime=movetime,btime=movetime)
82
+ return best_move
83
+
84
+ def search(self, board, wtime, btime, winc, binc):
85
+ self.engine.position(board)
86
+ best_move, _ = self.engine.go(
87
+ wtime=wtime,
88
+ btime=btime,
89
+ winc=winc,
90
+ binc=binc
91
+ )
92
+ return best_move
93
+
94
+ def print_stats(self):
95
+ self.print_handler_stats(self.engine.info_handlers[0].info, ["string", "depth", "nps", "nodes", "score"])
96
+
97
+
98
  class XBoardEngine(EngineWrapper):
99
 
100
  def __init__(self, board, commands):
 
138
 
139
  def print_stats(self):
140
  self.print_handler_stats(self.engine.post_handlers[0].post, ["depth", "nodes", "score"])