Try   HackMD

重力四子棋 課程組

(此遊戲由7個columm 6個row組成,我們可以任選一個column丟棋子下去)

所需閱讀

課程(code)

1.https://www.youtube.com/watch?v=XpYz-q1lxu8
2.https://www.youtube.com/watch?v=8392NJjj8s0&t=31s

演算法資料

影片

1.https://www.youtube.com/watch?v=l-hh51ncgDI&t=106s

PSEUODOCODE (看一眼維基百科的pseuodocode即可)

1.https://zh.wikipedia.org/wiki/极小化极大算法
2.https://zh.wikipedia.org/wiki/Alpha-beta剪枝

程式碼所需零件

基礎語法

1.迴圈 雙層迴圈
2.numpy np.zeros(), np.flip()
3.random random.choice(),random.randint()

副函式 (ai元件)

1.pick_best_move(board, AI_PIECE) # return the best column
2.get_valid_locations(board) # get the columns that can fill
3.is_valid_location(board, col) # return whether is valid to fill the column
4.get_next_open_row(board, col) # return the to fill
基本上會先丟其中一個column下去棋子,然後分析他的分數
5.drop_piece(temp_board, row, col, piece)(假裝我們已經下了這步棋,將下過的結果教給(6)function)
6.evaluatewindow()判斷此步權重
7.score_position(temp_board, piece) # 回傳下這一步棋的分數(越高分越應該下)

副函式 勝利條件

1.判斷直線
2.判斷橫線
3.判斷斜率為1
4.判斷斜率為-1

課程大綱

迴圈

1.從小一點的二維陣列開始介紹 ex 3x2

numpy, random module 直接講

順序

一、完成connect4.py (1HR)

1.雙層迴圈 ,:在List中使用, 函式
2.勝利條件
3.pygame包 複製貼上

程式碼: https://gist.github.com/Hacker-Davinci/7f19f2bca8902ca99c14389373120cb0#file-connect4-py

二、完成connect4_ai.py (1.5HR)

1.照副函式AI原件一個一個教

程式碼: https://gist.github.com/Hacker-Davinci/221f6928be54f2bd6ac55bccd229788c#file-connect4_ai_without_minmax_algorithm-py

三、辦32強比賽讓大家玩,可挑戰AI,關主(互打環節)(0.5HR)

四、教MINIMAX ALGORITHM大致上概念(發現有多的時間再教)

程式碼: https://gist.github.com/Hacker-Davinci/f34910db6a4ff85c7fb25740b43cadf8#file-connect4_minimax_algorithm-py