nostr-protocol / nips

Nostr Implementation Possibilities
2.39k stars 582 forks source link

Chess server #1453

Open mikedilger opened 2 months ago

mikedilger commented 2 months ago

To get a win today I wrote a chess server. I had to invent the protocol, and I went with this (this doesn't overlap with NIP-64):

[EDITED AS I CHANGED THE EVENTS A BIT]

Request to play:

{
    "pubkey": <player-asking>,
    "kind": 20300,
    "tags": [
         ["p", <server-pubkey>],
    ],
    "content": "",
     ...
}

Response to the request to play where status is one of:

{
   "pubkey": <server>,
   "kind": 20301,
   "tags": [
       ["p": <player-asking-or-their-opponent>],
   ],
   "content": <status-see-above>,
   ...
}

Game state (sent by the server initially and after every legal move). Initially it should come after the response to request to play. FEN is https://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards_Notation

{
    "pubkey": <server>
    "kind": 20302,
    "tags": [
        ["d": <game-id>],
        ["p": <pubkey-for-white>],
        ["p": <pubkey-for-black>],
    ],
    "content": <FEN>,
    ...
}

Game Move long algebraic move notation is https://en.wikipedia.org/wiki/Algebraic_notation_(chess)#Long_algebraic_notation (but without captures or piece notation or check notation... just the source and dest and maybe a promotion piece after that, e.g. e7e8Q)

{
    "pubkey": <player>,
    "kind": 20303,
    "tags": [
        ["d": <game-id>],
        ["p", <server-pubkey>],
        ["p": <pubkey-for-white>],
        ["p": <pubkey-for-black>],
    ],
    "content": <long-algebraic-move>, // or various other signals like 'quit' TBD.
    ...
}

Game error, If the game is known, and the error event came from a player of the game:

{
    "pubkey": <server>,
    "kind": 20304
    "tags": [
        ["e": <event-that-was-in-error>],
        ["d": <game-id>], // if relevant (not present if game not found)
        ["p": <pubkey-for-white>], // if game not found, this is the author of event reacted to
        ["p": <pubkey-for-black>], // only if game was found, this is the other player
    ],
    "content": <error message>
    ...
}

If the game is not known:

{
    "pubkey": <server>,
    "kind": 20304
    "tags": [
        ["e": <event-that-was-in-error>],
        ["p": <pubkey-of-error-event>],
    ],
    "content": <error message>
    ...
}

I am running it right now here:

pubkey: dbb45efeb8cc10e6f75fdff7e561e7db39cc7ba6592f4c22e26f3ee36b2e7bc2
relay:  wss://chorus.mikedilger.com:444/

We could add this to NIP-64 (or something like it).

mikedilger commented 2 months ago

I wrote a command line client and played with myself.