Skip to content

Commit

Permalink
Record pass and illegal move to sgf file
Browse files Browse the repository at this point in the history
  • Loading branch information
zakki committed Feb 26, 2024
1 parent 93ead87 commit 4bbe184
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions server-python/cgos/app/cgos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,12 @@ def _handle_player_genmove(sock: Client, data: str) -> None:
gameover(gid, over, "")
return

def add_move(mv: str):
if ctm & 1:
game.moves.append((mv, wrt, analysis))
else:
game.moves.append((mv, brt, analysis))

if mv.lower() == "resign":
err = 0
over = maybe
Expand All @@ -1062,7 +1068,8 @@ def _handle_player_genmove(sock: Client, data: str) -> None:
# nsend $w "play b $mv $brt"
vmsg = f"{mv} {brt}"
viewers.sendObservers(gid, f"update {gid} {vmsg}")
gameover(gid, over, "")
add_move("resign")
gameover(gid, over, "Resignation")
return
else:
err = gme[gid].make(mv)
Expand All @@ -1071,16 +1078,13 @@ def _handle_player_genmove(sock: Client, data: str) -> None:
xerr = err * -1
over = maybe
over += "Illegal"
gameover(gid, over, ERR_MSG[xerr])
add_move("pass")
gameover(gid, over, f"Illegal move error:{ERR_MSG[xerr]} move:{mv}")
return

# record the moves and times
# --------------------------
if ctm & 1:
game.moves.append((mv, wrt, analysis))
else:
game.moves.append((mv, brt, analysis))
games[gid].moves = game.moves
add_move(mv)

if game.w == who:
nsend(game.b, f"play w {mv} {wrt}")
Expand Down
2 changes: 1 addition & 1 deletion server-python/cgos/gogame/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def sgf(
mv = m.lower()
tleft = t // 1000

if mv.startswith("pas"):
if mv.startswith("pas") or mv == "resign":
s += f";{colstr[ctm]}[]{colstr[ctm]}L[{tleft}]"
else:
ccs = ord(mv[0])
Expand Down

0 comments on commit 4bbe184

Please sign in to comment.