【 摸索PP88廿一點 lihkg:匿名討論區的利與弊】

Table Of Content

c語言關於PP8821點遊戲人機對戰人人對戰設計及原始碼12


CAI21 ::~CAI21( void )

//函數做用:判斷玩家能可應該拿牌的決策函數

//輸入參數:id—玩家ID(0或1),cards—洗孬的52張牌數組,roundCards—兩玩家回合存牌數組,roundCardCnts—兩玩家回合存牌計數器數組,topIndex—牌數組中當前面上的牌序號

//函數説明:本函數被機械人拿牌函數RobotTakeCard所調用,RobotTakeCard大體上是與人類拿牌函數TakeCard差未幾的,而重要的焦點差別就是對本函數的調用取代了玩家1的TakeCard

bool CAI21 ::IfTakeCard( int id , char cards [52], char roundCards [2][5], int roundCardCnts [2], int topIndex )

//請在以下分段注釋下空缺處填寫相應的實現代碼

//1、清除必須拿和必須不拿的情況

if ( topIndex == 52)

return false ;

else

int cai = this ->CalcuPoint( roundCards [0], roundCardCnts [0]);

int gou = this ->CalcuPoint( roundCards [1], roundCardCnts [1]);

//假如自己已經爆了或者正孬拿到21點滿分,或者對方已經爆了,則必定不再拿牌,返回false

if ((cai >\= 21)