Yohaan Seth Nathan commited on
Commit
d484b5b
·
1 Parent(s): 1a8e627

Kyotoshogi Support

Browse files

https://github.com/WandererXII/lishogi/commit/5977c201c9c7c0a0a376df7072e56e3d215081ea

Files changed (4) hide show
  1. config.yml.default +2 -0
  2. engine_wrapper.py +8 -2
  3. lishogi-bot.py +14 -4
  4. model.py +4 -1
config.yml.default CHANGED
@@ -55,6 +55,8 @@ challenge: # Incoming challenges.
55
  - standard
56
  # - minishogi
57
  # - chushogi
 
 
58
  time_controls: # Time controls to accept.
59
  - ultraBullet
60
  - bullet
 
55
  - standard
56
  # - minishogi
57
  # - chushogi
58
+ # - annanshogi
59
+ # - kyotoshogi
60
  time_controls: # Time controls to accept.
61
  - ultraBullet
62
  - bullet
engine_wrapper.py CHANGED
@@ -54,13 +54,19 @@ class EngineWrapper:
54
  pass
55
 
56
  def search_for(self, board, game, movetime):
57
- moves = "" if game.variant_name == "Standard" else game.state["moves"].split()
 
 
 
58
  sfen = board.sfen() if game.variant_name == "Standard" else game.initial_sfen
59
  self.engine.set_variant_options(game.variant_name.lower())
60
  return self.search(sfen, moves, movetime=movetime // 1000)
61
 
62
  def search_with_ponder(self, game, board, btime, wtime, binc, winc, byo, ponder=False):
63
- moves = [m.usi() for m in list(board.move_stack)] if game.variant_name == "Standard" else game.state["moves"].split()
 
 
 
64
  sfen = game.initial_sfen
65
  cmds = self.go_commands
66
  movetime = cmds.get("movetime")
 
54
  pass
55
 
56
  def search_for(self, board, game, movetime):
57
+ if game.variant_name == "Kyoto shogi":
58
+ moves = game.state["fairyMoves"].split()
59
+ else:
60
+ moves = "" if game.variant_name == "Standard" else game.state["moves"].split()
61
  sfen = board.sfen() if game.variant_name == "Standard" else game.initial_sfen
62
  self.engine.set_variant_options(game.variant_name.lower())
63
  return self.search(sfen, moves, movetime=movetime // 1000)
64
 
65
  def search_with_ponder(self, game, board, btime, wtime, binc, winc, byo, ponder=False):
66
+ if game.variant_name == "Kyoto shogi":
67
+ moves = game.state["fairyMoves"].split()
68
+ else:
69
+ moves = [m.usi() for m in list(board.move_stack)] if game.variant_name == "Standard" else game.state["moves"].split()
70
  sfen = game.initial_sfen
71
  cmds = self.go_commands
72
  movetime = cmds.get("movetime")
lishogi-bot.py CHANGED
@@ -308,7 +308,10 @@ def play_game(li, game_id, control_queue, user_profile, config, challenge_queue,
308
  elif u_type == "gameState":
309
  game.state = upd
310
  if is_game_over(game):
311
- engine.report_game_result(game, game.state["moves"].split(" "))
 
 
 
312
  tell_user_game_result(game)
313
  conversation.send_message("player", goodbye)
314
  break
@@ -318,7 +321,10 @@ def play_game(li, game_id, control_queue, user_profile, config, challenge_queue,
318
  if len(board.move_stack) < 2:
319
  conversation.send_message("player", hello)
320
  else:
321
- print_move_number(game.state["moves"])
 
 
 
322
  start_time = time.perf_counter_ns()
323
  fake_thinking(config, board, game)
324
  correspondence_disconnect_time = correspondence_cfg.get("disconnect_time", 300)
@@ -524,8 +530,12 @@ def setup_board(game):
524
  logger.debug(f"Ignoring illegal move {move} on board {board.sfen()}")
525
  else:
526
  board = shogi.Board()
527
- for move in game.state["moves"].split():
528
- board.push(shogi.Move.null())
 
 
 
 
529
 
530
  return board
531
 
 
308
  elif u_type == "gameState":
309
  game.state = upd
310
  if is_game_over(game):
311
+ if game.variant_name == "Kyoto shogi":
312
+ engine.report_game_result(game, game.state["fairyMoves"].split(" "))
313
+ else:
314
+ engine.report_game_result(game, game.state["moves"].split(" "))
315
  tell_user_game_result(game)
316
  conversation.send_message("player", goodbye)
317
  break
 
321
  if len(board.move_stack) < 2:
322
  conversation.send_message("player", hello)
323
  else:
324
+ if game.variant_name == "Kyoto shogi":
325
+ print_move_number(game.state["fairyMoves"])
326
+ else:
327
+ print_move_number(game.state["moves"])
328
  start_time = time.perf_counter_ns()
329
  fake_thinking(config, board, game)
330
  correspondence_disconnect_time = correspondence_cfg.get("disconnect_time", 300)
 
530
  logger.debug(f"Ignoring illegal move {move} on board {board.sfen()}")
531
  else:
532
  board = shogi.Board()
533
+ if game.variant_name == "Kyoto shogi":
534
+ for move in game.state["fairyMoves"].split():
535
+ board.push(shogi.Move.null())
536
+ else:
537
+ for move in game.state["moves"].split():
538
+ board.push(shogi.Move.null())
539
 
540
  return board
541
 
model.py CHANGED
@@ -78,7 +78,10 @@ class Game:
78
  self.variant_name = json.get("variant")["name"]
79
  self.sente = Player(json.get("sente"))
80
  self.gote = Player(json.get("gote"))
81
- self.initial_sfen = json.get("initialSfen")
 
 
 
82
  self.state = json.get("state")
83
  self.is_sente = bool(self.sente.name and self.sente.name.lower() == username.lower())
84
  self.my_color = "sente" if self.is_sente else "gote"
 
78
  self.variant_name = json.get("variant")["name"]
79
  self.sente = Player(json.get("sente"))
80
  self.gote = Player(json.get("gote"))
81
+ if self.variant_name == "Kyoto shogi":
82
+ self.initial_sfen = json.get("fairyInitialSfen")
83
+ else:
84
+ self.initial_sfen = json.get("initialSfen")
85
  self.state = json.get("state")
86
  self.is_sente = bool(self.sente.name and self.sente.name.lower() == username.lower())
87
  self.my_color = "sente" if self.is_sente else "gote"