diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..1c2fda5
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..b6b8b4e
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/neos-majiang-v3.iml b/.idea/neos-majiang-v3.iml
new file mode 100644
index 0000000..ff88395
--- /dev/null
+++ b/.idea/neos-majiang-v3.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..9661ac7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/package-lock.json b/package-lock.json
index 07ee1d1..f949dca 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,18 +9,15 @@
"version": "3.0.0",
"license": "MIT",
"dependencies": {
- "axios": "^0.27.2",
"express": "^4.18.1",
"json2emap": "^0.2.0",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
- "swr": "^1.3.0",
"uuid": "^8.3.2",
"ws": "^8.8.1"
},
"devDependencies": {
- "@types/axios": "^0.14.0",
"@types/express": "^4.17.13",
"@types/lodash": "^4.14.184",
"@types/react-dom": "^18.0.6",
@@ -570,16 +567,6 @@
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==",
"dev": true
},
- "node_modules/@types/axios": {
- "version": "0.14.0",
- "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz",
- "integrity": "sha512-KqQnQbdYE54D7oa/UmYVMZKq7CO4l8DEENzOKc4aBRwxCXSlJXGz83flFx5L7AWrOQnmuN3kVsRdt+GZPPjiVQ==",
- "deprecated": "This is a stub types definition for axios (https://github.com/mzabriskie/axios). axios provides its own type definitions, so you don't need @types/axios installed!",
- "dev": true,
- "dependencies": {
- "axios": "*"
- }
- },
"node_modules/@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
@@ -1108,20 +1095,6 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
},
- "node_modules/asynckit": {
- "version": "0.4.0",
- "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
- "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
- },
- "node_modules/axios": {
- "version": "0.27.2",
- "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
- "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
- "dependencies": {
- "follow-redirects": "^1.14.9",
- "form-data": "^4.0.0"
- }
- },
"node_modules/balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -1469,17 +1442,6 @@
"integrity": "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==",
"dev": true
},
- "node_modules/combined-stream": {
- "version": "1.0.8",
- "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
- "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
- "dependencies": {
- "delayed-stream": "~1.0.0"
- },
- "engines": {
- "node": ">= 0.8"
- }
- },
"node_modules/commander": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
@@ -1649,14 +1611,6 @@
"node": ">=8"
}
},
- "node_modules/delayed-stream": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
- "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
- "engines": {
- "node": ">=0.4.0"
- }
- },
"node_modules/depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@@ -2086,25 +2040,6 @@
"flat": "cli.js"
}
},
- "node_modules/follow-redirects": {
- "version": "1.15.1",
- "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
- "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==",
- "funding": [
- {
- "type": "individual",
- "url": "https://github.com/sponsors/RubenVerborgh"
- }
- ],
- "engines": {
- "node": ">=4.0"
- },
- "peerDependenciesMeta": {
- "debug": {
- "optional": true
- }
- }
- },
"node_modules/foreground-child": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz",
@@ -2118,19 +2053,6 @@
"node": ">=8.0.0"
}
},
- "node_modules/form-data": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
- "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
- "dependencies": {
- "asynckit": "^0.4.0",
- "combined-stream": "^1.0.8",
- "mime-types": "^2.1.12"
- },
- "engines": {
- "node": ">= 6"
- }
- },
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@@ -4147,14 +4069,6 @@
"url": "https://github.com/sponsors/ljharb"
}
},
- "node_modules/swr": {
- "version": "1.3.0",
- "resolved": "https://registry.npmjs.org/swr/-/swr-1.3.0.tgz",
- "integrity": "sha512-dkghQrOl2ORX9HYrMDtPa7LTVHJjCTeZoB1dqTbnnEDlSvN8JEKpYIYurDfvbQFUUS8Cg8PceFVZNkW0KNNYPw==",
- "peerDependencies": {
- "react": "^16.11.0 || ^17.0.0 || ^18.0.0"
- }
- },
"node_modules/tapable": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
@@ -5279,15 +5193,6 @@
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==",
"dev": true
},
- "@types/axios": {
- "version": "0.14.0",
- "resolved": "https://registry.npmjs.org/@types/axios/-/axios-0.14.0.tgz",
- "integrity": "sha512-KqQnQbdYE54D7oa/UmYVMZKq7CO4l8DEENzOKc4aBRwxCXSlJXGz83flFx5L7AWrOQnmuN3kVsRdt+GZPPjiVQ==",
- "dev": true,
- "requires": {
- "axios": "*"
- }
- },
"@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
@@ -5762,20 +5667,6 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg=="
},
- "asynckit": {
- "version": "0.4.0",
- "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
- "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
- },
- "axios": {
- "version": "0.27.2",
- "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz",
- "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==",
- "requires": {
- "follow-redirects": "^1.14.9",
- "form-data": "^4.0.0"
- }
- },
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -6048,14 +5939,6 @@
"integrity": "sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==",
"dev": true
},
- "combined-stream": {
- "version": "1.0.8",
- "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
- "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
- "requires": {
- "delayed-stream": "~1.0.0"
- }
- },
"commander": {
"version": "8.3.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-8.3.0.tgz",
@@ -6188,11 +6071,6 @@
"strip-bom": "^4.0.0"
}
},
- "delayed-stream": {
- "version": "1.0.0",
- "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
- "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
- },
"depd": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
@@ -6524,11 +6402,6 @@
"integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==",
"dev": true
},
- "follow-redirects": {
- "version": "1.15.1",
- "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
- "integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA=="
- },
"foreground-child": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz",
@@ -6539,16 +6412,6 @@
"signal-exit": "^3.0.2"
}
},
- "form-data": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
- "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
- "requires": {
- "asynckit": "^0.4.0",
- "combined-stream": "^1.0.8",
- "mime-types": "^2.1.12"
- }
- },
"forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@@ -8045,12 +7908,6 @@
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
"dev": true
},
- "swr": {
- "version": "1.3.0",
- "resolved": "https://registry.npmjs.org/swr/-/swr-1.3.0.tgz",
- "integrity": "sha512-dkghQrOl2ORX9HYrMDtPa7LTVHJjCTeZoB1dqTbnnEDlSvN8JEKpYIYurDfvbQFUUS8Cg8PceFVZNkW0KNNYPw==",
- "requires": {}
- },
"tapable": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
diff --git a/src/dev/single/server.ts b/src/dev/single/server.ts
index 7094968..e44e55a 100644
--- a/src/dev/single/server.ts
+++ b/src/dev/single/server.ts
@@ -1,75 +1,78 @@
import Game from "../../lib/majiang/game";
import Player from "../../lib/majiang-ai/0502/player";
+import {PlayerProxy} from "../../server/player/Proxy"
import View from "../../lib/majiang/view";
import express from "express";
import http from "http";
import ws from "ws";
-import { Message, Paipu } from "../../lib/majiang/types";
+import {Message, Paipu} from "../../lib/majiang/types";
+import {WSPlayer} from "../../server/player/WSPlayer";
class NeoView extends View {
- game: Game;
- ws: any;
- constructor(game: Game) {
- super();
- game.view = this;
- this.game = game;
- }
+ game: Game;
+ ws: any;
- render(type: string, data?: any) {
- if (this.ws) {
- this.ws.send(JSON.stringify({ type, data, model: this.game.model }));
+ constructor(game: Game) {
+ super();
+ game.view = this;
+ this.game = game;
}
- }
- override kaiju = () => {
- this.render("kaiju");
- };
+ render(type: string, data?: any) {
+ if (this.ws) {
+ this.ws.send(JSON.stringify({type, data, model: this.game.model}));
+ }
+ }
+
+ override kaiju = () => {
+ this.render("kaiju");
+ };
- override redraw = () => {
- this.render("redraw");
- };
+ override redraw = () => {
+ this.render("redraw");
+ };
- override update = (data: Message) => {
- this.render("update", data);
- };
+ override update = (data: Message) => {
+ this.render("update", data);
+ };
- override say = (
- code: "zimo" | "gang" | "lizhi" | "rong" | "peng" | "chi",
- player: 0 | 1 | 2 | 3
- ) => {
- this.render("say", { code, player });
- };
+ override say = (
+ code: "zimo" | "gang" | "lizhi" | "rong" | "peng" | "chi",
+ player: 0 | 1 | 2 | 3
+ ) => {
+ this.render("say", {code, player});
+ };
- override summary = (paipu: Paipu) => {
- this.render("summary", paipu);
- };
+ override summary = (paipu: Paipu) => {
+ this.render("summary", paipu);
+ };
}
async function generateGame() {
- const players = [0, 1, 2, 3].map((num) => new Player());
- const game = new Game(players);
- const view = new NeoView(game);
- game.kaiju();
- return { game, view };
+ const players = [0, 1, 2, 3].map((num) => new PlayerProxy(new WSPlayer()));
+ const game = new Game(players);
+ const view = new NeoView(game);
+ game.kaiju();
+ return {game, view};
}
const app = express();
const server = http.createServer(app);
-const wss = new ws.Server({ server });
+const wss = new ws.Server({server});
let data: { game: Game; view: NeoView } | undefined = undefined;
app.use("/", express.static(__dirname + "/build"));
app.post("/api/entry/", async (req: express.Request, res: express.Response) => {
- data = await generateGame();
- res.send("ok");
+ data = await generateGame();
+ res.send("ok");
});
-wss.on("connection", (ws) => {
- if (data) {
- data.view.ws = ws;
- }
-});
+// wss.on("connection", (ws) => {
+// if (data) {
+// data.view.ws = ws;
+// }
+// });
server.listen(3000, () => console.log("dev single ok"));
diff --git a/src/lib/majiang/board.ts b/src/lib/majiang/board.ts
index b05c6aa..9aff2ea 100644
--- a/src/lib/majiang/board.ts
+++ b/src/lib/majiang/board.ts
@@ -23,6 +23,7 @@ class Shan {
}
export default class Board {
+ shoupai: any;
constructor(kaiju) {
if (kaiju) this.kaiju(kaiju);
}
diff --git a/src/lib/majiang/player.ts b/src/lib/majiang/player.ts
index 88dc826..e3b80f8 100644
--- a/src/lib/majiang/player.ts
+++ b/src/lib/majiang/player.ts
@@ -7,22 +7,9 @@ import { Message, MessageKaiju, MessageReply, Paipu } from "./types";
import Game from "./game";
import Util from "./util";
-type hoge = {
- a: {
- c: number;
- };
-};
-type hage = { b: { b: string } };
-type hamage = hoge | hage;
-
-const h: hamage = { a: { c: 10 } };
-if (h.a) {
- h;
-}
-
export default class Player {
_id: number;
- _callback: () => {} | null;
+ _callback: (...args?) => {} | null;
_rule: Rule;
_model: Board;
_menfeng: number;
@@ -97,7 +84,7 @@ export default class Player {
if (this._callback) this.action_kaiju(kaiju);
}
- /**
+ /** 最初の配牌
* qipai から 卓情報 を設定し、Majiang.Player#action_qipai を呼び出し応答を返す。
* @param {Majiang.Message} qipai メッセージ#配牌
*/
@@ -123,7 +110,7 @@ export default class Player {
if (this._callback) this.action_qipai(qipai);
}
- /**
+ /** ツモ
* zimo から 卓情報 を設定し、Majiang.Player#action_zimo を呼び出し応答を返す。 gangzimo が真の場合は槓自摸を表す。
* @param {Majiang.Message} zimo メッセージ#自摸 (もしくは メッセージ#槓自摸)
* @param {boolean} gangzimo
@@ -135,7 +122,7 @@ export default class Player {
if (this._callback) this.action_zimo(zimo, gangzimo);
}
- /**
+ /** 捨てる
* dapai から 卓情報 を設定し、Majiang.Player#action_dapai を呼び出し応答を返す。
* @param {Majiang.Message} dapai メッセージ#打牌
*/
diff --git a/src/main.ts b/src/server/main.ts
similarity index 93%
rename from src/main.ts
rename to src/server/main.ts
index 41cb87d..d9c68c4 100644
--- a/src/main.ts
+++ b/src/server/main.ts
@@ -1,5 +1,5 @@
import NeosGame from "./neosgame";
-import Player from "./lib/majiang/player";
+import Player from "../lib/majiang/player";
import ws from "ws";
import http from "http";
import express from "express";
diff --git a/src/neosPlayer.ts b/src/server/neosPlayer.ts
similarity index 91%
rename from src/neosPlayer.ts
rename to src/server/neosPlayer.ts
index ec850fd..414e204 100644
--- a/src/neosPlayer.ts
+++ b/src/server/neosPlayer.ts
@@ -1,4 +1,4 @@
-import Player from "./lib/majiang/player";
+import Player from "../lib/majiang/player";
import {
Kaiju,
Qipai,
@@ -10,7 +10,7 @@ import {
Hule,
Pingju,
Paipu,
-} from "./lib/majiang/types";
+} from "../lib/majiang/types";
import ws from "ws";
export class NeosPlayer extends Player {
diff --git a/src/neosgame.ts b/src/server/neosgame.ts
similarity index 80%
rename from src/neosgame.ts
rename to src/server/neosgame.ts
index 868183e..83b24ea 100644
--- a/src/neosgame.ts
+++ b/src/server/neosgame.ts
@@ -1,5 +1,5 @@
-import Game from "./lib/majiang/game";
-import { Rule } from "./lib/majiang/types";
+import Game from "../lib/majiang/game";
+import { Rule } from "../lib/majiang/types";
import { NeosPlayer } from "./neosPlayer";
export default class NeosGame extends Game {
diff --git a/src/server/player/Proxy.ts b/src/server/player/Proxy.ts
new file mode 100644
index 0000000..6fb5d6a
--- /dev/null
+++ b/src/server/player/Proxy.ts
@@ -0,0 +1,19 @@
+import Player from "../../lib/majiang/player";
+import {
+ Message,
+ MessageReply,
+} from "../../lib/majiang/types";
+
+export class PlayerProxy extends Player {
+ private player: Player
+
+ constructor(c: Player) {
+ super();
+ this.player = c
+ }
+
+ override action(msg: Message, callback: (MessageReply? : MessageReply) => {}) {
+ console.log("Proxying",msg)
+ this.player.action(msg, callback);
+ }
+}
diff --git a/src/server/player/WSPlayer.ts b/src/server/player/WSPlayer.ts
new file mode 100644
index 0000000..d862952
--- /dev/null
+++ b/src/server/player/WSPlayer.ts
@@ -0,0 +1,57 @@
+import Player from "../../lib/majiang/player";
+import {Dapai, Fulou, Gang, Gangzimo, Hule, Kaiju, Paipu, Pingju, Qipai, Zimo} from "../../lib/majiang/types";
+
+export class WSPlayer extends Player {
+ ws: any
+
+ constructor() {
+ super();
+ }
+
+ action_kaiju(kaiju: Kaiju) {
+ this?._callback();
+ }
+
+ action_qipai(qipai: Qipai) {
+ this?._callback();
+ }
+
+ // ツモ
+ action_zimo(zimo: Zimo | null, gangzimo: Gangzimo | null) {
+ if (zimo?.l != this._menfeng) return this._callback();
+ console.log(this._model.shoupai[this._menfeng]._bingpai)
+ // this._callback({ dapai: "m3" });
+ // this?._callback();
+ }
+
+ // 打牌
+ action_dapai(dapai: Dapai) {
+ // if (dapai?.l !== this._menfeng) {
+ // this?._callback();
+ // return;
+ // }
+ // console.log("dapai")
+ // this._callback({ daopai: "m1" });
+ this?._callback();
+ }
+
+ action_fulou(fulou: Fulou) {
+ this?._callback();
+ }
+
+ action_gang(gang: Gang) {
+ this?._callback();
+ }
+
+ action_hule(hule: Hule) {
+ this?._callback();
+ }
+
+ action_pingju(pingju: Pingju) {
+ this?._callback();
+ }
+
+ action_jieju(paipu: Paipu) {
+ this?._callback();
+ }
+}