Pierre
    • 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
    # 程式設計專題 ## 提問區 > 所以道路跟村莊要怎麼存,要找時間討論一下嗎 > > 另外我有個想法:有要15~17找一天掛線上做專題嗎?邊做邊討論之類的 > (到14號前,我可能......能碰的時間有限,14號之後才可能完全動起來) > > 又另一個想法:什麼時候要進入試玩階段 > 最晚或許17號就該定案+調整,18號(截止日)寫報告 > [name=何躍陽] ## 地圖板塊 麥田x4、森林x4、草原x4、山脈x3、丘陵x3、沙漠x1 | 編號 | 板塊 | 數量 | 生產資源 | |:----:|:----:|:----:|:--------:| | 0 | 沙漠 | 1 | N/A | | 1 | 麥田 | 4 | 小麥 grain | | 2 | 森林 | 4 | 木頭 lumber | | 3 | 草原 | 4 | 羊毛 wool | | 4 | 山脈 | 3 | 石頭 ore | | 5 | 丘陵 | 3 | 磚頭 brick | ### 數字指示物 共 18 個,2與12各一個,3-6, 8-11各兩個。 ### 板塊位置 由左至右,由上至下,共19塊 ### 板塊 struct 設計 | 型別 | 變數名稱 | 中文解釋 | 值 | 解釋 | |:----:|:--------:|:----------:|:------------:|:------------------:| | int | type | 板塊類型 | 0-5 | | | int | point | 骰子點數 | 0, 2-6, 8-12 | | | int | robber | 是否有盜賊 | 0,1 | | ## 需要那些結構 - 板塊 - 玩家 :::spoiler::: ```c= enum {WHEAT = 1, WOOD, WOOL, STONE, BRICK}; struct _player { int32_t id; // 可能不會用,應該會用player[3]的array處理 int32_t resource[6]; // not show to other players int32_t total_resource; //show to other players int32_t Is_use_develop_card; // one round use once int32_t NPC_difficulty; // user are 0, only for NPC }__attribute__ ((__packed__)); typedef struct _player Player; ``` ::: - 道路 - 村莊 - 系統 :::spoiler::: ```c= const int32_t WIN_SCORE = 10; struct _system { int32_t player_num; // 3 or 4 int32_t knight_card; // at most 14 int32_t score_card; // at most 5 size_t bank_resource[6]; // all: 19, 19, 19, 19, 19. Can't be zero. int32_t longest_road; // num of longest road in total players int32_t lr_player; // the player_id who has longest road card int32_t max_knight; // num of max knight card in total players int32_t mk_player; // the player_id who has max_num knight cards int32_t player_score[4]; }__attribute__ ((__packed__)); typedef struct _system System; ``` ::: ### 工作分配 - 陽:計分、電腦、地圖呈現, etc - 蔡:板塊結構設計 - 江:遊戲機制、流程設計 :::spoiler **map** ```c= #include <stdio.h> #include <stdint.h> #define MAP_WIDTH 5 #define MAP_HEIGHT 4 ////////////////// enum {DESERT, WHEAT_FIELD, FOREST, GRASSLAND, MOUNT, HILLS}; ////////////////// typedef struct { int type; // 板塊類型(0~5) int point; // 骰子點數(0, 2~6, 8~12) int robber; // 是否有盜賊(0:無,1:有) } Tile; Tile gameMap[MAP_HEIGHT][MAP_WIDTH]; // 地圖板塊陣列 void initializeMap() { // 初始化地圖 // 麥田板塊 x4 gameMap[0][0].type = 1; // 麥田 gameMap[0][0].point = 5; gameMap[0][0].robber = 0; gameMap[0][1].type = 1; // 麥田 gameMap[0][1].point = 2; gameMap[0][1].robber = 0; gameMap[0][2].type = 1; // 麥田 gameMap[0][2].point = 10; gameMap[0][2].robber = 0; gameMap[0][3].type = 1; // 麥田 gameMap[0][3].point = 9; gameMap[0][3].robber = 0; // 森林板塊 x4 gameMap[1][0].type = 2; // 森林 gameMap[1][0].point = 4; gameMap[1][0].robber = 0; gameMap[1][1].type = 2; // 森林 gameMap[1][1].point = 11; gameMap[1][1].robber = 0; gameMap[1][2].type = 2; // 森林 gameMap[1][2].point = 3; gameMap[1][2].robber = 0; gameMap[1][3].type = 2; // 森林 gameMap[1][3].point = 6; gameMap[1][3].robber = 0; // 草原板塊 x4 gameMap[2][0].type = 3; // 草原 gameMap[2][0].point = 8; gameMap[2][0].robber = 0; gameMap[2][1].type = 3; // 草原 gameMap[2][1].point = 10; gameMap[2][1].robber = 0; gameMap[2][2].type = 3; // 草原 gameMap[2][2].point = 9; gameMap[2][2].robber = 0; gameMap[2][3].type = 3; // 草原 gameMap[2][3].point = 12; gameMap[2][3].robber = 0; // 山脈板塊 x3 gameMap[3][0].type = 4; // 山脈 gameMap[3][0].point = 11; gameMap[3][0].robber = 0; gameMap[3][1].type = 4; // 山脈 gameMap[3][1].point = 4; gameMap[3][1].robber = 0; gameMap[3][2].type = 4; // 山脈 gameMap[3][2].point = 6; gameMap[3][2].robber = 0; // 丘陵板塊 x3 gameMap[4][0].type = 5; // 丘陵 gameMap[4][0].point = 3; gameMap[4][0].robber = 0; gameMap[4][1].type = 5; // 丘陵 gameMap[4][1].point = 8; gameMap[4][1].robber = 0; gameMap[4][2].type = 5; // 丘陵 gameMap[4][2].point = 5; gameMap[4][2].robber = 0; // 沙漠板塊 gameMap[5][0].type = 0; // 沙漠 gameMap[5][0].point = 0; gameMap[5][0].robber = 0; } void printMap() { char place[19][15] = { "山脈", "麥田", "麥田", "山脈", "森林", "山脈", "草原", "麥田", "丘陵", "森林", "沙漠", "草原", "丘陵", "草原", "丘陵", "麥田", "森林", "森林", "草原"}; char num [56][3] = {0}; for(int32_t i = 0; i < 56; i++){ num[i][0] = (char)( (i+1)/10 + '0'); num[i][1] = (char)( (i+1)%10 + '0'); } printf(" \n"); printf(" \n"); printf(" 2:1 %s----%s 2:1 \n", num[0], num[1]); printf(" / \\ / \\ / \\ \n"); printf(" %s----%s %s %s----%s \n", num[2], num[3], place[0], num[4], num[5]); printf(" / \\ / \\ \n"); printf(" 3:1 --%s----%s %s %s----%s %s %s----%s-- 3:1 \n", num[6], num[7], place[1], num[8], num[9], place[2], num[10], num[11]); printf(" \\ / \\ / \\ / \\ / \n"); printf(" %s %s %s----%s %s %s----%s %s %s \n", num[12], place[3], num[13], num[14], place[4], num[15], num[16], place[5], num[17]); printf(" \\ / \\ / \\ / \n"); printf(" %s----%s %s %s----%s %s %s----%s \n", num[19], num[20], place[6], num[21], num[22], place[7], num[23], num[24]); printf(" / \\ / \\ / \\ \n"); printf(" %s %s %s----%s %s %s----%s %s %s \n", num[25], place[8], num[26], num[27], place[9], num[28], num[29], place[10], num[30]); printf(" \\ / \\ / \\ / \\ \n"); printf(" %s----%s %s %s----%s %s %s----%s-- 2:1 \n", num[31], num[32], place[11], num[33], num[34], place[12], num[35], num[36]); printf(" / \\ / \\ / \\ \n"); printf(" %s %s %s----%s %s %s----%s %s %s \n", num[37], place[13], num[38], num[39], place[14], num[40], num[41], place[15], num[42]); printf(" / \\ / \\ / \\ / \n"); printf(" 2:1 --%s----%s %s %s----%s %s %s----%s \n", num[43], num[44], place[16], num[45], num[46], place[17], num[48], num[49]); printf(" / \\ / \\ / \\ \n"); printf(" 2:1 --%s----%s %s %s----%s-- 3:1 \n", num[50], num[51], place[18], num[52], num[53]); printf(" \\ / \n"); printf(" %s----%s \n", num[54], num[55]); printf(" \\ / \n"); printf(" 3:1 \n"); printf(" \n"); } int main() { initializeMap(); printMap(); return 0; } ::: :::spoiler **print_map** ```c= #include <stdio.h> void print_map(char place[18][15], char num[56][3]){ printf(" \n"); printf(" \n"); printf(" 2:1 %s----%s 2:1 \n", num[0], num[1]); printf(" / \\ / \\ / \\ \n"); printf(" %s----%s %s %s----%s \n", num[2], num[3], place[0], num[4], num[5]); printf(" / \\ / \\ \n"); printf(" 3:1 --%s----%s %s %s----%s %s %s----%s-- 3:1 \n", num[6], num[7], place[1], num[8], num[9], place[2], num[10], num[11]); printf(" \\ / \\ / \\ / \\ / \n"); printf(" %s %s %s----%s %s %s----%s %s %s \n", num[12], place[3], num[13], num[14], place[4], num[15], num[16], place[5], num[17]); printf(" \\ / \\ / \\ / \n"); printf(" %s----%s %s %s----%s %s %s----%s \n", num[19], num[20], place[6], num[21], num[22], place[7], num[23], num[24]); printf(" / \\ / \\ / \\ \n"); printf(" %s %s %s----%s %s %s----%s %s %s \n", num[25], place[8], num[26], num[27], place[9], num[28], num[29], place[10], num[30]); printf(" \\ / \\ / \\ / \\ \n"); printf(" %s----%s %s %s----%s %s %s----%s-- 2:1 \n", num[31], num[32], place[11], num[33], num[34], place[12], num[35], num[36]); printf(" / \\ / \\ / \\ \n"); printf(" %s %s %s----%s %s %s----%s %s %s \n", num[37], place[13], num[38], num[39], place[14], num[40], num[41], place[15], num[42]); printf(" / \\ / \\ / \\ / \n"); printf(" 2:1 --%s----%s %s %s----%s %s %s----%s \n", num[43], num[44], place[16], num[45], num[46], place[17], num[48], num[49]); printf(" / \\ / \\ / \\ \n"); printf(" 2:1 --%s----%s %s %s----%s-- 3:1 \n", num[50], num[51], place[18], num[52], num[53]); printf(" \\ / \n"); printf(" %s----%s \n", num[54], num[55]); printf(" \\ / \n"); printf(" 3:1 \n"); printf(" \n"); } int main(){ char place[19][15] = { "山脈", "麥田", "麥田", "山脈", "森林", "山脈", "草原", "麥田", "丘陵", "森林", "沙漠", "草原", "丘陵", "草原", "丘陵", "麥田", "森林", "森林", "草原"}; char num [56][3] = {0}; for(int32_t i = 0; i < 56; i++){ num[i][0] = (char)( (i+1)/10 + '0'); num[i][1] = (char)( (i+1)%10 + '0'); } print_map(place, num); return 0; } ``` ![](https://hackmd.io/_uploads/Hknrjz5Ph.png) ::: ## 遊戲流程 ### 回合流程 ```c= int game_state; // 0: 遊戲準備 // 1: 收成階段 // 2: 交易階段 // 3: 建築階段 // 4: 強盜(收成階段擲到七點時) int current_player; // 0 - 3 (玩家為0,其他為電腦玩家) ``` ## 參考資料 [遊戲規則](https://andyventure.com/boardgame-catan/) [遊戲規則-瘋桌遊](https://phantasiatw.pixnet.net/blog/post/117197942-%E5%8D%A1%E5%9D%A6%E5%B3%B6%E5%9F%BA%E6%9C%AC%E7%89%88-%E8%A6%8F%E5%89%87%2B%E5%BF%83%E5%BE%97) ## 板塊的structure ![](https://hackmd.io/_uploads/HJauC5aI2.png) 對應遊戲規則 * 板塊類型應是對應到這六種內陸板塊 ![](https://hackmd.io/_uploads/Byp9Ac6L3.png) * 骰子點數,則是對應到板塊上放置的數字指示物 ![](https://hackmd.io/_uploads/SJxpRqp8h.png) * 最後沙漠是沒有數字指示物,但會有盜賊 ![](https://hackmd.io/_uploads/HyOwkopI2.png) 板塊這樣宣告 ```c enum ResourceType { // 宣告六種版塊類型 Wheat = 0, Wood, Grassland, Mountain, Hill, Desert }; struct CatanTile { // 定義每個版塊內容 enum ResourceType resourceType; //類型 int number; // 分配到的數字指示物 int hasRobber; // 是否有盜賊 }; // 麥田x4、森林x4、草原x4、山脈x3、丘陵x3、沙漠x1 #define NUM_TILES 19 // 板塊的總數量 ``` 接下來我寫了一段可以隨機產生放置板塊順序的程式碼 ```c int main() { struct CatanTile tiles[NUM_TILES]; generateCatanTiles(tiles); printCatanTiles(tiles); return 0; } ``` ```c // 產生板塊 void generateCatanTiles(struct CatanTile* tiles) { // 內陸板塊有6種場地:麥田x4、森林x4、草原x4、山脈x3、丘陵x3、沙漠x1。 enum ResourceType resources[NUM_TILES] = { Wheat, Wheat, Wheat, Wheat, Wood, Wood, Wood, Wood, Grassland, Grassland, Grassland, Grassland, Mountain, Mountain, Mountain, Hill, Hill, Hill, Desert }; int numbers[NUM_TILES] = { 2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12 }; int remaining = NUM_TILES; shuffleResource(resources, NUM_TILES); // 將resource洗牌 shuffleNumbers(numbers, NUM_TILES - 1); // 將數字指示物洗牌 int numberIdx = 0; for (int resourceIdx = 0; resourceIdx < NUM_TILES; resourceIdx++) { tiles[resourceIdx].resourceType = resources[resourceIdx]; if (tiles[resourceIdx].resourceType == Desert) { // 是沙漠的話,不放數字,放盜賊 tiles[resourceIdx].hasRobber = 1; tiles[resourceIdx].number = 0; } else { // 不是沙漠的話,放數字,不放盜賊 tiles[resourceIdx].hasRobber = 0; tiles[resourceIdx].number = numbers[numberIdx]; numberIdx++; } } } ``` ![數字指示物](https://hackmd.io/_uploads/H1zMGsaI2.png) ```c // 測試函式:列印Catan板塊的資源類型和點數 void printCatanTiles(struct CatanTile* tiles) { int i; for (i = 0; i < NUM_TILES; i++) { printf("板塊 %d - 資源: ", i + 1); switch (tiles[i].resourceType) { case Wheat: printf("麥田"); break; case Wood: printf("森林"); break; case Grassland: printf("草原"); break; case Mountain: printf("山脈"); break; case Hill: printf("丘陵"); break; case Desert: printf("沙漠"); break; default: printf("%d", tiles[i].resourceType); break; } printf(", 數字: %d", tiles[i].number); if (tiles[i].hasRobber == 1) { printf(", 有盜賊"); } printf("\n"); } } ``` 下面是二個洗牌函式 ```c void shuffleResource(enum ResourceType* array, int length) { srand(time(NULL)); for (int i = length - 1; i > 0; --i) { int j = rand() % (i + 1); enum ResourceType temp = array[i]; array[i] = array[j]; array[j] = temp; } } void shuffleNumbers(int* array, int length) { srand(time(NULL)); for (int i = length - 1; i > 0; --i) { int j = rand() % (i + 1); int temp = array[i]; array[i] = array[j]; array[j] = temp; } } ``` yangming3.14159@gmail.com ryan6658@gmail.com - 玩家的開局的村莊選擇 - 村莊建立判定 - 電腦玩家的交易 - 何 - 印出資訊 - 何 - 道路 - 玩家有那裡道路 road[15][2] = { {1, 2}, .... } - 最長道路的計算 - (就是如果路徑中有其他玩家的村莊或城市,路徑會被切斷)這邊還沒判斷成功 - 遊戲流程(續) - 江 - ~~港口交易~~ (完成) - ~~資源發放~~ (完成) - 道路建設 - ~~搶奪資源~~ (完成) 17晚上完成 18號中午結束測試

    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