{"id":13724886,"url":"https://github.com/shivamMg/tictactinytoe","last_synced_at":"2025-05-07T19:31:13.523Z","repository":{"id":48809894,"uuid":"382390921","full_name":"shivamMg/tictactinytoe","owner":"shivamMg","description":"2 player tictactoe-hosting TCP server in 640 bytes","archived":false,"fork":false,"pushed_at":"2021-07-10T19:49:15.000Z","size":6,"stargazers_count":26,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-28T18:16:13.609Z","etag":null,"topics":["codegolf","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shivamMg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-02T15:39:12.000Z","updated_at":"2024-08-30T16:15:19.000Z","dependencies_parsed_at":"2022-09-23T21:52:39.236Z","dependency_job_id":null,"html_url":"https://github.com/shivamMg/tictactinytoe","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Ftictactinytoe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Ftictactinytoe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Ftictactinytoe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Ftictactinytoe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shivamMg","download_url":"https://codeload.github.com/shivamMg/tictactinytoe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252943698,"owners_count":21829291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codegolf","nodejs"],"created_at":"2024-08-03T01:02:05.715Z","updated_at":"2025-05-07T19:31:08.492Z","avatar_url":"https://github.com/shivamMg.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"### tictactinytoe\n\n2 player tictactoe-hosting TCP server in 640 bytes:\n\n\u003e ```F=_=\u003e{x=o=z=0;t=1};F();require(\"net\").createServer(c=\u003e{h=\"\\n\";w=s=\u003ec.write(s+h);if(o)return w(\"Game in progress\");c.m={};c.w=w;z++?(o=c,o.W=x.w,x.W=w):x=c;G=e=\u003e{for(l=\"\",i=1;i\u003c=9;i++)l+=i in x.m?\"X\":o\u0026\u0026i in o.m?\"O\":i,l+=i%3?\"|\":h;e.w(l)};G(c);c.on(\"end\",_=\u003ec.W(\"Player left\")).on(\"data\",d=\u003e{if(t^c==x)return;v=parseInt(d);if(isNaN(v)||v\u003c1||v\u003e9||v in{...x.m,...o.m})return c.w(\"Invalid move\");t=c.m[v]=1-t;G(x);o\u0026\u0026G(o);f=i=\u003ei\u003c24?\"123147159369789753258456\".slice(i,i+3).split(\"\").every(j=\u003ej in c.m)||f(i+3):0;if(f(0))throw c.w(\"You won\"),c.W(\"You lost\");if(z++\u003e9)throw r=\"Draw\",c.w(r),c.W(r)})}).listen(9191);process.on(\"uncaughtException\",F)```\n\nTested with node v14.16.1\n\n```bash\nnode -e 'F=_=\u003e{x=o=z=0;t=1};F();require(\"net\").createServer(c=\u003e{h=\"\\n\";w=s=\u003ec.write(s+h);if(o)return w(\"Game in progress\");c.m={};c.w=w;z++?(o=c,o.W=x.w,x.W=w):x=c;G=e=\u003e{for(l=\"\",i=1;i\u003c=9;i++)l+=i in x.m?\"X\":o\u0026\u0026i in o.m?\"O\":i,l+=i%3?\"|\":h;e.w(l)};G(c);c.on(\"end\",_=\u003ec.W(\"Player left\")).on(\"data\",d=\u003e{if(t^c==x)return;v=parseInt(d);if(isNaN(v)||v\u003c1||v\u003e9||v in{...x.m,...o.m})return c.w(\"Invalid move\");t=c.m[v]=1-t;G(x);o\u0026\u0026G(o);f=i=\u003ei\u003c24?\"123147159369789753258456\".slice(i,i+3).split(\"\").every(j=\u003ej in c.m)||f(i+3):0;if(f(0))throw c.w(\"You won\"),c.W(\"You lost\");if(z++\u003e9)throw r=\"Draw\",c.w(r),c.W(r)})}).listen(9191);process.on(\"uncaughtException\",F)'\n```\n\n* Non-minified code is in [tictactinytoe.js](tictactinytoe.js)\n* Use netcat to connect to the server and play\n* Both players must Ctrl-C and reconnect for a new game\n\n```bash\nnetcat localhost 9191  # first player: X\nnetcat localhost 9191  # second player: O\n```\n\n##### Docker\n\n```bash\ndocker run --rm -it node:14-alpine node -e 'F=_=\u003e{x=o=z=0;t=1};F();require(\"net\").createServer(c=\u003e{h=\"\\n\";w=s=\u003ec.write(s+h);if(o)return w(\"Game in progress\");c.m={};c.w=w;z++?(o=c,o.W=x.w,x.W=w):x=c;G=e=\u003e{for(l=\"\",i=1;i\u003c=9;i++)l+=i in x.m?\"X\":o\u0026\u0026i in o.m?\"O\":i,l+=i%3?\"|\":h;e.w(l)};G(c);c.on(\"end\",_=\u003ec.W(\"Player left\")).on(\"data\",d=\u003e{if(t^c==x)return;v=parseInt(d);if(isNaN(v)||v\u003c1||v\u003e9||v in{...x.m,...o.m})return c.w(\"Invalid move\");t=c.m[v]=1-t;G(x);o\u0026\u0026G(o);f=i=\u003ei\u003c24?\"123147159369789753258456\".slice(i,i+3).split(\"\").every(j=\u003ej in c.m)||f(i+3):0;if(f(0))throw c.w(\"You won\"),c.W(\"You lost\");if(z++\u003e9)throw r=\"Draw\",c.w(r),c.W(r)})}).listen(9191);process.on(\"uncaughtException\",F)'\n```\n\n* Use `docker inspect \u003ccontainer\u003e | grep -m 1 '\"IPAddress\":'` to find IP for netcat\n* To exit the server use `docker stop \u003ccontainer\u003e`\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FshivamMg%2Ftictactinytoe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FshivamMg%2Ftictactinytoe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FshivamMg%2Ftictactinytoe/lists"}