
可以键盘操作。比如鼠标移到某个位置,按r出来个黑车。空格删掉棋子。还可以自己吃自己,空白吃自己等,我感觉摆残局最方便。
程序很乱。鄙人之前所发贴的拼凑版。再贴部分代码:
httpd.py

# !/usr/bin/python3 from ee import * from http.server import * from threading import * from urllib.parse import unquote from random import randintclass HTTPReqHandler (SimpleHTTPRequestHandler):def __init__ (m, r, c, s): super().__init__(r, c, s, directory='www')def do_GET (m):def _200 ():m.send_response(200)m.send_header('Content-type', 'text/plain')m.end_headers()path = m.requestline.split(' ')[1]if path.startswith('/ucci?'):ee.send(unquote(path[6:]))_200()m.wfile.write(ee.recv().encode())elif path.startswith('/rpu'):n = randint(0, 6812)f = open('pu.txt', 'rb')for i in range(n): f.readline()_200()m.wfile.write(f.readline())f.close()else: super().do_GET()def do_HEAD (m): super().do_HEAD()def do_POST (m): super().do_POST()def end_headers (m): # callbackm.send_header('Cache-Control', 'no-store')super().end_headers()def httpd_thread ():port = 8000svr_addr = ('', port)httpd = ThreadingHTTPServer(svr_addr, HTTPReqHandler)print('Listening at', port)httpd.serve_forever()Thread(daemon=1, target=httpd_thread).start()try:while True: input() except BaseException: pass
JS

function ajax(req, param, cb){let ax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')ax.onreadystatechange = function(){if(ax.readyState != 4 || ax.status != 200) returncb(ax.responseText)}ax.open('GET', req + encodeURIComponent(param), true); ax.send() }function move (who, mv) {ucciout.innerText = 'busy'ajax('/ucci?', 'position fen ' + _brd2fen() + ' ' + who + '\ngo 999', (s)=>{ucciout.innerText = slet i = s.indexOf('\nbestmove')if(i === -1) return// 'b' - 'a'=NaN; '9' - '0'=9let a = 'a'.charCodeAt(0)fx = s.charCodeAt(i+10) - atx = s.charCodeAt(i+12) - afy = '9' - s.charAt(i+11)ty = '9' - s.charAt(i+13)//console.log(fx, fy, tx, ty)if (mv) { // 走棋而不是仅分析 recMove(fx, fy, tx, ty)_brd[ty][tx] = _brd[fy][fx]; _brd[fy][fx] = ' '; draw_all()}}) }function rpu () {ajax('/rpu', '', (s)=>{pad.value = sloadUBB()}) }let dic = JSON.parse(`{"r":"车", "n":"马", "c":"炮", "b":"象", "B":"相", "a":"士", "A":"仕", "k":"将", "K":"帅", "p":"卒", "P":"兵"}`) dic['R'] = dic['r']; dic['N'] = dic['n']; dic['C'] = dic['c']function recMove(fx, fy, tx, ty) {let c = _brd[fy][fx]if (c === ' ') returnlet isRed = c < 'a'let d = fy - tyif (d < 0) d = -ds = dic[c]if (isRed) {let x = "九八七六五四三二一"s += x[fx]if (fy === ty)s += "平" + x[tx]else {s += (fy > ty) ? "进" : "退"if ("RCPK".includes(c))s += "零一二三四五六七八九"[d]elses += x[tx]}}else {let x = "123456789"s += x[fx]if (fy === ty)s += "平" + x[tx]else {s += (fy < ty) ? "进" : "退"if ("rcpk".includes(c))s += "0123456789"[d]elses += x[tx]}}if (!moves.value.length) mc = 0moves.value += s + ' ' }