Giter Club home page Giter Club logo

intro-to-ai-group-project's Introduction

SA.py

  • global variables

    • INF:隨便定的 infinity,目前設 1e10
    • CORNER, EMPTY, BLACK, WHITE:隨便給數字,增加 code readability 而已
    • WIDTH, HEIGHT:盤面大小,8x8
    • NORTH, NORTHEAST, ..., DIRECTIONS:各種移動方向,第一個與第二個值分別為 row 與 col 的移動方向
  • SearchAgent()

    • attribute
      • PLAYER:agent 的身分(黑棋 or 白棋)
      • MAX_DEPTH:最大搜尋深度
      • DURATION:最大思考時間
      • WEIGHT_PIECE:權重
      • WEIGHT_EDGE:權重
      • WEIGHT_MOVE:權重
      • LIFETIME:now + DURATION
    • method
      • OutOfBoard(pos, direction)
        • 檢查 pos 沿 direction 方向移動一步後是否超出棋盤
      • IsValidMove(board, pos, direction, is_black)
        • 如果把棋子下在 pos,並檢查沿 direction 方向是否能把敵方的棋子 flip
      • GetValidMoves(board, is_black)
        • central 6x6 的位置只要是 EMPTY 就是 valid move
        • 檢查四條邊有沒有 valid move,原本可以用 for-loop 就好,但為了減少搜尋時間所以把所有情況展開個別處理
      • CheckFlip(board, pos, direction, is_black)
        • 檢查目前的 boardpos 為出發點,沿 direction 方向前進,是否有 opponent 的 piece 可以 flip
        • return 是否有東西可 flip, 所有可 flip 的座標
      • PlaceAndFlip(board, pos, is_black)
        • place a piece at pos, then call CheckFlip
      • Evaluate(board, is_black)
        • calculate the score of current board
        • things being taken into account
          • number of pieces on the edge
          • number of available moves
          • number of total pieces
          • 權重比較請見 Note
      • PVS(board, is_black, depth, alpha, beta)

Team_2.py

  • 詳細 code 請參考 reinforcement 與 td_agent_dev 兩個 branch
  • 將訓練好的 weights 用於對局

weight folder

  • 利用 reinforcement learning - TD learning 學習出來的 weights
  • 有四個本版:訓練 10 萬、15 萬、20 萬、25 萬場的 weights
  • .p 檔名開頭的 all_{數字}
    • all_2:使用 2-tuple 訓練
    • all_3:使用 3-tuple 訓練
  • .p 檔名中間的 refcustom
    • ref:參考 paper 所實作的 networks
    • custom:基於 ref 上另外添加一些資訊的 networks
  • .p 檔名末端的 blackwhite
    • black:針對先手的 weights(黑棋先下)
    • white:針對後手的 weights

Note

SA.py 跟助教提供的 AI 對局的結果
對局 100 場
對於相同 score 的 move -> 選擇第一個走訪的

參數 結果
DURATION = 4.98
WEIGHT_PIECE = 1.0
WEIGHT_EDGE = 100.0
WEIGHT_MOVE = 10.0
我方勝場:61
平手:6
我方勝率:61.0%
對方勝率:33.0%
DURATION = 4.98
WEIGHT_PIECE = 0.1
WEIGHT_EDGE = 100.0
WEIGHT_MOVE = 10.0
我方勝場:74
平手:6
我方勝率:74.0%
對方勝率:20.0%
DURATION = 4.98
WEIGHT_PIECE = 10.0
WEIGHT_EDGE = 100.0
WEIGHT_MOVE = 50.0
我方勝場:69
平手:4
我方勝率:69.0%
對方勝率:27.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 50.0
WEIGHT_MOVE = 1.0
我方勝場:54
平手:11
我方勝率:54.0%
對方勝率:35.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 1.0
WEIGHT_MOVE = 50.0
我方勝場:58
平手:8
我方勝率:58.0%
對方勝率:34.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 1.0
WEIGHT_MOVE = 10.0
我方勝場:49
平手:5
我方勝率:49.0%
對方勝率:46.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 10.0
WEIGHT_MOVE = 1.0
我方勝場:60
平手:3
我方勝率:60.0%
對方勝率:37.0%

SA.py 跟助教提供的 AI 對局的結果
對局 100 場
對於相同 score 的 move -> 隨機挑一個
看起來沒有比較好

