Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@ on: [push]

jobs:
pylama:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
- name: Install tox
run: pip install tox
- name: Run linting with tox
run: tox -e lint

mypy:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
- name: Install tox
run: pip install tox
- name: Run type checks with tox
run: tox -e static

unittest:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11
- name: Install tox
run: pip install tox
- name: Run unit tests with tox
Expand Down
17 changes: 8 additions & 9 deletions dgt/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from utilities import AsyncRepeatingTimer, DisplayMsg, hms_time
import asyncio


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -83,13 +82,13 @@ class DgtBoard(EBoard):
"""Handle the DGT board communication."""

def __init__(
self,
device: str,
disable_revelation_leds: bool,
is_pi: bool,
disable_end: bool,
loop: asyncio.AbstractEventLoop,
field_factor=0,
self,
device: str,
disable_revelation_leds: bool,
is_pi: bool,
disable_end: bool,
loop: asyncio.AbstractEventLoop,
field_factor=0,
):
super(DgtBoard, self).__init__()
self.given_device = device
Expand Down Expand Up @@ -470,7 +469,7 @@ def _process_board_message(self, message_id: int, message: tuple, message_length
board = ""
for character in message:
board += piece_to_char[character & 0x0F]
logger.debug("\n" + "\n".join(board[0 + i : 8 + i] for i in range(0, len(board), 8))) # Show debug board
logger.debug("\n" + "\n".join(board[0 + i: 8 + i] for i in range(0, len(board), 8))) # Show debug board
# Create fen from board
fen = ""
empty = 0
Expand Down
5 changes: 2 additions & 3 deletions eboard/certabo/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from eboard.certabo.sentio import Sentio
from eboard.certabo.usb_transport import Transport


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -187,11 +186,11 @@ def _event_worker_thread(self):
msg = self.trque.get()
token = "agent-state: "
if msg[: len(token)] == token:
toks = msg[len(token) :]
toks = msg[len(token):]
i = toks.find(" ")
if i != -1:
state = toks[:i]
emsg = toks[i + 1 :]
emsg = toks[i + 1:]
else:
state = toks
emsg = ""
Expand Down
1 change: 0 additions & 1 deletion eboard/certabo/usb_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

usb_support = True
except ImportError:
serial = None
usb_support = False


Expand Down
5 changes: 2 additions & 3 deletions eboard/chesslink/chess_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import eboard.chesslink.chess_link_protocol as clp
import eboard.chesslink.chess_link_bluepy as tri


# See document:
# `magic-board.md <https://github.com/domschl/python-mchess/blob/master/mchess/magic-board.md>_
# for details on the Chess Link protocol.
Expand Down Expand Up @@ -292,11 +291,11 @@ def _event_worker_thread(self, que, mutex):
msg = self.trque.get()
token = "agent-state: "
if msg[: len(token)] == token:
toks = msg[len(token) :]
toks = msg[len(token):]
i = toks.find(" ")
if i != -1:
state = toks[:i]
emsg = toks[i + 1 :]
emsg = toks[i + 1:]
else:
state = toks
emsg = ""
Expand Down
2 changes: 1 addition & 1 deletion eboard/chessnut/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse(self, msg: bytearray):
def _parse_position(self, data, index):
data_length = 36
if len(data) >= (index + data_length + 2):
data = data[index + 2 :]
data = data[index + 2:]
index += data_length + 1
return index, data
else:
Expand Down
4 changes: 2 additions & 2 deletions eboard/chessnut/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def _event_worker_thread(self):
msg = self.trque.get()
token = "agent-state: "
if msg[: len(token)] == token:
toks = msg[len(token) :]
toks = msg[len(token):]
i = toks.find(" ")
if i != -1:
state = toks[:i]
emsg = toks[i + 1 :]
emsg = toks[i + 1:]
else:
state = toks
emsg = ""
Expand Down
2 changes: 1 addition & 1 deletion eboard/ichessone/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse(self, msg: bytearray):
def _parse_position(self, data, index):
data_length = 32
if len(data) >= (index + data_length + 2):
data = data[index + 2 :]
data = data[index + 2:]
index += data_length + 1
return index, data
else:
Expand Down
4 changes: 2 additions & 2 deletions eboard/ichessone/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def _event_worker_thread(self):
msg = self.trque.get()
token = "agent-state: "
if msg[: len(token)] == token:
toks = msg[len(token) :]
toks = msg[len(token):]
i = toks.find(" ")
if i != -1:
state = toks[:i]
emsg = toks[i + 1 :]
emsg = toks[i + 1:]
else:
state = toks
emsg = ""
Expand Down
2 changes: 1 addition & 1 deletion eboard/move_debouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def stop(self):
self.timer.cancel()

def _shall_start_timer(self, short_fen: str):
self.previous_fens = self.previous_fens[len(self.previous_fens) - 2 :] # keep two entries max
self.previous_fens = self.previous_fens[len(self.previous_fens) - 2:] # keep two entries max
for previous in self.previous_fens:
if self._is_move_extendable(previous, short_fen):
self.previous_fens = []
Expand Down
63 changes: 31 additions & 32 deletions engines/pgn_engine/pgn_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
p_pgn_game_file = "/opt/picochess/games/last_game.pgn"
p_engine_path = "/opt/picochess/engines/aarch64/a-stockf"
p_audio_comment = ""
p_game_sequence = "backward" ## possible values: random, forward, backward
##p_pgn_game_file = '/Users/molli/Desktop/games/mate_in_two.pgn'
##p_pgn_game_file = '/Users/molli/Desktop/games/games.pgn'
##p_pgn_game_file = '/Users/molli/Desktop/games/fool.pgn'
##p_engine_path = '/Users/molli/Documents/stockfish-9-mac/Mac/stockfish-9-bmi2'
##p_audio_comment = '/Users/molli/Desktop/hoerspiel_NwZ.mp3'
p_game_sequence = "backward" # possible values: random, forward, backward
# p_pgn_game_file = '/Users/molli/Desktop/games/mate_in_two.pgn'
# p_pgn_game_file = '/Users/molli/Desktop/games/games.pgn'
# p_pgn_game_file = '/Users/molli/Desktop/games/fool.pgn'
# p_engine_path = '/Users/molli/Documents/stockfish-9-mac/Mac/stockfish-9-bmi2'
# p_audio_comment = '/Users/molli/Desktop/hoerspiel_NwZ.mp3'
flag_audio_playing = False
p_think_time = 3
think_time = 0
Expand Down Expand Up @@ -161,17 +161,17 @@ def get_move():
if is_uci and game_started:

if "book.pgn" in p_pgn_game_file:
## for book test return ABORT to notify that last move wasn't a book move
# for book test return ABORT to notify that last move wasn't a book move
uci_move = "ABORT"
ponder_move = ""
elif max_moves == 0 or move_counter > (max_moves - 1):
## game over
# game over
uci_move = "ABORT"
ponder_move = ""
info_str = "info depth 999 multipv 1 score cp 999"
else:

## get next move
# get next move
move_pgn = move_list[move_counter]
move_counter = move_counter + 1
# Do NOT: push the board here because it might be a wrong guess
Expand All @@ -183,15 +183,14 @@ def get_move():
log.write("new move_counter %s\n" % str(move_counter))

if think_time > 0:

move = ""
ponder_move = ""

info_str = "info depth 0"

ponder_move = move ## molli: the ponder move for pico is the current engine move
##else:
##ponder_move = move_list[move_counter]
ponder_move = move # molli: the ponder move for pico is the current engine move
# else:
# ponder_move = move_list[move_counter]

if move_pgn == "0000" or move_pgn == "ABORT" or move_pgn == "":
uci_move = "ABORT"
Expand Down Expand Up @@ -250,10 +249,10 @@ def get_orig_game_index(find_game):
found = True
i = i + 1

##for game in orig_game_list:
## if game.headers == find_game.headers:
## orig_index = i
## i = i + 1
# for game in orig_game_list:
# if game.headers == find_game.headers:
# orig_index = i
# i = i + 1

return orig_index

Expand Down Expand Up @@ -298,11 +297,11 @@ def newgame():
move_list = []

if game_counter == 0:
## reset list to all games
# reset list to all games
game_counter = max_games
game_list = orig_game_list.copy()

## get game from remaining games by specified sequence
# get game from remaining games by specified sequence
if p_game_sequence == "random":
game_index = int(random.randint(0, game_counter - 1))
elif p_game_sequence == "forward":
Expand Down Expand Up @@ -363,22 +362,22 @@ def newgame():

if log:
log.write("FEN: %s\n" % str(fen))
## delete this game from current list
# delete this game from current list
if l_continue:
del game_list[game_index]
game_counter = game_counter - 1

## create move list of the new game
# create move list of the new game
move_counter = 0
max_moves = 0

## create new game board
# create new game board
board = get_start_pos(board)
input_board = get_start_pos(input_board)

i = 0
if l_continue:
for move in pgn_game.mainline_moves(): ## molli: later mainline_moves() for python-chess 25
for move in pgn_game.mainline_moves(): # molli: later mainline_moves() for python-chess 25
i = i + 1
move_list.append(move.uci())

Expand All @@ -389,7 +388,7 @@ def newgame():
log.write("Number of moves: %s\n" % str(max_moves))
log.flush()

## log current pgn game infos for picochess control in main program
# log current pgn game infos for picochess control in main program

try:
log_p = open(log_file_pgn_info, "w")
Expand Down Expand Up @@ -526,7 +525,7 @@ def set_move_counter_from_fen(last_move):
line = input()
except KeyboardInterrupt: # XBoard sends Control-C characters, so these must be caught
if not is_uci:
pass # Otherwise Python would quit.
pass # Otherwise Python would quit.

mstart_t = int(time.time())

Expand Down Expand Up @@ -581,7 +580,7 @@ def set_move_counter_from_fen(last_move):

input_board = chess.Board()

for mo in mm: ## get last move and set current position
for mo in mm: # get last move and set current position
input_board.push(chess.Move.from_uci(mo))
last_move = mo

Expand All @@ -598,14 +597,14 @@ def set_move_counter_from_fen(last_move):
elif "position startpos" in line:
input_board = chess.Board()
move_counter = 0
##game_started = True
# game_started = True

if log:
log.write("position startpos ready\n")
log.flush()

elif "position fen" in line:
##game_started = True
# game_started = True
if line == last_fen_line:
if log:
log.write("WARNING: input fen (double)")
Expand All @@ -622,7 +621,7 @@ def set_move_counter_from_fen(last_move):

input_board = chess.Board(ff)

for mo in mm: ## get last move and set current position
for mo in mm: # get last move and set current position
input_board.push(chess.Move.from_uci(mo))
last_move = mo

Expand Down Expand Up @@ -660,7 +659,7 @@ def set_move_counter_from_fen(last_move):

elif line == "isready":
j = 0
## load pgn file
# load pgn file
if p_pgn_game_file:
l_continue = True
try:
Expand Down Expand Up @@ -708,7 +707,7 @@ def set_move_counter_from_fen(last_move):
pub_move()

elif line == "stop":
## if pygame.mixer.music.get_busy():
# if pygame.mixer.music.get_busy():
if flag_audio_playing:
pygame.mixer.music.pause()
flag_audio_playing = False
Expand All @@ -729,4 +728,4 @@ def set_move_counter_from_fen(last_move):
if len(line) == 4 and is_uci and game_started:
if line[0] in abc and line[2] in abc and line[1] in nn and line[3] in nn:
move = line
push_uci_move(move) ## just for testing
push_uci_move(move) # just for testing
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[mypy]
warn_unused_configs = True
disable_error_code = annotation-unchecked
exclude = (?x)(
^venv/
)
Expand Down
Loading
Loading