Willem Olding
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Fundamentals of Games on Holochain Holochain is an ideal system for developing certain types of game protocols. The word 'game' can mean a lot of different things in different contexts. When we refer to a game we mean it in the simplest possible way. - An interaction between two or more **players** - The players take **actions/moves** which must abide by certain **rules** - Through taking actions the game reaches a demonstratable **outcome** Many types of interactions people engage in that we typically don't refer to as games can be framed this way (e.g. a cryptocurrency transaction, voting etc) ## What kind of games are suitable? The simplest class of games that are well suited to Holochain are [sequantial games](https://en.wikipedia.org/wiki/Sequential_game) with [perfect information](https://en.wikipedia.org/wiki/Perfect_information). This includes the classical board games including - Chess/Checkers - tic-tac-toe - Go - Chinese Checkers - [Reversi/Othello](https://en.wikipedia.org/wiki/Reversi) *great one to try - [Dots and Boxes](https://en.wikipedia.org/wiki/Dots_and_Boxes) - [Halma](https://en.wikipedia.org/wiki/Halma) - [Nim](https://plus.maths.org/content/play-win-nim) - [Hex](https://en.wikipedia.org/wiki/Hex_(board_game)) - [Racetrack](https://en.wikipedia.org/wiki/Racetrack_(game)) (Thanks Mike great suggestion) These are the types of games we will focus on in this course. As an aside Holochain can also be used for games that require imperfect/hidden information that must be committed to in advance and not changed. Examples of these types of games are - rock/paper/scissors - battleship There is also the possibility of games that require randomness. Randomness cannot be generated internally but entropy can be supplied by each of the participants such that no subset can predict the outcome. This allows for games like - dice games - card games These are outside of the scope of this course but will be entirely within your ability after the course is complete! ### Games that are NOT suitable Anything that requires real-time or timing dependent interactions. Basically anything considered a modern video game is not suitable. Furthermore any single player game is not a good choice since this does not make use of the features of Holochain! Games with many players are possible but outside the scope of this course. It is best to keep the player requirements small. If you have another idea for a game you want to implement be sure to check with us beforehand to ensure you have the best learning experience possible. ## 1. General game architecture The fundamental building block of all of these games is an **action** or **move**. Given all the moves that have taken place in a particular game so far it should be possible to entirely determine the **game state**. Given moves made so far and a new move must be possible to determine if this new move is valid or invalid. Each move must also be cryptographically signed by the agent making it to prove that it was indeed authorized by them. Moves can be represented by **entries** in Holochain. This means they are automatically validated, signed, persisted to the local chain and possible pushed to the DHT as well. ### An example - Checkers ![checkers-board](https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Ftse3.mm.bing.net%2Fth%3Fid%3DOIP.woCAGsOml45cM-5BuKHVtAHaD_%26pid%3DApi&f=1) #### Moves Lets look at the concrete example of a game of checkers. A move might looks as follows: ```javascript { game: "QmHashOfGame123", author: "QmMyAgentAddress000", previous_move: "QmHashOfPreviousMove" move_type: { MovePiece: { from: {x: 0, y: 2}, to: {x: 1, y: 3} }. } } } ``` This would be some agent (QmMyAgentAddress000) playing some game (QmHashOfGame123) moving a piece diagonally. It is important to include all of this extra information (e.g. author, previous move) such that this move has a unique identifying hash. #### Validation What might the validation for this kind of move look like? It turns out a simple game like checkers has quite a lot of rules when it comes down to it: - It must be the authors turn in this game - The game must not have already ended - All coordinates must be in bounds - A piece belonging to the author must exist at the `from` coordinates - The location of the `to` coordinates must be empty - That particular movement must be allowed according to the movement rules of the game - Can only move diagonally unless jumping an opponents piece - Can only move forward unless piece is a king (has reached the other side) If these rules are correctly captured and encoded into the Holochain validation callback for a `move` entry the DNA will reject any attempted moves that are not valid. It is fundamentally impossible to make an invalid move without hacking the validation process (after which other legitmate agents who validate your move can identify you as a cheater and block any further actions). #### State The game state for a checkers game could be represented in many ways. One possible way is to store only the location of the pieces for each player in a sparse array format e.g. ```javascript { complete: false, player_1: { pieces: [{x: 3, y: 2}, {x: 4, y: 1}, ...], resigned: false, } player_2: { pieces: [{x: 7, y: 2}, {x: 8, y: 3}, ...], resigned: false, } } ``` Remember the state is not stored but only reduced from a sequence of moves. It is only needed for performing the validation of new moves. Reducing the state from a sequence of moves may also be complex and account for things such as: - Pieces captured - Pieces reaching the other side to become a king - If one of the players has resigned ### Exercises: 1. Write down what a move for your game might look like. Make sure that each move has enough fields to be totally unique. 1. List the validation rules for a move in your game. Be sure to capture everything even if it is obvious (Holochain doesn't know about object permanance) 1. Consider how to represent the state in your game. Write pseudocode for how you could reduce a sequence of moves into a given game state.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully