Skip to content

Commit

Permalink
python bot: fix #379 (#380)
Browse files Browse the repository at this point in the history
- replace unmaintained dependency socketIO_client with socketIO_client_nexus
 - handle new message 'update'
  • Loading branch information
francoijs authored and nicolodavis committed Mar 15, 2019
1 parent a34c036 commit c1ee6f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 9 additions & 5 deletions python/boardgameio.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"""

import logging
import socketIO_client as io
import socketIO_client_nexus as io

class Namespace(io.BaseNamespace):
"""
Expand Down Expand Up @@ -47,8 +47,12 @@ def on_reconnect(self):
""" Handle reconnection event. """
self.log.info('reconnected')

def on_update(self, *args):
""" Handle server 'update' event. """
self.on_sync(*args)

def on_sync(self, *args):
""" Handle serve 'sync' event. """
""" Handle server 'sync' event. """
game_id = args[0]
state = args[1]
state_id = state['_stateID']
Expand Down Expand Up @@ -77,7 +81,7 @@ def on_sync(self, *args):
# pop next action
action = self.actions.pop(0)
self.log.info('sent action: %s', action['payload'])
self.emit('action', action, state_id, game_id,
self.emit('update', action, state_id, game_id,
self.bot.player_id)


Expand Down Expand Up @@ -144,11 +148,11 @@ def think(self, _G, _ctx):
To be overridden by the user.
Shall return a list of actions, instantiated with make_move().
"""
assert False
raise NotImplementedError

def gameover(self, _G, _ctx):
"""
To be overridden by the user.
Shall handle game over.
"""
assert False
raise NotImplementedError
12 changes: 10 additions & 2 deletions python/test_boardgameio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import unittest
import logging
import mock
import socketIO_client as io
import socketIO_client_nexus as io
from boardgameio import Namespace, Bot


Expand Down Expand Up @@ -46,7 +46,15 @@ def test_on_sync_shall_call_think(self):
# call Namespace.on_sync()
self.sut.on_sync(self.botmock.game_id, self.game_state)
self.botmock.think.assert_called_once_with(self.game_state['G'], self.game_state['ctx'])
self.sut.emit.assert_called_once_with('action', self.resulting_move,
self.sut.emit.assert_called_once_with('update', self.resulting_move,
self.game_state['_stateID'],
self.botmock.game_id, self.botmock.player_id)

def test_on_update_shall_call_think(self):
# call Namespace.on_update()
self.sut.on_update(self.botmock.game_id, self.game_state)
self.botmock.think.assert_called_once_with(self.game_state['G'], self.game_state['ctx'])
self.sut.emit.assert_called_once_with('update', self.resulting_move,
self.game_state['_stateID'],
self.botmock.game_id, self.botmock.player_id)

Expand Down

0 comments on commit c1ee6f3

Please sign in to comment.