feat: tetris test

This commit is contained in:
2025-10-03 21:41:05 +02:00
parent 3ff5df5a6f
commit 3077f8685b
5 changed files with 1578 additions and 0 deletions

855
test/pixelstream/tetris/package-lock.json generated Normal file
View File

@@ -0,0 +1,855 @@
{
"name": "tetris",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "tetris",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"express": "^4.21.2",
"ws": "^8.18.3"
}
},
"node_modules/accepts": {
"version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
"integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
"license": "MIT",
"dependencies": {
"mime-types": "~2.1.34",
"negotiator": "0.6.3"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
"license": "MIT"
},
"node_modules/body-parser": {
"version": "1.20.3",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz",
"integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==",
"license": "MIT",
"dependencies": {
"bytes": "3.1.2",
"content-type": "~1.0.5",
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"on-finished": "2.4.1",
"qs": "6.13.0",
"raw-body": "2.5.2",
"type-is": "~1.6.18",
"unpipe": "1.0.0"
},
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
"integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/call-bound": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
"integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"get-intrinsic": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/content-disposition": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
"integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
"license": "MIT",
"dependencies": {
"safe-buffer": "5.2.1"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/content-type": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
"integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==",
"license": "MIT"
},
"node_modules/debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"license": "MIT",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
"integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/destroy": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
"integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
"license": "MIT",
"engines": {
"node": ">= 0.8",
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dunder-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
"integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.1",
"es-errors": "^1.3.0",
"gopd": "^1.2.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
"license": "MIT"
},
"node_modules/encodeurl": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
"integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/es-define-property": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
"integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-errors": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/es-object-atoms": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
"integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
"license": "MIT"
},
"node_modules/etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/express": {
"version": "4.21.2",
"resolved": "https://registry.npmjs.org/express/-/express-4.21.2.tgz",
"integrity": "sha512-28HqgMZAmih1Czt9ny7qr6ek2qddF4FclbMzwhCREB6OFfH+rXAnuNCwo1/wFvrtbgsQDb4kSbX9de9lFbrXnA==",
"license": "MIT",
"dependencies": {
"accepts": "~1.3.8",
"array-flatten": "1.1.1",
"body-parser": "1.20.3",
"content-disposition": "0.5.4",
"content-type": "~1.0.4",
"cookie": "0.7.1",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "2.0.0",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "1.3.1",
"fresh": "0.5.2",
"http-errors": "2.0.0",
"merge-descriptors": "1.0.3",
"methods": "~1.1.2",
"on-finished": "2.4.1",
"parseurl": "~1.3.3",
"path-to-regexp": "0.1.12",
"proxy-addr": "~2.0.7",
"qs": "6.13.0",
"range-parser": "~1.2.1",
"safe-buffer": "5.2.1",
"send": "0.19.0",
"serve-static": "1.16.2",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
},
"engines": {
"node": ">= 0.10.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/finalhandler": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.1.tgz",
"integrity": "sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"on-finished": "2.4.1",
"parseurl": "~1.3.3",
"statuses": "2.0.1",
"unpipe": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
"integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/function-bind": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-intrinsic": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
"integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
"license": "MIT",
"dependencies": {
"call-bind-apply-helpers": "^1.0.2",
"es-define-property": "^1.0.1",
"es-errors": "^1.3.0",
"es-object-atoms": "^1.1.1",
"function-bind": "^1.1.2",
"get-proto": "^1.0.1",
"gopd": "^1.2.0",
"has-symbols": "^1.1.0",
"hasown": "^2.0.2",
"math-intrinsics": "^1.1.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/get-proto": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
"integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
"license": "MIT",
"dependencies": {
"dunder-proto": "^1.0.1",
"es-object-atoms": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/gopd": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
"integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/has-symbols": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
"integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/hasown": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
"license": "MIT",
"dependencies": {
"function-bind": "^1.1.2"
},
"engines": {
"node": ">= 0.4"
}
},
"node_modules/http-errors": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
"integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
"license": "MIT",
"dependencies": {
"depd": "2.0.0",
"inherits": "2.0.4",
"setprototypeof": "1.2.0",
"statuses": "2.0.1",
"toidentifier": "1.0.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"license": "MIT",
"dependencies": {
"safer-buffer": ">= 2.1.2 < 3"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ipaddr.js": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
"integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/math-intrinsics": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
}
},
"node_modules/media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/merge-descriptors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
"integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"license": "MIT",
"bin": {
"mime": "cli.js"
},
"engines": {
"node": ">=4"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
"license": "MIT"
},
"node_modules/negotiator": {
"version": "0.6.3",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
"integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/object-inspect": {
"version": "1.13.4",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
"integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
"license": "MIT",
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/on-finished": {
"version": "2.4.1",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
"integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
"license": "MIT",
"dependencies": {
"ee-first": "1.1.1"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/path-to-regexp": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
"integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
"license": "MIT"
},
"node_modules/proxy-addr": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
"integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
"license": "MIT",
"dependencies": {
"forwarded": "0.2.0",
"ipaddr.js": "1.9.1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/qs": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz",
"integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==",
"license": "BSD-3-Clause",
"dependencies": {
"side-channel": "^1.0.6"
},
"engines": {
"node": ">=0.6"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/raw-body": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz",
"integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==",
"license": "MIT",
"dependencies": {
"bytes": "3.1.2",
"http-errors": "2.0.0",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
},
"node_modules/send": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz",
"integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==",
"license": "MIT",
"dependencies": {
"debug": "2.6.9",
"depd": "2.0.0",
"destroy": "1.2.0",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "0.5.2",
"http-errors": "2.0.0",
"mime": "1.6.0",
"ms": "2.1.3",
"on-finished": "2.4.1",
"range-parser": "~1.2.1",
"statuses": "2.0.1"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/send/node_modules/encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/send/node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/serve-static": {
"version": "1.16.2",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz",
"integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==",
"license": "MIT",
"dependencies": {
"encodeurl": "~2.0.0",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"send": "0.19.0"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/setprototypeof": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
"license": "ISC"
},
"node_modules/side-channel": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
"integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.3",
"side-channel-list": "^1.0.0",
"side-channel-map": "^1.0.1",
"side-channel-weakmap": "^1.0.2"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-list": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
"integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
"license": "MIT",
"dependencies": {
"es-errors": "^1.3.0",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-map": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
"integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/side-channel-weakmap": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
"integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
"license": "MIT",
"dependencies": {
"call-bound": "^1.0.2",
"es-errors": "^1.3.0",
"get-intrinsic": "^1.2.5",
"object-inspect": "^1.13.3",
"side-channel-map": "^1.0.1"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/statuses": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
"integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/toidentifier": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
"integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
"license": "MIT",
"engines": {
"node": ">=0.6"
}
},
"node_modules/type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"license": "MIT",
"dependencies": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
"license": "MIT",
"engines": {
"node": ">= 0.4.0"
}
},
"node_modules/vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
"license": "MIT",
"engines": {
"node": ">= 0.8"
}
},
"node_modules/ws": {
"version": "8.18.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

View File

@@ -0,0 +1,18 @@
{
"name": "tetris",
"version": "1.0.0",
"description": "16x16 Tetris pixelstream demo",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.21.2",
"ws": "^8.18.3"
}
}

View File

@@ -0,0 +1,563 @@
(() => {
const GRID_WIDTH = 16;
const GRID_HEIGHT = 16;
const FRAME_INTERVAL_MS = 50;
const AUTO_DROP_MS = 600;
const SOFT_DROP_MS = 60;
const canvas = document.getElementById('board');
const ctx = canvas.getContext('2d', { alpha: false });
const scoreEl = document.getElementById('score');
const linesEl = document.getElementById('lines');
const wsDot = document.getElementById('ws-dot');
const wsLabel = document.getElementById('ws-label');
const MATRIX_WIDTH = canvas.width;
const MATRIX_HEIGHT = canvas.height;
const COLOR_ORDER = 'RGB';
const BRIGHTNESS = 1.0;
const SERPENTINE = true;
const FLIP_X = true;
const FLIP_Y = false;
const TETROMINOES = [
{
name: 'I',
color: '#2dd9ff',
rotations: [
[ [0, 1], [1, 1], [2, 1], [3, 1] ],
[ [2, 0], [2, 1], [2, 2], [2, 3] ],
[ [0, 2], [1, 2], [2, 2], [3, 2] ],
[ [1, 0], [1, 1], [1, 2], [1, 3] ],
],
spawnOffset: { x: 6, y: -1 },
},
{
name: 'J',
color: '#3b7ddd',
rotations: [
[ [0, 0], [0, 1], [1, 1], [2, 1] ],
[ [1, 0], [2, 0], [1, 1], [1, 2] ],
[ [0, 1], [1, 1], [2, 1], [2, 2] ],
[ [1, 0], [1, 1], [0, 2], [1, 2] ],
],
spawnOffset: { x: 6, y: -1 },
},
{
name: 'L',
color: '#f7b733',
rotations: [
[ [2, 0], [0, 1], [1, 1], [2, 1] ],
[ [1, 0], [1, 1], [1, 2], [2, 2] ],
[ [0, 1], [1, 1], [2, 1], [0, 2] ],
[ [0, 0], [1, 0], [1, 1], [1, 2] ],
],
spawnOffset: { x: 6, y: -1 },
},
{
name: 'O',
color: '#ffe66d',
rotations: [
[ [1, 0], [2, 0], [1, 1], [2, 1] ],
[ [1, 0], [2, 0], [1, 1], [2, 1] ],
[ [1, 0], [2, 0], [1, 1], [2, 1] ],
[ [1, 0], [2, 0], [1, 1], [2, 1] ],
],
spawnOffset: { x: 6, y: -1 },
},
{
name: 'S',
color: '#30db6d',
rotations: [
[ [1, 0], [2, 0], [0, 1], [1, 1] ],
[ [1, 0], [1, 1], [2, 1], [2, 2] ],
[ [1, 1], [2, 1], [0, 2], [1, 2] ],
[ [0, 0], [0, 1], [1, 1], [1, 2] ],
],
spawnOffset: { x: 6, y: -1 },
},
{
name: 'T',
color: '#c86bff',
rotations: [
[ [1, 0], [0, 1], [1, 1], [2, 1] ],
[ [1, 0], [1, 1], [2, 1], [1, 2] ],
[ [0, 1], [1, 1], [2, 1], [1, 2] ],
[ [1, 0], [0, 1], [1, 1], [1, 2] ],
],
spawnOffset: { x: 6, y: -1 },
},
{
name: 'Z',
color: '#ff5f5f',
rotations: [
[ [0, 0], [1, 0], [1, 1], [2, 1] ],
[ [2, 0], [1, 1], [2, 1], [1, 2] ],
[ [0, 1], [1, 1], [1, 2], [2, 2] ],
[ [1, 0], [0, 1], [1, 1], [0, 2] ],
],
spawnOffset: { x: 6, y: -1 },
},
];
const LINE_SCORE_TABLE = {
1: 100,
2: 250,
3: 400,
4: 800,
};
let ws;
let wsReady = false;
let sendingFrame = false;
let board;
let currentPiece;
let holdQueue;
let score;
let clearedLines;
let isGameOver;
let dropTimer;
let softDropActive;
function connectWebSocket() {
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const url = `${protocol}://${location.host}/ws`;
ws = new WebSocket(url);
ws.binaryType = 'arraybuffer';
setWsStatus('connecting');
ws.addEventListener('open', () => {
wsReady = true;
setWsStatus('open');
});
ws.addEventListener('close', () => {
wsReady = false;
setWsStatus('closed');
});
ws.addEventListener('error', () => {
wsReady = false;
setWsStatus('error');
});
}
function setWsStatus(state) {
if (state === 'open') {
wsDot.classList.add('ok');
wsLabel.textContent = 'WS: connected';
} else if (state === 'connecting') {
wsDot.classList.remove('ok');
wsLabel.textContent = 'WS: connecting…';
} else if (state === 'closed') {
wsDot.classList.remove('ok');
wsLabel.textContent = 'WS: disconnected';
setTimeout(connectWebSocket, 1000);
} else {
wsDot.classList.remove('ok');
wsLabel.textContent = 'WS: error';
}
}
function clampToByte(value) {
if (value < 0) return 0;
if (value > 255) return 255;
return value | 0;
}
function applyBrightness(value) {
return clampToByte(Math.round(value * BRIGHTNESS));
}
function mapXYToLinearIndex(x, y, width, height) {
const mappedX = FLIP_X ? (width - 1 - x) : x;
const mappedY = FLIP_Y ? (height - 1 - y) : y;
const isOddRow = (mappedY % 2) === 1;
const columnInRow = (SERPENTINE && isOddRow) ? (width - 1 - mappedX) : mappedX;
return (mappedY * width) + columnInRow;
}
function writePixelWithColorOrder(target, baseIndex, r, g, b) {
switch (COLOR_ORDER) {
case 'RGB':
target[baseIndex + 0] = r;
target[baseIndex + 1] = g;
target[baseIndex + 2] = b;
break;
case 'GRB':
target[baseIndex + 0] = g;
target[baseIndex + 1] = r;
target[baseIndex + 2] = b;
break;
case 'BRG':
target[baseIndex + 0] = b;
target[baseIndex + 1] = r;
target[baseIndex + 2] = g;
break;
case 'BGR':
target[baseIndex + 0] = b;
target[baseIndex + 1] = g;
target[baseIndex + 2] = r;
break;
case 'RBG':
target[baseIndex + 0] = r;
target[baseIndex + 1] = b;
target[baseIndex + 2] = g;
break;
case 'GBR':
target[baseIndex + 0] = g;
target[baseIndex + 1] = b;
target[baseIndex + 2] = r;
break;
default:
target[baseIndex + 0] = g;
target[baseIndex + 1] = r;
target[baseIndex + 2] = b;
break;
}
}
function encodeCanvasToNeoPixelFrame() {
const width = MATRIX_WIDTH;
const height = MATRIX_HEIGHT;
const out = new Uint8Array(width * height * 3);
const src = ctx.getImageData(0, 0, width, height).data;
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const srcIndex = ((y * width) + x) * 4;
const r = applyBrightness(src[srcIndex + 0]);
const g = applyBrightness(src[srcIndex + 1]);
const b = applyBrightness(src[srcIndex + 2]);
const pixelIndex = mapXYToLinearIndex(x, y, width, height);
const base = pixelIndex * 3;
writePixelWithColorOrder(out, base, r, g, b);
}
}
return out;
}
function createEmptyBoard() {
const rows = [];
for (let y = 0; y < GRID_HEIGHT; y++) {
rows.push(new Array(GRID_WIDTH).fill(null));
}
return rows;
}
function makePiece(template) {
return {
name: template.name,
color: template.color,
rotations: template.rotations,
rotationIndex: 0,
x: template.spawnOffset.x,
y: template.spawnOffset.y,
};
}
function getCurrentShape(piece) {
return piece.rotations[piece.rotationIndex];
}
function forEachBlock(piece, callback) {
const shape = getCurrentShape(piece);
for (let i = 0; i < shape.length; i++) {
const [dx, dy] = shape[i];
callback(piece.x + dx, piece.y + dy);
}
}
function isInside(x, y) {
return x >= 0 && x < GRID_WIDTH && y < GRID_HEIGHT;
}
function isCellFree(x, y) {
if (y < 0) {
return true;
}
if (!isInside(x, y)) {
return false;
}
return board[y][x] === null;
}
function canPlace(piece, offsetX, offsetY, rotationDelta) {
const nextRotation = (piece.rotationIndex + rotationDelta + piece.rotations.length) % piece.rotations.length;
const shape = piece.rotations[nextRotation];
for (let i = 0; i < shape.length; i++) {
const [dx, dy] = shape[i];
const x = piece.x + offsetX + dx;
const y = piece.y + offsetY + dy;
if (!isCellFree(x, y)) {
return false;
}
}
return true;
}
function commitPieceToBoard(piece) {
const shape = getCurrentShape(piece);
for (let i = 0; i < shape.length; i++) {
const [dx, dy] = shape[i];
const x = piece.x + dx;
const y = piece.y + dy;
if (y >= 0 && y < GRID_HEIGHT && x >= 0 && x < GRID_WIDTH) {
board[y][x] = piece.color;
}
}
}
function clearLines() {
let linesCleared = 0;
const newRows = [];
for (let y = 0; y < GRID_HEIGHT; y++) {
if (board[y].every(cell => cell !== null)) {
linesCleared += 1;
} else {
newRows.push(board[y]);
}
}
while (newRows.length < GRID_HEIGHT) {
newRows.unshift(new Array(GRID_WIDTH).fill(null));
}
board = newRows;
if (linesCleared > 0) {
clearedLines += linesCleared;
const awarded = LINE_SCORE_TABLE[linesCleared] || (linesCleared * 200);
score += awarded;
}
}
function spawnNextPiece() {
if (holdQueue.length === 0) {
refillBag();
}
currentPiece = makePiece(holdQueue.shift());
if (!canPlace(currentPiece, 0, 0, 0)) {
isGameOver = true;
}
}
function refillBag() {
const bag = [...TETROMINOES];
for (let i = bag.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[bag[i], bag[j]] = [bag[j], bag[i]];
}
holdQueue.push(...bag);
}
function tryMove(offsetX, offsetY) {
if (!currentPiece || !canPlace(currentPiece, offsetX, offsetY, 0)) {
return false;
}
currentPiece.x += offsetX;
currentPiece.y += offsetY;
return true;
}
function tryRotate(clockwise = true) {
if (!currentPiece) {
return;
}
const delta = clockwise ? 1 : -1;
const originalRotation = currentPiece.rotationIndex;
const targetRotation = (originalRotation + delta + currentPiece.rotations.length) % currentPiece.rotations.length;
const kicks = [
{ x: 0, y: 0 },
{ x: -1, y: 0 },
{ x: 1, y: 0 },
{ x: -2, y: 0 },
{ x: 2, y: 0 },
{ x: 0, y: -1 },
];
for (const kick of kicks) {
if (canPlace(currentPiece, kick.x, kick.y, delta)) {
currentPiece.rotationIndex = targetRotation;
currentPiece.x += kick.x;
currentPiece.y += kick.y;
return;
}
}
}
function hardDrop() {
if (!currentPiece) {
return;
}
while (tryMove(0, 1)) {
score += 2;
}
lockPiece();
}
function lockPiece() {
commitPieceToBoard(currentPiece);
clearLines();
scoreEl.textContent = String(score);
linesEl.textContent = String(clearedLines);
spawnNextPiece();
dropTimer = 0;
}
function updateGame(deltaMs) {
if (isGameOver) {
return;
}
dropTimer += deltaMs;
const targetDrop = softDropActive ? SOFT_DROP_MS : AUTO_DROP_MS;
if (dropTimer >= targetDrop) {
dropTimer = 0;
if (!tryMove(0, 1)) {
lockPiece();
}
}
}
function drawBoard() {
ctx.fillStyle = '#000000';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (let y = 0; y < GRID_HEIGHT; y++) {
for (let x = 0; x < GRID_WIDTH; x++) {
const cell = board[y][x];
if (cell) {
ctx.fillStyle = cell;
ctx.fillRect(x, y, 1, 1);
}
}
}
if (currentPiece) {
ctx.fillStyle = currentPiece.color;
forEachBlock(currentPiece, (x, y) => {
if (y >= 0 && y < GRID_HEIGHT && x >= 0 && x < GRID_WIDTH) {
ctx.fillRect(x, y, 1, 1);
}
});
}
if (isGameOver) {
ctx.fillStyle = '#ff3b30';
for (let x = 3; x < GRID_WIDTH - 3; x++) {
ctx.fillRect(x, 6, 1, 1);
ctx.fillRect(x, 9, 1, 1);
}
for (let y = 6; y <= 9; y++) {
ctx.fillRect(3, y, 1, 1);
ctx.fillRect(GRID_WIDTH - 4, y, 1, 1);
}
}
}
function toHex(value) {
const bounded = Math.max(0, Math.min(255, value));
const hex = bounded.toString(16);
return hex.length === 1 ? `0${hex}` : hex;
}
function sendFrame() {
if (!wsReady || !ws || ws.readyState !== WebSocket.OPEN) {
return;
}
if (sendingFrame) {
return;
}
sendingFrame = true;
try {
const frame = encodeCanvasToNeoPixelFrame();
ws.send(frame.buffer);
} catch (_) {
// ignore
} finally {
sendingFrame = false;
}
}
let previousTimestamp = performance.now();
function gameLoop() {
const now = performance.now();
const delta = now - previousTimestamp;
previousTimestamp = now;
updateGame(delta);
drawBoard();
sendFrame();
setTimeout(gameLoop, FRAME_INTERVAL_MS);
}
function resetGame() {
board = createEmptyBoard();
holdQueue = [];
score = 0;
clearedLines = 0;
isGameOver = false;
dropTimer = 0;
softDropActive = false;
scoreEl.textContent = '0';
linesEl.textContent = '0';
refillBag();
spawnNextPiece();
}
window.addEventListener('keydown', (event) => {
if (isGameOver && event.key.toLowerCase() === 'r') {
resetGame();
return;
}
switch (event.key) {
case 'ArrowLeft':
event.preventDefault();
tryMove(-1, 0);
break;
case 'ArrowRight':
event.preventDefault();
tryMove(1, 0);
break;
case 'ArrowDown':
event.preventDefault();
softDropActive = true;
break;
case 'ArrowUp':
event.preventDefault();
tryRotate(true);
break;
case ' ': // Space hard drop
case 'Enter':
event.preventDefault();
hardDrop();
break;
case 'r':
case 'R':
event.preventDefault();
resetGame();
break;
default:
break;
}
});
window.addEventListener('keyup', (event) => {
if (event.key === 'ArrowDown') {
softDropActive = false;
}
});
resetGame();
connectWebSocket();
gameLoop();
})();

View File

@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>16×16 Tetris</title>
<style>
:root {
color-scheme: dark;
}
body {
font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
background: #0b0b0b;
color: #e8e8e8;
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
margin: 0;
padding: 24px 12px;
}
h2 { margin: 0 0 4px 0; font-weight: 600; }
#board {
width: 640px;
height: 640px;
image-rendering: pixelated;
border: 1px solid #333;
background: #000;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.hud {
display: flex;
gap: 20px;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.status {
display: inline-flex;
gap: 8px;
align-items: center;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: #a33; }
.dot.ok { background: #3a3; }
.pill { padding: 2px 8px; border: 1px solid #333; border-radius: 999px; font-size: 12px; }
.hint { color: #aaa; font-size: 12px; }
</style>
</head>
<body>
<h2>16×16 Tetris</h2>
<div class="hud">
<div>Score: <span id="score">0</span></div>
<div>Lines: <span id="lines">0</span></div>
<div class="status"><span class="dot" id="ws-dot"></span><span class="pill" id="ws-label">WS: connecting…</span></div>
</div>
<canvas id="board" width="16" height="16"></canvas>
<div class="hint">Arrow keys to move, Up to rotate, Space or Enter to hard drop, R to restart.</div>
<script src="app.js"></script>
</body>
</html>

View File

@@ -0,0 +1,81 @@
const path = require('path');
const http = require('http');
const express = require('express');
const dgram = require('dgram');
const { WebSocketServer } = require('ws');
const HTTP_PORT = process.env.PORT || 3000;
const UDP_BROADCAST_PORT = Number(process.env.UDP_PORT) || 4210;
const UDP_BROADCAST_ADDR = process.env.UDP_ADDR || '10.0.1.144';
const MATRIX_WIDTH = Number(process.env.MATRIX_WIDTH) || 16;
const MATRIX_HEIGHT = Number(process.env.MATRIX_HEIGHT) || 16;
const BYTES_PER_PIXEL = 3;
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
const server = http.createServer(app);
const wss = new WebSocketServer({ server, path: '/ws' });
const udpSocket = dgram.createSocket('udp4');
udpSocket.on('error', (err) => {
console.error('[UDP] error:', err);
});
udpSocket.bind(() => {
try {
udpSocket.setBroadcast(true);
console.log(`[UDP] Ready to broadcast on ${UDP_BROADCAST_ADDR}:${UDP_BROADCAST_PORT}`);
} catch (e) {
console.error('[UDP] setBroadcast failed:', e);
}
});
wss.on('connection', (ws, req) => {
const clientAddress = req?.socket?.remoteAddress || 'unknown';
console.log(`[WS] Client connected: ${clientAddress}`);
ws.on('message', (data) => {
const bufferToSend = Buffer.isBuffer(data)
? data
: (data instanceof ArrayBuffer ? Buffer.from(data) : Buffer.from(String(data)));
const expectedSize = MATRIX_WIDTH * MATRIX_HEIGHT * BYTES_PER_PIXEL;
if (bufferToSend.length !== expectedSize) {
console.warn(`[WS] Unexpected frame size: ${bufferToSend.length} bytes (expected ${expectedSize}).`);
}
const hexPayload = bufferToSend.toString('hex');
const udpPayload = Buffer.from(`RAW:${hexPayload}`, 'ascii');
udpSocket.send(
udpPayload,
UDP_BROADCAST_PORT,
UDP_BROADCAST_ADDR,
(err) => {
if (err) {
console.error('[UDP] send error:', err.message);
}
}
);
});
ws.on('close', () => {
console.log('[WS] Client disconnected');
});
ws.on('error', (err) => {
console.error('[WS] error:', err.message);
});
});
server.listen(HTTP_PORT, () => {
console.log(`Server listening on http://localhost:${HTTP_PORT}`);
});
process.on('SIGINT', () => {
console.log('Shutting down...');
try { udpSocket.close(); } catch {}
try { server.close(() => process.exit(0)); } catch {}
});