def process_console_command(self, raw): cmd = raw.lower() try: # Here starts the simulation of a dgt-board! # Let the user send events like the board would do if cmd.startswith('fen:'): fen = raw.split(':')[1].strip() # dgt board only sends the basic fen => be sure it's same no matter what fen the user entered fen = fen.split(' ')[0] bit_board = chess.Board() # valid the fen bit_board.set_board_fen(fen) EvtObserver.fire(Event.KEYBOARD_FEN(fen=fen)) # end simulation code elif cmd.startswith('go'): if 'last_dgt_move_msg' in self.shared: fen = self.shared['last_dgt_move_msg']['fen'].split(' ')[0] EvtObserver.fire(Event.KEYBOARD_FEN(fen=fen)) # TEST webserver with 2 clocks (web & i2c) - doesnt work anymore with normal dgt board! elif cmd.startswith('but:'): button = raw.split(':')[1].strip() MsgDisplay.show(Message.DGT_BUTTON(button=button, dev='i2c')) else: # Event.KEYBOARD_MOVE tranfers "move" to "fen" and then continues with "Message.DGT_FEN" move = chess.Move.from_uci(cmd) EvtObserver.fire(Event.KEYBOARD_MOVE(move=move)) except (ValueError, IndexError): logging.warning('Invalid user input [%s]', raw)
def process_console_command(self, raw): cmd = raw.lower() try: # Here starts the simulation of a dgt-board! # Let the user send events like the board would do if cmd.startswith('fen:'): fen = raw.split(':')[1].strip() # dgt board only sends the basic fen => be sure it's same no matter what fen the user entered fen = fen.split(' ')[0] bit_board = chess.Board() # valid the fen bit_board.set_board_fen(fen) Observable.fire(Event.KEYBOARD_FEN(fen=fen)) # end simulation code elif cmd.startswith('go'): if 'last_dgt_move_msg' in self.shared: fen = self.shared['last_dgt_move_msg']['fen'].split(' ')[0] Observable.fire(Event.KEYBOARD_FEN(fen=fen)) else: # Event.KEYBOARD_MOVE tranfers "move" to "fen" and then continues with "Message.DGT_FEN" move = chess.Move.from_uci(cmd) Observable.fire(Event.KEYBOARD_MOVE(move=move)) except (ValueError, IndexError): logging.warning('Invalid user input [%s]', raw)
def run(self): logging.info('evt_queue ready') print('#' * 42 + ' PicoChess v' + version + ' ' + '#' * 42) print('To play a move enter the from-to squares like "e2e4". To play this move on board, enter "go".') print('When the computer displays its move, also type "go" to actually do it on the board (see above).') print('Other commands are:') print('newgame:<w|b>, print:<fen>, setup:<fen>, fen:<fen>, button:<0-5>, lever:<l|r>, plug:<in|off>') print('') print('This console mode is mainly for development. Better activate picochess together with a DGT-Board ;-)') print('#' * 100) print('') while True: raw = input('PicoChess v'+version+':>').strip() if not raw: continue cmd = raw.lower() try: if cmd.startswith('print:'): fen = raw.split(':')[1] print(chess.Board(fen)) else: if not self.board_plugged_in and not cmd.startswith('plug:'): print('The command isnt accepted cause the virtual board is not plugged in') continue if cmd.startswith('newgame:'): side = cmd.split(':')[1] if side == 'w': self.flip_board = False self.fire(Event.DGT_FEN(fen='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR')) elif side == 'b': self.flip_board = True self.fire(Event.DGT_FEN(fen='RNBKQBNR/PPPPPPPP/8/8/8/8/pppppppp/rnbkqbnr')) else: raise ValueError(side) elif cmd.startswith('setup:'): fen = raw.split(':')[1] uci960 = False # make it easy for the moment bit_board = chess.Board(fen, uci960) if bit_board.is_valid(): self.fire(Event.SETUP_POSITION(fen=bit_board.fen(), uci960=uci960)) else: raise ValueError(fen) # Here starts the simulation of a dgt-board! # Let the user send events like the board would do elif cmd.startswith('fen:'): fen = raw.split(':')[1] # dgt board only sends the basic fen => be sure # it's same no matter what fen the user entered self.fire(Event.DGT_FEN(fen=fen.split(' ')[0])) elif cmd.startswith('button:'): button = int(cmd.split(':')[1]) if button not in range(6): raise ValueError(button) if button == 5: # make it to power button button = 0x11 self.fire(Event.KEYBOARD_BUTTON(button=button, dev = 'ser')) elif cmd.startswith('lever:'): lever = cmd.split(':')[1] if lever not in ('l', 'r'): raise ValueError(lever) button = 0x40 if lever == 'r' else -0x40 self.fire(Event.KEYBOARD_BUTTON(button=button, dev = 'ser')) elif cmd.startswith('plug:'): plug = cmd.split(':')[1] if plug not in ('in', 'off'): raise ValueError(plug) if plug == 'in': self.board_plugged_in = True self.rt.stop() text_l, text_m, text_s = 'VirtBoard ', 'V-Board ', 'VBoard' text = Dgt.DISPLAY_TEXT(l=text_l, m=text_m, s=text_s, wait=True, beep=False, maxtime=1) DisplayMsg.show(Message.EBOARD_VERSION(text=text, channel='console')) if plug == 'off': self.board_plugged_in = False self.rt.start() elif cmd.startswith('go'): if keyboard_last_fen is not None: self.fire(Event.KEYBOARD_FEN(fen=keyboard_last_fen)) else: print('last move already send to virtual board') elif cmd.startswith('shutdown'): self.fire(Event.SHUTDOWN()) # end simulation code else: # move => fen => virtual board sends fen move = chess.Move.from_uci(cmd) self.fire(Event.KEYBOARD_MOVE(move=move)) except ValueError as e: logging.warning('Invalid user input [%s]', raw)