krouzek:uloha:sachy1

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Obě strany předchozí revize Předchozí verze
Následující verze
Předchozí verze
krouzek:uloha:sachy1 [2023/10/17 20:33] adminkrouzek:uloha:sachy1 [2023/11/15 20:54] (aktuální) – upraveno mimo DokuWiki 127.0.0.1
Řádek 14: Řádek 14:
   * Můžete svůj program dělat v klasické stránce - výstup můžete rovnou "rendrovat" na stránku - tj. po každém tahu aktualizovat hodnoty "šachovnice" - HTML tabulky (nejsnazší)   * Můžete svůj program dělat v klasické stránce - výstup můžete rovnou "rendrovat" na stránku - tj. po každém tahu aktualizovat hodnoty "šachovnice" - HTML tabulky (nejsnazší)
  
-Můžeme program napsat v NodeJS a potom jeho výstup poslat do klienta (jako JSON). Klient potom výstup zobrazí.+**Nejrobustnější**: Můžeme program napsat v NodeJS a potom jeho výstup poslat do klienta (jako JSON). Klient potom výstup zobrazí.
 Tímto komplikovanějším řešením umožníme budoucí síťovou hru více hráčů proti sobě. Také nás to donutí striktně oddělit logiku (v nodejs projektu) od zobrazení a UI (ve stránce) Tímto komplikovanějším řešením umožníme budoucí síťovou hru více hráčů proti sobě. Také nás to donutí striktně oddělit logiku (v nodejs projektu) od zobrazení a UI (ve stránce)
-Nejzajímavější možností pak je možnost rozdělit práci bez problémů na dva programátory = jeden dělá zobrazovadlo a klikadlo, druhý implementuje pravidla šachů - a shodnete se na nějakém rozhraní. 
  
-==== Client/Server rozhraní od ChatGPT ==== +Zajímavou možností pak je rozdělit práci bez problémů na dva programátory = jeden lá zobrazovadlo klikadlodruhý implementuje pravidla šachů - a shodnete se na nějakém rozhraní.
-> Create an interface for a multiplayer chess game between the client (visualizing the game, allowing the players to select next move) and the server (implementing the chess game logic). RESTApi +
- +
-Poznámky: +
-  * Všimněte si, že návrh vlastně neřeší že hrajeme šachy, ale věnuje se spíš správě herních sessions +
-  * Pravděpodobně by podobná šablona šla použít na libovolnou tahovou hru +
-  * Není řešena autentizace uživatelů, ale samozřejmě by bylo potřeba jí pak mít +
-  * Problém který není řešen: endpoint //GET /api/games/{gameId}/allowed-moves// - pokud nechceme v klientovi opakovat kód pro logiku tvoření tahů, musí se dozvět co je přípustné co ne (aby umožnil uživateli pouze přípustné tahy) +
- +
-==== Endpoints ==== +
- +
-1. **Create a New Game** +
-   - Endpoint: `POST /api/games` +
-   - Description: Create a new chess game. This endpoint initializes the game state and returns a unique game ID for reference. +
-   - Request: None +
-   - Response: `{"gameId": "unique-game-id"}` +
- +
-2. **Get Game State** +
-   - Endpoint: `GET /api/games/{gameId}` +
-   - Description: Retrieve the current state of the gameincluding the board configuration, whose turn it is, and other game-specific details. +
-   - Request: None +
-   - Response: Detailed game state JSON +
- +
-3. **Make Move** +
-   - Endpoint: `POST /api/games/{gameId}/move` +
-   - Description: Allows a player to make a move in the gameThe request should include the player's move details, such as the starting and ending positions of the piece. +
-   - Request: `{ "playerColor": "white", "from": { "x": X1, "y": Y1 }, "to": { "x": X2, "y": Y2 } }` +
-   - Response: `{"success": true, "message": "Move successful"}` +
- +
-4. **List Active Games** +
-   - Endpoint: `GET /api/games` +
-   - Description: Retrieve a list of all active games, including their IDs and details. +
-   - Request: None +
-   - Response: List of active game objects +
- +
-5. **Join a Game** +
-   - Endpoint: `POST /api/games/{gameId}/join` +
-   - Description: Allows a player to join an existing game. +
-   - Request: `{ "playerName": "PlayerName", "playerColor": "black" }` +
-   - Response: `{"success": true, "message": "Joined the game"}` +
- +
-6. **Resign from the Game** +
-   - Endpoint: `POST /api/games/{gameId}/resign` +
-   - Description: Allows a player to resign from the game. +
-   - Request: None +
-   - Response: `{"success": true, "message": "Resigned from the game"}`+
  
 +Vygenerovaný příklad takového klient-server rozhraní najdete na konci stránky.
  
 ==== Data Structures ==== ==== Data Structures ====
Řádek 246: Řádek 201:
 </code> </code>
  
 +
 +----
 +
 +==== Client/Server rozhraní od ChatGPT ====
 +> Create an interface for a multiplayer chess game between the client (visualizing the game, allowing the players to select next move) and the server (implementing the chess game logic). RESTApi
 +
 +Poznámky:
 +  * Všimněte si, že návrh vlastně neřeší že hrajeme šachy, ale věnuje se spíš správě herních sessions
 +  * Pravděpodobně by podobná šablona šla použít na libovolnou tahovou hru
 +  * Není řešena autentizace uživatelů, ale samozřejmě by bylo potřeba jí pak mít
 +  * Problém který není řešen: endpoint //GET /api/games/{gameId}/allowed-moves// - pokud nechceme v klientovi opakovat kód pro logiku tvoření tahů, musí se dozvědět co je přípustné a co ne (aby umožnil uživateli pouze přípustné tahy)
 +
 +==== Endpoints ====
 +
 +1. **Create a New Game**
 +   - Endpoint: `POST /api/games`
 +   - Description: Create a new chess game. This endpoint initializes the game state and returns a unique game ID for reference.
 +   - Request: None
 +   - Response: `{"gameId": "unique-game-id"}`
 +
 +2. **Get Game State**
 +   - Endpoint: `GET /api/games/{gameId}`
 +   - Description: Retrieve the current state of the game, including the board configuration, whose turn it is, and other game-specific details.
 +   - Request: None
 +   - Response: Detailed game state JSON
 +
 +3. **Make a Move**
 +   - Endpoint: `POST /api/games/{gameId}/move`
 +   - Description: Allows a player to make a move in the game. The request should include the player's move details, such as the starting and ending positions of the piece.
 +   - Request: `{ "playerColor": "white", "from": { "x": X1, "y": Y1 }, "to": { "x": X2, "y": Y2 } }`
 +   - Response: `{"success": true, "message": "Move successful"}`
 +
 +4. **List Active Games**
 +   - Endpoint: `GET /api/games`
 +   - Description: Retrieve a list of all active games, including their IDs and details.
 +   - Request: None
 +   - Response: List of active game objects
 +
 +5. **Join a Game**
 +   - Endpoint: `POST /api/games/{gameId}/join`
 +   - Description: Allows a player to join an existing game.
 +   - Request: `{ "playerName": "PlayerName", "playerColor": "black" }`
 +   - Response: `{"success": true, "message": "Joined the game"}`
 +
 +6. **Resign from the Game**
 +   - Endpoint: `POST /api/games/{gameId}/resign`
 +   - Description: Allows a player to resign from the game.
 +   - Request: None
 +   - Response: `{"success": true, "message": "Resigned from the game"}`
  
  
  • krouzek/uloha/sachy1.1697574787.txt.gz
  • Poslední úprava: 2023/11/15 20:54
  • (upraveno mimo DokuWiki)