cysun
    • 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
    • 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 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
    --- tags: AI robots: noindex, nofollow description: AI program2 --- <!-- 字型 --> <style type="text/css"> #doc { font-family: "Heiti TC", "Microsoft JhengHei", "文泉驛正黑" !important; } </style> <!-- --- --> AI game project 筆記 = ## Code https://github.com/cysun0226/Artifical-Intelligence/tree/master/game-project * main.cpp * chessboard.h * chessboard.cpp * agnet.h * agent.cpp * debug.h * debug.cpp * generate_state.cpp ## 置頂 ### 目前的 code 流程說明 ![](https://imgur.com/GH0Fi0L.png) ### 目前進度 * 會動了ヽ( ・∀・)ノ★*"'*-.,_,.-*'"*-.,_☆,.-*'" * ChessBoard::update_one() * reasonable move * 把 code 塞到一個檔案 (要上傳時再合併) * 報告 #### 前幾天 * 新增 generate_state.cpp,可以用來生測資~ * Agent::readState 改為 bool,回傳是否有新 state * 如果有新 state,才做 ChessBoard::update() * ~~debug.h 被我拆成 debug.h 和 debug.cpp 了~~ * 又改回 debug.h 了,改成 inline * 修好圖形化棋盤程式的 bug (原本第三列的點會沒畫出來) * 盤面連線計算 * 每筆連線記錄包含開始位置、長度、由哪些 block 組成、頭尾開放狀態、所屬勢力 * 每個格子的 neighbor * 每個格子的 x, y, z 位置標記 * 遊戲主程式 * 讀寫檔時會在 command line 寫 log (next position 都先設為 0) ![](https://imgur.com/0yMrCzV.png) ### 注意事項 * state_xx.txt 及 move_xx.txt 的數字代表的是 team number,不是目前步數! * 假設 team 1 和 team 2 比賽,那 judge.exe 會輪流放 state_1.txt 和 state_2.txt。 ## Todo - [x] class 棋盤 - [x] 格子 (array) - [x] 目前盤面上的連線 - [x] update - [x] move = 1 或 2 時做 initialize - [x] 格子 (struct?) - [x] row, column - [x] neighbors (vector?) - [x] state ( = ME, OPPONENT, EMPTY) - [x] 讀寫檔 - [x] gametree 建立 - [x] utility function - [x] (minimax?) * 這個棋盤的 branching factor 約為 216,以 200 算,只要往後 4 步 200^4^ = 1,600,000,000 就已經很大了 * 或者用一些方法省去幫助不大的 node,像只搜尋現有 node 的 neighbor 之類的 - [ ] 查一些五子棋的開局方法 - [x] visualize ~~其實這根本不重要~~ - [ ] ... ## 參考資料 與一般五子棋相比,普通的五子棋一子有八個方向可以延伸,但這種只有六個方向,這點可以思考一下🤔️ ### 五子棋開局 * http://587.renju.org.tw/open.htm * https://www.zhihu.com/question/21026248 ### utility function * http://587.renju.org.tw/teach/teach017.htm # 遊戲規則 ## 獲勝條件 > 下棋方五顆連成一線 ## 違規 > 另一方勝出,遊戲結束 * 下棋方耗時超過規定(5s) * 下棋方下在非法位子 * 不在 0~216 內 * 下在已有棋子的位子 * 寫出的檔格式不合規定 * move_##.txt 格式錯誤 * 改動 state_##.txt ## 棋盤 ![](https://i.imgur.com/fXZTjtT.png) ### array 位置對照 ![](https://i.imgur.com/Iqs2315.png) ### 位置表示 ![](https://imgur.com/FVsepCE.png) 如上圖,棋盤有三個座標軸:X Y Z X, Y 軸皆由左至右。而 Z 軸由上至下。 array[0] = x[8][0] = y[0][0] = z[0][0] array[100] = x[0][0] = y[0][8] = z[8][0] array[108] = x[8][8] = y[8][8] = z[8][8] 之所以需要三個座標軸是為了方便計算棋盤中棋子連線的狀況, 例如最上面 array[2] ~ array[6] 連線,即為 z[0][2] ~ z[0][6] 斜線的 array[20] ~ array[70],則是 y[1][2] ~ y[1][6] ### 範例 \* 號為先手方 ![](https://scontent-tpe1-1.xx.fbcdn.net/v/t35.18174-0/p280x280/30826000_1652429824841540_1599572809_o.png?_nc_cat=0&oh=ce58ef240f96812d22140ff60627a325&oe=5AE3D120) ## input/output file ### state_*.txt (input) 內容為兩行數字: ``` [目前步數] [棋盤 array] ``` 5 0 1 0 2 1 0 0 …… * 第一行為目前要下的步數 * 5 代表目前棋盤上有 4 個子,自己要下第 5 個 * 第二行為棋盤狀態 * 共有 217 個數字,以空白隔開 * 0 為空位子,表示可下,1 為自己下過的位子,2 是對方下過的位置 ### move_*.txt (output) ``` [下第幾步] [位置] ``` 5 17 * 內容為兩個整數,自己下第幾步及下在哪個位子,以空白隔開。 * 自己下第 5 步在編號 17 那格 # 程式執行 ## 比賽 1. 把兩個 AI 程式和 judge.exe 放到同一個資料夾 ( 以 player42.exe 和 dummy.exe 為例 ) 2. 執行 player42.exe 和 dummy.exe 3. 執行 judge.exe ``` ./judge.exe [隊名1] [隊名2] ``` ![](https://i.imgur.com/EbLSgwK.png) 4. 產生兩個 log file,分別為 * game-log-[team1]-[team2].txt * game-log-[team2]-[team1].txt ## 圖形化棋盤 ![](https://i.imgur.com/S4W5UTJ.png) ### 執行方法 > 點這裡下載 [show_chessboard.zip](https://drive.google.com/file/d/1Jl2gz05l3RD_e1VhGNmrVuRYSXX6wVoS/view?usp=sharing) (含程式、背景圖片及一個測試用的 state42.txt ) > [color=lightblue] 1. 把 show_chessboard.exe 和 [棋盤圖片](https://people.cs.nctu.edu.tw/~cysun0226/chessboard.png) 放到同一個資料夾 2. 輸入以下 command ( 可能要等個 5~10 秒 ) ``` ./show_chessboard.exe [state_*.txt] ``` * 或者電腦有裝 python 的話可以直接跑下面那份 code,速度快很多而且檔案也比較小,但可能要用 pip install 用到的 package ./python3 show_chessboard.py [state_*.txt] 3. 在同一資料夾會產生 state_*.png,即為該 state 之棋盤樣子 ![](https://i.imgur.com/UEgTDSQ.png) ### code https://gist.github.com/cysun0226/1f56b10d808893e7af7c6daf1ffb809c #### 棋盤圖片 https://people.cs.nctu.edu.tw/~cysun0226/chessboard.png #### 棋盤背景圖片畫法參考 http://mendezitmg.blogspot.tw/p/programas-con-python.html

    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