{"id":18569028,"url":"https://github.com/filipchalupa/piskvorky","last_synced_at":"2025-07-20T22:06:07.640Z","repository":{"id":65681011,"uuid":"597219721","full_name":"FilipChalupa/piskvorky","owner":"FilipChalupa","description":null,"archived":false,"fork":false,"pushed_at":"2023-02-08T00:03:53.000Z","size":983,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-20T22:04:55.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/FilipChalupa.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-03T22:31:48.000Z","updated_at":"2023-02-03T22:44:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"edf2cd5a-cce1-41a3-822d-bfd9fb6a950c","html_url":"https://github.com/FilipChalupa/piskvorky","commit_stats":{"total_commits":39,"total_committers":1,"mean_commits":39.0,"dds":0.0,"last_synced_commit":"a9e1e75089cf9d7fc66868349cc1228bcf41b0fa"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/FilipChalupa/piskvorky","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fpiskvorky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fpiskvorky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fpiskvorky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fpiskvorky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FilipChalupa","download_url":"https://codeload.github.com/FilipChalupa/piskvorky/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FilipChalupa%2Fpiskvorky/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266205317,"owners_count":23892443,"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":[],"created_at":"2024-11-06T22:31:52.325Z","updated_at":"2025-07-20T22:06:07.616Z","avatar_url":"https://github.com/FilipChalupa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Piškvorky (tic-tac-toe) [![npm](https://img.shields.io/npm/v/piskvorky.svg)](https://www.npmjs.com/package/piskvorky) ![npm type definitions](https://img.shields.io/npm/types/piskvorky.svg)\n\nHelper functions for tic-tac-toe game.\n\n## Installation\n\n```bash\nnpm install piskvorky\n```\n\n## Usage\n\n### Functions\n\n#### `findWinner`\n\nExpects a 1D or 2D array of strings representing the board. Returns the winner (`'o'` or `'x'`), `'tie'` or `null` if there is no winner.\n\n| Value   | Description              |\n| ------- | ------------------------ |\n| `'o'`   | player O                 |\n| `'x'`   | player X                 |\n| `'_'`   | empty field              |\n|         |                          |\n| `'tie'` | tie                      |\n| `null`  | the game is not over yet |\n\n#### `suggestNextMove`\n\nExpects the board and current player (`'o'` or `'x'`). Returns a suggested move position calculated by a very sophisticated 🙃 AI.\n\n---\n\n### Package\n\n```js\nimport { findWinner, suggestNextMove } from 'piskvorky'\n\nconst board = [\n\t['_', '_', 'o'],\n\t['x', 'o', 'o'],\n\t['x', 'x', 'o'],\n]\n\nconst winner = findWinner(board) // the winner is player 'o'\n\nconst flatBoard = ['_', '_', 'o', 'x', 'o', 'o', 'x', 'x', 'o'] // same as board.flat()\n\nconst winnerOfFlatBoard = findWinner(flatBoard) // the winner is player 'o'\n\nconst nextMove = suggestNextMove([\n\t['o', 'x', 'o'],\n\t['_', 'o', 'x'],\n\t['x', 'o', 'x'],\n]) // the next move is {x: 0, y: 1}\n```\n\n#### CDN\n\n```js\nimport { findWinner, suggestNextMove } from 'https://unpkg.com/piskvorky@latest'\n```\n\n---\n\n### Online api\n\n#### Find winner\n\n```js\nconst board = [\n\t['_', '_', 'o'],\n\t['x', 'o', 'o'],\n\t['x', 'x', 'o'],\n]\n\nconst response = await fetch(\n\t'https://piskvorky.czechitas-podklady.cz/api/find-winner',\n\t{\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-type': 'application/json',\n\t\t},\n\t\tbody: JSON.stringify({ board }),\n\t},\n)\nconst { winner, error } = await response.json()\nconsole.log({ winner, error })\n```\n\n#### Suggest next move\n\n```js\nconst response = await fetch(\n\t'https://piskvorky.czechitas-podklady.cz/api/suggest-next-move',\n\t{\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-type': 'application/json',\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tboard: [\n\t\t\t\t['_', '_', 'o'],\n\t\t\t\t['_', 'o', '_'],\n\t\t\t\t['_', 'x', 'x'],\n\t\t\t],\n\t\t\tplayer: 'o',\n\t\t}),\n\t},\n)\nconst { position, error } = await response.json()\nconsole.log({ position, error })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilipchalupa%2Fpiskvorky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilipchalupa%2Fpiskvorky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilipchalupa%2Fpiskvorky/lists"}