当前位置: 首页 > news >正文

穷人的中国象棋打谱程序

fenScreenshot_20251007_145147

以上两张图都比盲棋简单多了。

 

<html><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0">
<style>
textarea { width:354; border:none; outline:none; font-size:14; text-align:center }
pre { display:none }
div { display:grid; min-height:85vh; place-items:end center }
button { margin-left:16; width:72; height:55; font:bold 18 sans-serif }
canvas { position:absolute; top:50%; left:50%; transform:translate(-50%, -60%) }
</style></head><body><center>
<textarea spellcheck=false readonly="readonly" id="_desc" onclick="copy()"></textarea><pre>
EXB@EO@[F?^]AQ@??I?[VFAIFW^E[UGWRF[EFQ\ECHFDN
</pre><div><p>
<button onclick="_auto=0;draw(++_i)">前 进</button><button onclick="_auto=0;draw(--_i)">后 退</button><button onclick="_auto=1">自 动</button></p></div>
<canvas width="354" height="398"></canvas></center></body>
<script>
function copy () {let e = _desce.select()document.execCommand('copy')navigator.clipboard.writeText(e.value)e.selectionStart = e.selectionEndalert(e.value)
}function tag (s) { return document.getElementsByTagName(s)[0] }tag('p').style.transform = 'translate(-16px, 0px)'let _ctx = tag('canvas').getContext('2d', {willReadFrequently:true, alpha:false})
_ctx.font = '22px serif'
let _img_brd = Array.from({length:10}, ()=>Array(9).fill(0)), _img_red, _img_hei
const S = 40, L = 0, T = 4
let _d = JSON.parse('{"r":"车", "n":"马", "b":"象", "a":"士", "k":"将", "c":"炮", "p":"卒", "B":"相", "A":"仕", "K":"帅", "P":"兵"}')
_d['R'] = _d['r']; _d['N'] = _d['n']; _d['C'] = _d['c']
let _fenary = [], _i = 0
let _auto = 0// 在线图片base64
BRD_JPG = RED_PNG = HEI_PNG = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWIAAAGOCAAAAAC
IsVZfAAACAUlEQVR42u3QMREAAAgEILV/5zeE5wYR6BS/RoFixShWrBjFilGsWDGKFStGsWIUK1aMYsWKUawYxYoVo1
ixYhQrRrFixShWrBjFilGsWDGKFStGsWIUK1aMYsWKUawYxYoVo1ixYhQrRrFixShWrBjFilGsWDGKFStGsWIUK1aMY
sWKUawYxYoVo1ixYhQrRrFixShWrBjFilGsWDGKFStGsWIUK1aMYsWKUawYxYoVo1ixYhQrRrFixShWjGLFilGsWDGK
FaNYsWIUK1aMYsUoVqwYxYoVo1gxihUrRrFixShWjGLFilGsWDGKFaNYsWIUK1aMYsUoVqwYxYoVo1gxihUrRrFixShW
jGLFilGsWDGKFaNYsWIUK1aMYsUoVqwYxYoVo1gxihUrRrFixShWjGLFilGsWDGKFaNYsWIUK1aMYsUoVqwYxYoVo1gx
ihUrRrFixQoUK0axYsUoVoxixYpRrFgxihWjWLFiFCtWjGLFKFasGMWKFaNYMYoVK0axYsUoVoxixYpRrFgxihWjWLFi
FCtWjGLFKFasGMWKFaNYMYoVK0axYsUoVoxixYpRrFgxihWjWLFiFCtWjGLFKFasGMWKFaNYMYoVK0axYsUoVoxixYpRr
FgxihWjWLFiFCtWjGLFKFasGMWKFaNYMYoVK0axYhQrVoxixYq5W0lrBBu7x/R5AAAAAElFTkSuQmCC`function get_img (src, fn) {let img = new Image()img.onload = () => { fn(img) }img.src = srcreturn img
}get_img(BRD_JPG, (img) => {_ctx.drawImage(img, 0, 0)for (let y = 0; y < 10; y++)for(let x = 0; x < 10; x++)_img_brd[y][x] = _ctx.getImageData(L+x*S, T+y*S, S, S)_img_red = get_img(RED_PNG, () => {_img_hei = get_img(HEI_PNG, () => {start()})})
})function draw () {if (_i < 1) _i = _fenary.lengthif (_i > _fenary.length) _i = 1document.title = ((_i&1) ? '红 ' : '黑 ') + _ilet b = fen2brd(_fenary[_i - 1])for (let y = 0; y < 10; y++)for (let x = 0; x < 9; x++) {let px = L + x * S, py = T + y * S_ctx.putImageData(_img_brd[y][x], px, py)let c = b[y][x]if (c === ' ') continue//_ctx.drawImage(c >= 'a' ? _img_hei : _img_red, px, py)_ctx.fillStyle = c >= 'a' ? 'black' : 'red'_ctx.fillText(_d[c], px + 5, py + 24)}
}function start () {let s = 'rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w'_fenary.push(s)let b = fen2brd(s)_moves = tag('pre')let f = _moves.innerHTML.split('\n')let n = f.lengthif (!f[n-1].length) f.pop(), --nlet j = Math.round(Math.random() * (n - 1))s = f[j]for (i = 0; i < s.length; i += 3) {function d(i) { return s.charCodeAt(i) - '?'.charCodeAt(0) }let m = 1024*d(i) + 32*d(i+1) + d(i+2)// 第一次~把浮点数转换为32位整数(截断小数部分)let fx = ~~(m / 1000); m %= 1000let fy = ~~(m / 100); m %= 100let tx = ~~(m / 10), ty = m % 10b[ty][tx] = b[fy][fx]; b[fy][fx] = ' '_fenary.push(brd2fen(b) + ((_fenary.length & 1) ? ' b' : ' w'))}_desc.value = (j+1) + '# ' + (_fenary.length - 1)draw()setTimeout(auto, 1500)
}function auto () {setTimeout(auto, 1500)if (_auto) draw(++_i)
}function fen2brd (s) {try {let f = s.split('/')let b = Array.from({length:10}, ()=>Array(9).fill(' '))for (let y = 0; y < 10; y++) {let x = 0for (let i = 0; i < f[y].length; i++) {let c = f[y][i]if (c >= '1' && c <= '9') x += c - '0'else b[y][x++] = c}}return b} catch (e) { return null }
}function brd2fen (b) {let s = ''for (let y = 0; y < 10; y++) {let n = 0for (let x = 0; x < 9; x++) {let c = b[y][x]if (c === ' ') ++nelse {if (n) s += ns += c; n = 0}}if (n) s += nif (y != 9) s += '/'}return s
}document.addEventListener('touchstart', function(e) {if (e.touches.length > 1) e.preventDefault()
})
</script></html>

 

http://www.hskmm.com/?act=detail&tid=26113

相关文章:

  • 文件系统的层次结构
  • oracle 19c学习笔记2
  • 文件保护
  • 一些数数杂题
  • AI元人文:规则与人文的统一之路
  • 10.7
  • qmd 模拟赛的一道题
  • 四元数:从理论基础到实际应用的深度探索 - 教程
  • Day12
  • HoneyWell(霍尼韦尔)1450g扫码枪说明书
  • 课上动手东脑问题
  • 箭头函数的疑问
  • 文件共享
  • 【万字长文】让面试没有难撕的JS基础题
  • Java总览
  • PCoT: Persuasion-Augmented Chain of Thought for Detecting Fake News and Social Media Disinformation
  • 博客地址
  • 宏定义中,为什么使用:do{}while(0)这种模式是最安全的
  • 20251007J赛合订本
  • XML 元素:基础、应用与优化 - 教程
  • Educational Codeforces Round 183 (Rated for Div. 2) A~D
  • Cisco vManage漏洞分析:未授权RCE与权限提升完整攻击链
  • QBXT2025S刷题 Day6题
  • 硅芯片创新如何成为云计算成功的关键
  • 东萍象棋 DhtmlXQ UBB 转 中国象棋云库查询 FEN
  • 斑马ZT210碳带及纸张安装教程
  • DHCP及DNS
  • Gitlab Runner 学习
  • AI元人文:论价值原语博弈与人文知识库共建如何重塑智能社会的决策基石
  • 算法第一张作业