一、結對隊友博客-楊歡javascript
二、本做業博客的連接html
三、Github地址前端
楊歡:前端qt界面,以及網絡接口java
梅恆權:後端AI出牌算法python
PSP2.1 | Personal Software Process Stages | 預估耗時(min) | 實際耗時(min) |
---|---|---|---|
Planning | 計劃 | 60 | 60 |
Estimate | 估計這個任務須要多少時間 | 60 | 60 |
Development | 開發 | 1200 | 1500 |
Analysis | 需求分析(包括學習新技術) | 400 | 600 |
Design Spec | 生成設計文檔 | 20 | 10 |
Design Review | 設計複審 | 30 | 60 |
Coding Standard | 代碼規範(爲開發制定合適的規範) | 30 | 40 |
Design | 具體設計 | 400 | 600 |
Coding | 具體編碼 | 1200 | 1500 |
Code Review | 代碼複審 | 60 | 120 |
Test | 測試(自我測試,修改,提交修改) | 60 | 240 |
Reporting | 報告 | 60 | 60 |
Test Report | 測試報告 | 60 | 60 |
Size Measurement | 計算工做量 | 20 | 10 |
Postmortem & Process Improvement Plan | 過後總結並提出過程改進計劃 | 60 | 60 |
Total | 合計 | 3720 | 4980 |
def signIn(self,account):#註冊接口 headers = { "Content-Type": 'application/json', "User-Agent": 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Mobile Safari/537.36' } response = requests.post('http://api.revth.com/auth/register2', json.dumps(account), headers=headers) reData = json.loads(response.text)
def login(self,account): #登錄 # account=self.account headers = { "Content-Type": 'application/json', "User-Agent": 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Mobile Safari/537.36' } response = requests.post('http://api.revth.com/auth/login', json.dumps(account), headers=headers) reData = json.loads(response.text)
def openGame(self,token): headers = { "X-Auth-Token": '', "User-Agent": 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Mobile Safari/537.36' } headers["X-Auth-Token"] = token response = requests.post('http://api.revth.com/game/open', headers=headers) reData=json.loads(response.text)
url = 'http://api.revth.com/rank' re = requests.get(url) self.rank_json = json.loads(re.text)
headers={ "X-Auth-Token":self.token, } data={ "player_id":id, "limit":20, "page":self.page } response=requests.get("http://api.revth.com/history",data=data,headers=headers) self.listData=json.loads(response.text)["data"]
算法使用了回溯搜索,關鍵在於減枝和分數矩陣評分的算法設計linux
關鍵實現部分流程圖以下:git
搜索回溯github
optimize_back() { for (var b1 = 0; b1 < 9; ++b1) { for (var b2 = b1 + 1; b2 < 10; ++b2) { for (var b3 = b2 + 1; b3 < 11; ++b3) { for (var b4 = b3 + 1; b4 < 12; ++b4) { for (var b5 = b4 + 1; b5 < 13; ++b5) { this.back = new WaveEvaluator( [this.hand[b1], this.hand[b2], this.hand[b3], this.hand[b4], this.hand[b5]], Back); if (this.back.pattern == Junk) continue; if (200 + this.back.value < this.threshold) continue; var bits = (1<<b1) + (1<<b2) + (1<<b3) + (1<<b4) + (1<<b5); this.optimize_center(bits); } } } } } } optimize_center(bits) { out: for (var c1 = 0; c1 < 9; ++c1) { if ((1 << c1) & bits) continue; for (var c2 = c1 + 1; c2 < 10; ++c2) { if ((1 << c2) & bits) continue; for (var c3 = c2 + 1; c3 < 11; ++c3) { if ((1 << c3) & bits) continue; for (var c4 = c3 + 1; c4 < 12; ++c4) { if ((1 << c4) & bits) continue; for (var c5 = c4 + 1; c5 < 13; ++c5) { if ((1 << c5) & bits) continue; this.center = new WaveEvaluator( [this.hand[c1], this.hand[c2], this.hand[c3], this.hand[c4], this.hand[c5]], Center); if (this.back.is_smaller_than(this.center)) break out; if (100 + this.center.value + this.back.value < this.threshold) continue; var center_bits = (1<<c1) + (1<<c2) + (1<<c3) + (1<<c4) + (1<<c5); this.optimize_front(bits + center_bits); } } } } } } optimize_front(bits) { out: for (var f1 = 0; f1 < 11; ++f1) { if ((1 << f1) & bits) continue; for (var f2 = f1 + 1; f2 < 12; ++f2) { if ((1 << f2) & bits) continue; for (var f3 = f2 + 1; f3 < 13; ++f3) { if ((1 << f3) & bits) continue; this.front = new WaveEvaluator( [this.hand[f1], this.hand[f2], this.hand[f3]], Front); if (this.center.is_smaller_than(this.front)) break out; var sum_value = expected_points(this.front, this.center, this.back); var duplicate = false; for (var pos = 0; pos < this.top_waves.length; ++pos) { if (sum_value < this.top_waves[pos][0]) break; if (sum_value == this.top_waves[pos][0]) { duplicate = true; break; } } if (duplicate) continue; if (pos == 0 && this.top_waves.length == this.handicap + 1) continue; this.top_waves.splice(pos, 0, [sum_value].concat( this.front.wave, this.center.wave, this.back.wave)); if (this.top_waves.length > this.handicap + 1) this.top_waves.shift(); this.threshold = this.top_waves[0][0]; } } } }
權重矩陣算法
var pattern_points = [ // Tr FH Qu SF RF [1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1], // front [1, 1, 1, 1, 1, 1, 1, 2, 8, 10, 20], // center [1, 1, 1, 1, 1, 1, 1, 1, 4, 5, 10], // back ]; var junk_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 1, 1, 2, 2, 4, 7, 15, 34], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ]; var junk_value0 = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 20, 20, 21, 21, 22, 23, 24, 26, 30, 34, 42, 0], //A? [ 0, 9, 9, 10, 10, 11, 11, 12, 13, 15, 18, 0, 0], //K? [ 0, 5, 5, 5, 6, 6, 7, 7, 8, 8, 0, 0, 0] //Q? ]; var one_pair_value = [ //2 3 4 5 6 7 8 9 T J Q K A [45, 47, 49, 51, 53, 56, 60, 64, 68, 73, 81, 89, 97], [ 2, 3, 3, 4, 5, 6, 8, 10, 12, 15, 18, 24, 33], [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 3] ]; var one_pair_value0 = [ //2 3 4 5 6 7 8 9 T J Q K A [96, 96, 96, 96, 96, 96, 97, 97, 97, 97, 98, 98, 0], //A? [86, 86, 86, 86, 86, 87, 87, 88, 89, 89, 90, 0, 91], //K? [76, 76, 77, 77, 77, 78, 78, 78, 79, 80, 0, 82, 83] //Q? ]; var one_pair_value1 = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 30, 31, 31, 32, 32, 33, 33, 34, 35, 36, 0], //A? [ 0, 0, 23, 23, 23, 23, 23, 24, 25, 25, 26, 0, 27], //K? [ 0, 0, 17, 17, 18, 18, 18, 19, 19, 20, 0, 21, 22] //Q? ]; var two_pair_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 37, 37, 39, 41, 43, 46, 49, 54, 58, 62, 64, 64], [ 0, 3, 3, 4, 4, 5, 7, 8, 10, 11, 13, 14, 14] ]; var continuous_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 37, 37, 39, 41, 43, 46, 49, 54, 58, 62, 64, 64], [ 0, 3, 3, 4, 4, 5, 7, 8, 10, 11, 13, 14, 14] ]; var triple_value = [ //2 3 4 5 6 7 8 9 T J Q K A [99, 99, 99, 99, 99,100,100,100,100,100,100,100,100], [63, 66, 69, 71, 72, 72, 74, 74, 74, 75, 75, 75, 76], [12, 13, 13, 15, 16, 16, 16, 16, 16, 14, 15, 15, 15] ]; var straight_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 77, 79, 81, 83, 85, 87, 88, 89, 91, 92], [ 0, 0, 0, 16, 18, 20, 22, 24, 26, 28, 31, 34, 37] ]; var flush_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [ 0, 0, 0, 0, 0, 93, 92, 92, 93, 94, 95, 97, 98], [ 0, 0, 0, 0, 0, 35, 37, 38, 38, 40, 44, 50, 61] ]; var flush_value2 = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 53, 54, 55, 56, 57, 59, 62, 65, 0], //A? [ 0, 0, 0, 44, 44, 45, 46, 47, 48, 49, 52, 0, 0], //K? [ 0, 0, 0, 41, 41, 41, 42, 42, 44, 45, 0, 0, 0] //Q? ]; var full_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [98, 99, 99, 99, 99, 99, 99, 99,100,100,100,100,100], [65, 66, 69, 71, 73, 75, 78, 80, 82, 85, 88, 91, 94], ]; var quadruple_value = [ //2 3 4 5 6 7 8 9 T J Q K A [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [100,100,100,100,100,100,100,100,100,100,100,100,100], [ 94, 94, 95, 95, 95, 96, 97, 97, 97, 97, 98, 98, 98] ];
改進的時候就是看時間是否知足調節,經過算法的優化減少時間的耗費。編程
從暴搜到簡單搜索到牌型貪心組合。枚舉13張牌可能組成的牌型,從單張(junks)到順子(straights),每種牌型從大到小排序,再從中枚舉組合出後中前墩的可能出牌模式,最後枚舉判斷是否合法便可。
可見CPU運行達到峯值,在出牌的AI算法上
由以上可知,因爲是回溯搜索,因此時間主要在三墩牌的組合上。
function test(arr) { for (var i = 0; i < arr.length; ++i ) { var mypos = Math.floor(Math.random() * (arr.length - i)); var item = arr[mypos]; arr[mypos] = array[arr.length - 1 - i]; arr[arr.length - 1 - i] = item; } return arr; } console.time("running time"); for (var i =0 ; i<=1000 ;++i ) { tmp=optimize_hand(test([...Array(52).keys()])); } console.timeEnd("running time");
隨機測試出牌狀況,輸出運行時間。
隨機數據生成,保證算法的魯棒性,隨機生成出1000次牌局,儘量爭取達到各類各樣的牌型與決策。
問題描述
結對沒有儘早開始寫代碼,拖延得比較後面。每週都在deadline各類趕(linux,實驗,比賽等等)
作過哪些嘗試
意識到來不及了,就趕快寫了,連續熬夜一兩天戰鬥了
是否解決
已解決
有何收穫
隊友是一個好隊友。
在deadline前效率是最高,但過了以後,真的很傷身體
值得學習的地方
強者風範,不緊不滿,成竹在胸
須要改進的地方
好像沒有什麼須要改進的,總的來講,感謝個人隊友,考慮到個人各類緣由,包攬
了大部分的工做。平心而論,若是此次是我的做業,我可能就完成不了了,或者說只會作出一個很是難受的UI界面。
第N周 | 新增代碼(行) | 累計代碼(行) | 本週學習耗時(小時) | 累計學習耗時(小時) | 重要成長 |
---|---|---|---|---|---|
1 | 0 | 0 | 10 | 10 | 學會markdown寫博客 |
2 | 500 | 500 | 26 | 36 | 學會json格式使用 使用request庫調用API |
3 | 0 | 0 | 21 | 57 | 使用Axure進行原型設計 設計出征戰十三水原型 |
4 | 600 | 1100 | 16 | 73 | 使用Pyqt進行UI設計 設計出征戰十三水UI |
… | … | … | … | … | … |