參數 結果
DURATION = 4.98
WEIGHT_PIECE = 0.1
WEIGHT_EDGE = 100.0
WEIGHT_MOVE = 10.0
我方勝場:57
平手:3
我方勝率:57.0%
對方勝率:40.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 50.0
WEIGHT_MOVE = 1.0
我方勝場:46
平手:8
我方勝率:46.0%
對方勝率:46.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 1.0
WEIGHT_MOVE = 50.0
我方勝場:51
平手:6
我方勝率:51.0%
對方勝率:43.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 1.0
WEIGHT_MOVE = 10.0
我方勝場:55
平手:7
我方勝率:55.0%
對方勝率:38.0%
DURATION = 4.98
WEIGHT_PIECE = 100.0
WEIGHT_EDGE = 10.0
WEIGHT_MOVE = 1.0
我方勝場:47
平手:6
我方勝率:47.0%
對方勝率:47.0%
DURATION = 4.98
WEIGHT_PIECE = 1.0
WEIGHT_EDGE = 100.0
WEIGHT_MOVE = 10.0
我方勝場:49
平手:7
我方勝率:49.0%
對方勝率:44.0%
DURATION = 4.98
WEIGHT_PIECE = 10.0
WEIGHT_EDGE = 100.0
WEIGHT_MOVE = 50.0
我方勝場:54
平手:4
我方勝率:54.0%
對方勝率:42.0%

TODO

  • GetValidMove
  • 想 evaluate function
    • 考慮的東西
      • 四條邊上棋子的數量
      • 棋子總數
      • valid moves 的數量
    • 權重比較請見 Note
    • 權重可能還要修改
    • 想想還有沒有什麼東西可以加入 evaluation function
  • minimax algorithm
  • alpha-beta pruning
  • 有沒有其他加速方式,讓搜尋深度可以加大

intro-to-ai-group-project's People

Contributors

eugene87222 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

intro-to-ai-group-project's Issues

TD learning 缺陷

目前 TD learning function 的 weight 依然會持續長歪
待處理

TD update 公式
s = s + alpha * ( (r + s') - s )
alpha = > learning rate (0~1)
r => reward of next state [-1, 1]
s' => next state
s => before state

Progress

TODO

  • get valid move (PR #3)
  • 想 evaluate function
    • 權重 (commit 3d2a6a3)
      • 四條邊上棋子的數量 * 2.0
      • 棋子總數 * 1.5
      • valid moves 的數量 * 1.8
    • 權重可能還要修改
    • 想想還有沒有什麼東西可以加入 evaluation function
  • minimax algorithm
    • 新增 prototype (commit 0bd4f7a)
    • first version,可以跟 AI 對局了 (commit bc77d36)
  • alpha-beta pruning
    • 新增 prototype (commit 0bd4f7a)
    • first version,可以跟 AI 對局了 (commit bc77d36)
    • 看要不要增搜尋深度,目前是 100

棋子 統計狀況 討論

要針對 pattern 檢查可能有點困難

我目前只隔離在輸贏情況

遊戲過程選擇下棋位置的分佈
image

  1. 黑棋贏
  2. 黑棋輸
  3. 白旗贏
  4. 白旗輸
    概況:
    (a) 白旗完全迴避在綠色位置下棋
    (b) 白旗和黑棋佔邊次數很平均

結束,輸贏時擁有屬於黑白 擁有的 棋子位置分佈
image
同上(1. 黑棋贏
2. 黑棋輸
3. 白旗贏
4. 白旗輸)

概況:
(a) 白旗在贏得局面 經常爭取反轉中間的棋子

td learning 和 searching agent 比較效果

目前上傳的版本 分別是和 all_3_black 對戰 10000場 和 20000 場的訓練的 weight
all_3_10000.p
all_3_20000.p

之前的 td_agent 版本練的效果是勝利不到25%
目前這個版本拿 20000 對抗 下面這個設定的 agent
black = SearchingAgent(True, 4.9 , 2.0, 1.0, 1.5, algo='pvs')
只持白棋 似乎有稍微能對抗一下 (大約50%)

還需要更多測試
all_2_tuple 的版本 也可以練一份看看效果
据 reference 提到的是 all_2_tuple 訓練速度結論來説比 all_3 優一些

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.