Bela Stoyan
    • 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
    # MG2: Messages ## State Machine ``` +-------------+ placementPhase +------------------+ | Lobby state +--------------------->| Placement state | +-------------+ +-------+----------+ ^ | | | | | | | gameStart | | | | | | | v | gameOver +---------------+ +-----------------------------+ Running state | +---------------+ ``` ## Datatypes ### ServerState (Struct) | Field | Type | Explanation | | - | - | - | | teamShips | ShipState[] | | | actionPoints | int | Action points per player | | visibleHostileShips | Coordinate[] | Visible hostile ships | ### Config (Struct) | Field | Type | Explanation | | - | - | - | | serverName | String | Server Name | shipBalancings | ShipBalancing[2][] | | | shipsPerTeam | ShipType[2][] | | | N | int | Board size | | actionPointsGain | int | Action point gain per turn | | teamSizes | int[2] | Team sizes | ### ShipState (Struct) | Field | Type | Explanation | | - | - | - | | shipType | ShipType | | | position | Coord | | | currentHealth | int | Current health of the ship | | remainingCooldown | int | Remaining cooldown of the ship | | owner | String | Owner of the ship | ### Coordinate (Struct) | Field | Type | Explanation | | - | - | - | | x | int | x coordinate | | y | int | y coodinate | ### PlayerLobbyState (Struct) | Field | Type | Explanation | | - | - | - | | ready | bool | Is player ready | | playerID | int | Unique player ID | | name | String | Player name | ### Costs (Struct) | Field | Type | Explanation | | - | - | - | | cooldown | int | Number of rounds needed for cooldown | | actionPoints | int | Action points the action requires | ### CommonBalancing (Struct) | Field | Type | Explanation | | - | - | - | | shootCosts | Costs | | | shootRange | int | | | movementCosts | Costs | | | movementSpeed | int | | | abilityCosts | Costs | | | visionRange | int | | | initialHealth | int | | ### ShipBalancing (Struct) | Field | Type | Explanation | | - | - | - | | shipType | ShipTypeWithBalancing | - | | commonBalancing | CommonBalancing | - | ### ShipType (Struct) | Values | | - | | CARRIER | | BATTLESHIP| | CRUISER | | SUBMARINE| | DESTROYER| ### ShipTypeWithBalancing (Enum) | Values | | - | | CARRIER(ability: ScoutBalancing) | | BATTLESHIP (ability: MultiMissleBalancing)| | CRUISER(ability: EngineBoostBalancing) | | SUBMARINE(ability: TorpedoBalancing) | | DESTROYER(ability: PredatorMissileBalancing) | ### ScoutBalancing (Enum) | Field | Type | Explanation | - | - | - | | range | int | Range of the scout ability | | radius | int | Radius of scout ability | ### MultiMissleBalancing (Enum) | Field | Type | Explanation | - | - | - | | radius | int | Radius of missle ability | | damage | int | The damage of each rocket | ### PredatorMissileBalancing (Enum) | Field | Type | Explanation | - | - | - | | range | int | Range of the scout ability | | radius | int | Radius of scout ability | | damage | int | Damage of predator missile ability | ### EngineBoostBalancing (Struct) | Field | Type | Explanation | - | - | - | | steps | int | The ammount of fields the ship moves | ### TorpedoBalancing (Struct) | Field | Type | Explanation | - | - | - | | range | int | Range of the torpedo ability | | damage | int | The damage of the torpedo ability | ### ShipAction (enum) | Values | | - | | MOVE(moveProps: MoveProperties) | | SHOOT(shootProps: ShootProperties) | | ROTATE(rotateProps: RotateProperties) | | TORPEDO(torpedoProps: TorpedoProperties) | | SCOUT_PLANE(scoutProps: ScoutPlaneProperties) | | MULTI_MISSILE(multiMissileProps: MultiMissileProperties) | | PREDATOR(predatorProps: PredatorProperties) | | ENGINE_BOOST | ### MoveProperties (Struct) | Field | Type | Explanation | | - | - | - | | direction | MoveDirection | Direction to move ### ShootProperties (Struct) | Field | Type | Explanation | | - | - | - | | target | Coordinate | Target of Attack | ### RotateProperties (Struct) | Field | Type | Explanation | | - | - | - | | roatation | RoatationDirection | | ### TorpedoProperties (Struct) | Field | Type | Explanation | | - | - | - | | direction | Direction | Direction to shoot torpedo towards | ### ScoutPlaneProperties (Struct) | Field | Type | Explanation | | - | - | - | | center | Coordinate | Center point of scout ability | ### MultiMissileProperties (Struct) | Field | Type | Explanation | | - | - | - | | positions | Coordinate[3] | Positions to shoot at | ### PredatorMissileProperties (Struct) | Field | Type | Explanation | | - | - | - | | center | Coordinate | center of missile impact | ### Direction (Enum) | Values | | - | | NORTH | | EAST | | SOUTH | | WEST | ### MoveDirection (Enum) | Values | | - | | FORWARD | | BACKWARD | ### RotationDirection (Enum) | Values | | - | | COUNTER_CLOCKWISE | | CLOCKWISE | ### GameEndReason (Enum) | Values | | - | | DISCONNECT | | REGULAR(is_winner: bool) | ### ShipAssignment (Struct) | Field | Type | Explanation | | - | - | - | | shipNumber | int | | | coordinate | Coordinate | coordinate of ship origin | | direction | Direction | direction of ship | ## Error Codes | Number | Reason | | - | - | ## Messages ### Errors Responses can either be: - A success - A failure with a error code and an optional error message A response always contains the response type and, iff successfull all fields of the specific response. If the response is non-successfull it instead contains an error code and a optional error message. The equivalent rust type would be: ```rust enum Response<T> { Ok(T), Error(int, Option<String>) } ``` ### Serverbound #### Discovery ##### serverConfigRequest Every client can request the config of the server, even before joining the lobby. | Field | Type | Explanation | | - | - | - | ##### joinRequest Sent by the client to get to the server lobby. | Field | Type | Explanation | | - | - | - | | username | String | | #### Lobby ##### teamSwitchRequest | Field | Type | Explanation | | - | - | - | ##### setReadyStateRequest | Field | Type | Explanation | | - | - | - | | readyState | bool | New ready state | #### Placement ##### setPlacementRequest | Field | Type | Explanation | | - | - | - | | assignments | ShipAssignment[] | Assignments | #### Game ##### serverStateRequest | Field | Type | Explanation | | - | - | - | ##### shipActionRequest | Field | Type | Explanation | | - | - | - | | shipNumber | int | Origin of action | ### Clientbound #### Discovey ##### serverAdvertisment Sent via multicast to every device in the local network at a regular interval while the server is in the lobby state. | Field | Type | Explanation | | - | - | - | | address | String | Adress of server | ##### joinResponse: Response to joinRequest Response to the client who requested to join the lobby. | Field | Type | Explanation | | - | - | - | | playerId | int | Unique server assigned player id | ##### serverConfigResponse: Response to serverConfigRequest Response to the client who requested the server config. | Field | Type | Explanation | | - | - | - | | config | Config | Configuration of the server | #### Lobby ##### teamSwitchResponse: Response to teamSwitchRequest Response to the client who requested to switch teams. | Field | Type | Explanation | | - | - | - | ##### setReadyStateResponse: Response to setReadyStateRequest Response to the client who requested a ready state change. | Field | Type | Explanation | | - | - | - | ##### lobbyChangeEvent Sent to every client connected to the lobby to inform them about a change in the members of a team / the ready state of players. | Field | Type | Explanation | | - | - | - | | teams | PlayerLobbyState[2][] | | #### Placement ##### placementPhase Sent to every client who is connected to the lobby when everyone is in the ready state and the team sizes are not violated. | Field | Type | Explanation | | - | - | - | | corner | Coordinate | Coordinate of the bottom left corner | ##### placementResponse: Response to placementRequest Sent to the client who requested to place his ships. | Field | Type | Explanation | | - | - | - | #### Game ##### gameStart Note: This method moves the client from the Placement Phase to the Game Phase Sent to every client connected to the server once every player has sent a valid ship placement. | Field | Type | Explanation | | - | - | - | | state | ServerState | | ##### serverStateResponse: Response to serverStateRequest Sent to the client who requested the state of the game the server has. | Field | Type | Explanation | | - | - | - | | state | ServerState | | ##### shipActionResponse: Response to shipActionRequest Sent to the client who requested one of the ship actions. | Field | Type | Explanation | | - | - | - | ##### nextTurn Sent to every player in the game to indicate that it is now the turn of another player. | Field | Type | Explanation | | - | - | - | | nextPlayerId | int | The id of the next Player | | positionInQueue | int | turns remaining | ##### hitEvent Sent to the team of the player who performed the hit and the team of the player who received the hit. | Field | Type | Explanation | | - | - | - | | coordinate | Coordinate | Coordinate of the hit | | damage | int | Damage dealt | ##### destructionEvent Sent to the team of the player who performed the destructive shot and the team of the player who received the destructive shot. | Field | Type | Explanation | | - | - | - | | coordinate | Coordinate | Coordinate of destructive hit | TODO: Ask if destruction should display whole ship - (shipType) - (position) - (orientation) ##### visionEvent Sent to the players of a team once their collective vision changes. | Field | Type | Explanation | | - | - | - | | isShip | bool | Whether a ship is visible at the coordinate. When a ship gets out of vision, server sends a isShip=false and the client decides whether to draw fog of war or water | | coordinate | Coordinate | Where the vision event occured | ##### shipActionEvent Sent to the team of the player who performed the ship action. | Field | Type | Explanation | | - | - | - | | action | ShipAction | Ship Action | | shipNumber | int | Origin of action | ##### gameOverEvent Sent to every player in the game once a team won or a player left the game. | Field | Type | Explanation | | - | - | - | | reason | GameEndReason | | ## Example P is the current player E is a enemy of P T is a teammate of P S is the server ### Successfull torpedo attack 1. (P -> S) shipActionRequest { action: TORPEDO::({Direction::NORTH}), ship_number: 2 } 2. (S -> P) Response::OK ({ shipActionResponse { } } 3. (S -> P,T) shipActionEvent { action: TORPEDO::({Direction::NORTH}), ship_number: 2 } 4. (S -> P,T,E) hitEvent { coordinate: (21, 16), damage: 400 } 5. (S -> P,T,E) destructionEvent { coordinate: (21, 16) } ### Failed torpedo attack 1. (P -> S) shipActionRequest { action: TORPEDO::({Direction::NORTH}), ship_number: 2 } 2. (S -> P) Response::Error { error_code: 501, error_msg: "Cruiser cant shoot torpedo" } ## Tasks | Tasks | Assigned | - | - | Consider all Request Response Pairs and add Error Codes to the Error table for possible errors| | Explain the Error Mechanism for Responses| | Specify all Client-Bound Discovery Messages in the RFC| | Specify all Client-Bound Lobby Messages in the RFC| | Specify all Client-Bound Placement Messages in the RFC|MG2 | Specify all Client-Bound Game Messages in the RFC | | Specify all Server-Bound Discovery Messages in the RFC| | Specify all Server-Bound Lobby Messages in the RFC| | Specify all Server-Bound Placement Messages in the RFC| | Specify all Server-Bound Game Messages in the RFC | |ServerState, ShipState, ShipType |ShipBalancing, ShipTypeWithBalancing, CommonBalancing, Costs |Config, PlayerLobbyState, Coordinate, ShipAssignment |ScoutBalancing, MultiMissileBalancing, PredatorBalancing, EngineBoostBalancing, TorpedoBalancing |MoveProperties, ShootProperties, RotateProperties, ScoutProperties, MultiMissileProperties, PredatorProperties, EngineBoostProperties, TorpedoProperties |Direction, MoveDirection, RotationDirection, GameEndReason| MG2

    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