Serve practice mode from the main server, add mode switch, fix touch
Practice mode is now at /practice on server.py instead of a separate server, with a button in the bottom-right corner of each page to the other mode. Touch: no double-tap zoom, no sticky hover after a tap, no long-press selection on the board, and a pressed look on tapped squares. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c52f30dc59
commit
ce6b71eb35
7 files changed
+51
-42
No files matched your search
+2
-27
@@ -1,26 +1,18 @@
|
||||
"""Moonchess practice server: play against the computer.
|
||||
"""Moonchess practice mode: play against the computer. server.py serves it at /practice.
|
||||
|
||||
Stateless: the page sends the current position with every request and gets the new
|
||||
position back, so there's no session to lose. The page decides whose turn belongs to
|
||||
the computer; this server only applies moves and picks them.
|
||||
the computer; this module only applies moves and picks them.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
from aiohttp import web
|
||||
|
||||
from game import Game
|
||||
from server import STATIC_DIR, no_cache
|
||||
from solver import Solver
|
||||
|
||||
solver = Solver() # solves every position up front; takes about a second
|
||||
|
||||
|
||||
async def index(request):
|
||||
return web.FileResponse(STATIC_DIR / "practice.html")
|
||||
|
||||
|
||||
async def play(request):
|
||||
"""Body: {history, turn, cell} to play `cell`, or {history, turn, accuracy} for a
|
||||
computer move, where accuracy (0-1) is the chance it plays a perfect move. A computer
|
||||
@@ -41,20 +33,3 @@ async def play(request):
|
||||
if error:
|
||||
return web.json_response({"error": error}, status=400)
|
||||
return web.json_response({**game.to_dict(), "computerMove": computer_move})
|
||||
|
||||
|
||||
def make_app():
|
||||
app = web.Application(middlewares=[no_cache])
|
||||
app.router.add_get("/", index)
|
||||
app.router.add_post("/api/play", play)
|
||||
app.router.add_static("/static", STATIC_DIR)
|
||||
return app
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Moonchess practice server")
|
||||
parser.add_argument("--host", default="127.0.0.1")
|
||||
parser.add_argument("--port", type=int, default=8081)
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
|
||||
web.run_app(make_app(), host=args.host, port=args.port)
|
||||
Reference in new issue
Block a user