Skip to content

Commit d681e2e

Browse files
authored
Merge pull request niklasf#165 from Mk-Chan/master
Added stop() command and removed buggy option testing
2 parents dec8941 + 8a7923e commit d681e2e

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ before_install:
3737
- make unix-gcc
3838
- export PATH="`pwd`:${PATH}"
3939
- cd ..
40-
- # WyldChess
41-
- git clone https://github.com/Mk-Chan/WyldChess
42-
- cd WyldChess/src
43-
- make
44-
- export PATH="`pwd`:${PATH}"
45-
- cd ../..
4640
- # Gaviota libgtb
4741
- git clone https://github.com/michiguel/Gaviota-Tablebases.git --depth 1
4842
- cd Gaviota-Tablebases

chess/xboard.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,36 @@ def command():
875875

876876
return self._queue_command(command, async_callback)
877877

878+
def stop(self, async_callback=None):
879+
"""
880+
Stop calculating as soon as possible. The actual XBoard command is `?`.
881+
882+
:return: Nothing.
883+
"""
884+
# Only send stop when the engine is actually searching.
885+
def command():
886+
with self.semaphore:
887+
with self.state_changed:
888+
if not self.idle:
889+
self.search_started.wait()
890+
891+
backoff = 0.5
892+
while not self.move_received.is_set() and not self.terminated.is_set():
893+
if self.idle:
894+
break
895+
else:
896+
self.send_line("?")
897+
self.move_received.wait(backoff)
898+
backoff *= 2
899+
900+
self.idle = True
901+
self.state_changed.notify_all()
902+
903+
if self.terminated.is_set():
904+
raise EngineTerminatedException()
905+
906+
return self._queue_command(command, async_callback)
907+
878908
def usermove(self, move, async_callback=None):
879909
"""
880910
Tell the XBoard engine to make a move on it's internal

test.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,30 +2148,6 @@ def test_wierd_header(self):
21482148
self.assertEqual(game.headers["Black"], "[=0040.34h5a4]")
21492149

21502150

2151-
class WyldTestCase(unittest.TestCase):
2152-
2153-
def setUp(self):
2154-
try:
2155-
self.engine = chess.xboard.popen_engine("wyldchess")
2156-
except OSError:
2157-
self.skipTest("need wyldchess")
2158-
2159-
self.engine.xboard()
2160-
2161-
def tearDown(self):
2162-
self.engine.quit()
2163-
2164-
def test_options(self):
2165-
self.engine.new()
2166-
self.engine.st(2)
2167-
self.engine.sd(100)
2168-
option_dict = { "MoveOverhead" : 1900 };
2169-
self.engine.option(option_dict)
2170-
self.engine.go(async_callback=True)
2171-
time.sleep(0.2)
2172-
self.assertTrue(self.engine.idle, True)
2173-
2174-
21752151
class CraftyTestCase(unittest.TestCase):
21762152

21772153
def setUp(self):
@@ -2191,6 +2167,13 @@ def test_level(self):
21912167
self.engine.level(1, 0, 1, 0)
21922168
self.engine.go()
21932169

2170+
def test_stop(self):
2171+
self.engine.new()
2172+
self.engine.time(1000000)
2173+
self.engine.go(async_callback=True)
2174+
time.sleep(0.1)
2175+
self.engine.stop()
2176+
21942177
def test_time(self):
21952178
self.engine.new()
21962179
self.engine.level(0, 1, 0, 0)

0 commit comments

Comments
 (0)