alanmoss
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CS50 Nuggets ## Design Spec In this document we reference the REQUIREMENTS.md and focus on the implementation-independent design decisions. Here we focus on the core subset: - User interface - Inputs and outputs - Functional decomposition into modules - Pseudo code (plain English-like language) for logic/algorithmic flow - Major data structures - Testing plan ## User interface As described in the [Requirements Spec](REQUIREMENTS.md), the nugget’s interface with the user is initially through the command line when the user creates the server or connects to the server. Once the game starts, the user interacts with the program with their keyboard. ```server $ ./server map.txt seed ``` ```client $ ./client hostname port [playername] ``` The user also interacts with the game through the client side through stdin. Allowing the player to move about and quit the game. The server has no more user interaction after being called. Check the [Requirements Spec](REQUIREMENTS.md) to see the specific keystrokes available to the client ## Inputs and outputs *Input:* when creating the server, the user must provide the server the map text file. Once the game has started, the user provides input to the program exclusively through keystrokes from the keyboard to stdin. *Output:* the output is the map display updated to player movements and game events updated by the server and pushed out to all of the clients. ## Functional decomposition into modules We anticipate the following modules or functions: #### SERVER MODULE *server* runs the server and parses and receives Messages from Clients, sends relevant visible maps for all players. Handles all the GameLogic and initializes the map. 1. *main*, parses args, Seeds randomness initializes Game, start networkServer(MessageLoop) 2. *initializeGame*, placeGold, make Map #### SERVERCMDS MODULE 1. *movePlayer*, gets a direction and a player and does a move for that player and collects gold, true on all gold collected 2. *joinUser*, adds a player, calls ensureDimensions on player, and places them on the map also can add a user as a spectator if name is NULL 3. *leaveUser*, gets a player and removes them from the game 4. *sendDisplays*, (Static) send visible map (get it via getVisibleMap) and the relevant information that's displayed at the top of the screen. To all players. 5. *endGame*, (Static) disconnect everyone, give them Scoreboards #### CLIENT MODULE *client* sends keystrokes and join msg; Displays the visible map for players and the end game screen 1. *Main* Parses args, connects to the server, Start N Curses, start NetworkPlayer(MessageLoop) #### CLIENTCMDS 1. *Display* Display what the server sends to the client 2. *DisplayHeader* Displays the string on the top of the screen, which provides relevant game information to the client. 3. *DisplayAction* Writes an action message on the viewer given a char* 4. *EnsureDimensions* Called by join server and loops on player until they have the right dimensions 5. *QuitClient* Called if server finishes or player quits, called from server, returns true. Upon receiving a QUIT message the client shall exit curses, print the explanation followed by a newline, and exit. And some helper modules that provide data structures: 1. *gameInfo* Struct holding number of gold piles left, amount of gold left, and a PlayerInfo array also holds the map struct 2. *grid* Struct to hold a map of characters that can be interacted with 2d coordinates to get and set. Has toString and parseFromString 3. *map* Struct to hold BaseGrid and GameState Grid, functions to send display to players, setPlayerPos, Place Gold, and a function to return a visible map from a sight grid 4. *playerInfo* Struct to hold player-specific info such as location (x and y coordinates), gold collected, playerID, and address. 5. *pos2D* Struct wrapper for x and y coordinates, has getX and getY also has Set function 6. *Visibility* Module that provides a function to check if one point is visible from another given a map. 7. *Network* Runs message.h and handles messages and timeouts, parses them and translates them to functions which must be called on the player ## Pseudo code for logic/algorithmic flow ### The server will run as follows: ``` parse the command line, validate parameters, initialize other modules create gameInfo struct initalizes the game start network server get messages - parse them call appropriate functions on server ``` InitializeGame ``` read the map file create two grid for that map create the map struct place gold in map ``` ### ServerCmds will run as follows MovePlayer ``` getplayerpos and cmd/direction if not a sprint use one shortMove if sprint, loop through shortMove until shortMove false send new game state if no more gold endgame return true ``` Helper ShortMove: ``` take move dir find adjacent pos if wall return false if gold add Score to player use TakeOutGold to remove it if another player save playerID setPlayerPos to the pos (map SetPlayerPos) if replaced another player setPlayerPos of other player to old pos (map SetPlayerPos) return true ``` JoinPlayer ``` if player terminal size is not big enough, call JoinFail on client with size needed return early if there is space for another player, Create a new playerInfo struct to insert into the array of players (stored in gameInfo struct) Assign the new player a location on the map and place them there Send all players the updated map else, Send the player a rejection message ``` JoinSpectator ``` if there is a current spectator, Kick them off the server let the new spectator connect send the player a join message messageLoop receives display input from the server if spectator presses “q”, send a quit message to the server and disconnect spectator. ``` LeavePlayer ``` take Player off the map (GameInfo removePlayer) delete corresponding playerInfo send new Game State (Map SendNewGameState) if no more players, endGame return true ``` EndGame ``` construct a scoreboard (GameInfo) send a scoreboard of all the gold collected and other relevant information to the players send a quit message to all of the players close down the server ``` ### The client will run as follows: ``` parse the command line args, validate parameters connect to the server and send it an initialization message start nCurses starts NetworkPlayer (MessageLoop) display what the server sends the client send keystrokes to the server through the handleInput function in MessageLoop try to call JoinPlayer on server quit when the user presses “q” or when a quit message is received from the server ``` ### ClientCmds will run as Follows Display ``` Clear out the old N curses display take a string print it with nCurses use addch(c) and move cursor through the entire display to print each given character ``` DisplayHeader ``` Construct a header message Spectator: for a spectator Player A has p nuggets otherwise Call display action if we received gold print out the decided on header to the top in ncurses ``` DisplayAction ``` Check args get the string move to top right and print the string backwards ``` ensureDimensions ``` Get the dimensions loop until the screen is large enough for it print message asking to fix screen ``` quitClient ``` exit curses with endwin() print the explanation passed in the quit message exit main with zero; ``` ## Major data structures Helper modules provide all the data structures we need: - *gameInfo* holds all the major data structures needed to run the game - *array* playerIDs are the indices, the array stores playerInfo structs - *map* holds the base grid and gamestate grid along with various methods - *grid* base grid: holds the original base map.txt - *grid* gamestate grid: hold the current state of the game - *grid* sight grids: holds what a particular player can see - *playerInfo* struct to hold the information of a single player ## Testing plan For testing, we plan to run the server from a local host as well as remotely, connecting multiple clients to test connection, as well as running the program. A sampling of tests that should be run: - Using the provided “bot mode” to test multiple players at once while running the server - Test erroneous cases - such as using bot mode to connect a number of players over the player count and joining as a spectator once a spectator is already connected. - Test player collisions during gameplay to ensure proper switching - Test tunnels to make sure players can only see one space in front of them - Test connecting from multiple clients remotely to make sure network connections are running as needed - Check error logs to make sure all tests are run correctly → print stderr and stdout to testing.out while running the program - Test multiple map sizes to make sure the program reads in map text files and assembles grid layouts correctly ### Division of work In the interest of efficiency, it makes sense to have each person work on modules of the project that are co-dependent. This allows each individual team member to build knowlege on one section of the project, without needing to know the nitty gritty detailed of every module. It also streamlines the workflow, as each team member is responsible for writing the code that their future code is dependent on, ensuring that we spend little to no time waiting on others to finish modules. When writing the modules, if functionality from one module is requisite for functionality in another, team members are to assume that the functions being borrowed from other modules do exactly as described without fail. This allows for individuals to complete their code in the absence of worrying about functionality on the part of the others, thus enhancing efficiency. General Responsibilities James: Visibility Module & Testing, Server Main, Move, displayHeader, leaveUser, & Server Testing Will: Grid Module & Testing, Map Module & Testing, Various Functions in Player.c, Player EnsureDimensions Spencer: GameInfo Module & Testing, Pos2D module, server endGame, Player Testing Alan: Network Module & Testing, Server join User, server leave User, server endGame, display, display action

    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