QoL changes (non vibed)
This commit is contained in:
parent
3138dfc99f
commit
33efd24b26
2 changed files with 8 additions and 9 deletions
|
|
@ -31,10 +31,11 @@ from quarto.shared.game import (
|
|||
|
||||
|
||||
class ClientApp:
|
||||
def __init__(self, host: str, port: int, name: str) -> None:
|
||||
def __init__(self, host: str, port: int, name: str, timeout: float = 5.0) -> None:
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.name = name
|
||||
self.timeout = timeout
|
||||
self.conn = ClientConnection(host, port)
|
||||
self.ai = QuartoAI()
|
||||
self.state: Optional[GameState] = None
|
||||
|
|
@ -89,7 +90,7 @@ class ClientApp:
|
|||
# If we are player1, we must immediately choose initial piece
|
||||
if self.our_player == Player.PLAYER1:
|
||||
assert self.state is not None
|
||||
init_move = self.ai.choose_initial_piece(self.state, 5.0)
|
||||
init_move = self.ai.choose_initial_piece(self.state, self.timeout)
|
||||
# Do NOT apply locally; wait for server broadcast MOVE~M
|
||||
self.conn.send_line(format_move_initial(init_move.chosen_piece))
|
||||
|
||||
|
|
@ -154,7 +155,7 @@ class ClientApp:
|
|||
return
|
||||
|
||||
# Use AI to choose move within 5 seconds
|
||||
move = self.ai.choose_normal_move(state, 5.0)
|
||||
move = self.ai.choose_normal_move(state, self.timeout)
|
||||
|
||||
# Validate locally via simulation before sending
|
||||
tmp_state = self._clone_state(state)
|
||||
|
|
@ -205,9 +206,11 @@ def main() -> None:
|
|||
parser.add_argument("--port", type=int, default=12345)
|
||||
parser.add_argument("--name", default="QuartoBot",
|
||||
help="Client name/description to send in HELLO")
|
||||
parser.add_argument("--timeout", default=5.0, type=float,
|
||||
help="The maximum think time for the AI")
|
||||
args = parser.parse_args()
|
||||
|
||||
client = ClientApp(host=args.host, port=args.port, name=args.name)
|
||||
client = ClientApp(host=args.host, port=args.port, name=args.name, timeout=args.timeout)
|
||||
client.run()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ class ClientConnection:
|
|||
|
||||
def connect(self) -> None:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(self.timeout)
|
||||
s.connect((self.host, self.port))
|
||||
self.sock = s
|
||||
|
||||
|
|
@ -31,10 +30,7 @@ class ClientConnection:
|
|||
if b"\n" in self._buffer:
|
||||
line, self._buffer = self._buffer.split(b"\n", 1)
|
||||
return line.decode("utf-8", errors="replace").rstrip("\r")
|
||||
try:
|
||||
chunk = self.sock.recv(4096)
|
||||
except socket.timeout:
|
||||
return None
|
||||
chunk = self.sock.recv(4096)
|
||||
if not chunk:
|
||||
return None
|
||||
self._buffer += chunk
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue