• 大小: 44KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-09
  • 语言: Python
  • 标签: 麻将  AI  

资源简介

国际麻将AI-根据向听数计算最优操作,用python写的。适合做棋牌的人参考。

资源截图

代码片段和文件信息

#-*- coding: utf-8 -*- 
from BasicDefinition import CardIndex
import mahjong
class Agent :
   

    def __init__(selfplayer_number):
        self.playerNumber = player_number
        self.reset()

    def reset(self):    
        self.handcard = None
        self.cardsOnBoard = [[][][][]]
        self.cardsThrowed = [[][][][]]
        self.cardsThrowedNoTaken = []
        self.cardOpened = []
        self.wind =None

    def setAction(selfaction):
        self.action = action
    
    def goalTest(self):
        s1 = []    #distinguish 4 color
        s2 = []
        s3 = []
        s4 = []
        self.handcard.sort()
        combination = []
        for card in self.handcard:
            if 1 <= card <= 9:
                s1.append(card)
            elif 11 <= card <=19:
                s2.append(card)
            elif 21 <= card <= 29:
                s3.append(card)
            else:
                s4.append(card)
        s = [s1s2s3]  
        twoPair = 0
        while len(s4) != 0:
            count = s4.count(s4[0])
            if count == 3:
                combination.append([s4[0]]*3)
                s4 = s4[3:]
            elif count == 2:
                if twoPair == 0:
                    twoPair += 1
                    combination.append([s4[0]]*2)
                    s4 = s4[2:]
                else:
                    return FalseNone
            else:
                return FalseNone
                
        for color in s:
            if len(color) != 0:
                ## 整除
                if len(color) % 3 == 0:
                    while len(color) != 0:
                        first = color[0]
                        ## 檢查碰
                        if color[1] == first:
                            if color[2] == first:
                                color = color[3:]
                                combination.append([first]*3)
                            else:
                                return FalseNone
                        ## 檢查順子
                        elif color[1] == first + 1:
                            if first + 2 in color:
                                color.remove(first + 2)
                                color = color[2:]
                                combination.append([firstfirst+1first+2])
                            else:
                                return FalseNone
                        else:
                            return FalseNone
                ## 可能有pair
                elif len(color) % 3 == 2:
                    if twoPair != 0:
                        return FalseNone
                    else:
                        i = 0
                        correct1 = False
                        while i < len(color):
                            count = color.count(color[i])
                            ## 某類牌有2 3 4張在手上
                            if count > 1:
                                temp = color[:]
                                tempCombination = [[temp

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-03 17:11  MahjongAI\
     文件        1059  2017-01-17 02:20  MahjongAI\.gitignore
     文件       12513  2017-01-17 02:20  MahjongAI\Agent.py
     文件        1893  2017-01-17 02:20  MahjongAI\BasicDefinition.py
     文件        5862  2017-01-17 02:20  MahjongAI\Counter.py
     文件       21646  2017-01-17 02:20  MahjongAI\evalScore.py
     文件       23740  2017-01-17 02:20  MahjongAI\learningAgent.py
     文件       40084  2017-07-06 11:10  MahjongAI\mahjong.py
     文件        1694  2017-01-17 02:20  MahjongAI\main.py
     文件        1801  2017-01-17 02:20  MahjongAI\README.md
     文件        6074  2017-01-17 02:20  MahjongAI\scoreRules
     文件        2243  2017-06-29 12:16  MahjongAI\SimpleAction.py
     文件       17689  2017-01-17 02:20  MahjongAI\SimpleAgent.py
     文件       15152  2017-01-17 02:20  MahjongAI\Table.py
     文件        8620  2017-01-17 02:20  MahjongAI\train_main.py
     文件        6341  2017-01-17 02:20  MahjongAI\util.py

评论

共有 条评论