精华内容
下载资源
问答
  • 国际象棋棋手 国际象棋人工智能
  • Chess.ai.js Chess.ai.js是专为下棋而设计的AI。 它使用minmax和Alphabeta算法,可以很容易地进行调整以玩其他游戏(例如,跳棋)...缺少国际象棋游戏元素(铸造,典当促销等) 更复杂的游戏状态度量 实施其他AI算法
  • 【实例简介】中国象棋代码,参考象眼,AI算法相当给力【实例截图】【核心代码】chineseChess└── chineseChess├── AndroidManifest.xml├── assets│ └── BOOK.DAT├── bin│ ├── AndroidManifest....

    【实例简介】

    中国象棋代码,参考象眼,AI算法相当给力

    【实例截图】

    【核心代码】

    chineseChess

    └── chineseChess

    ├── AndroidManifest.xml

    ├── assets

    │   └── BOOK.DAT

    ├── bin

    │   ├── AndroidManifest.xml

    │   ├── chineseChess.apk

    │   ├── classes

    │   │   └── com

    │   │   └── jameschen

    │   │   └── game

    │   │   ├── chess

    │   │   │   ├── BuildConfig.class

    │   │   │   ├── ChessGame.class

    │   │   │   ├── ChessView$1.class

    │   │   │   ├── ChessView.class

    │   │   │   ├── HashItem.class

    │   │   │   ├── Position.class

    │   │   │   ├── R$attr.class

    │   │   │   ├── R$drawable.class

    │   │   │   ├── R$raw.class

    │   │   │   ├── R$string.class

    │   │   │   ├── R$style.class

    │   │   │   ├── R.class

    │   │   │   ├── Search$SortItem.class

    │   │   │   └── Search.class

    │   │   └── util

    │   │   ├── Util$RC4.class

    │   │   └── Util.class

    │   ├── classes.dex

    │   ├── dexedLibs

    │   │   └── annotations-5f9797a0f6c289478ae75f380ca39632.jar

    │   ├── jarlist.cache

    │   ├── res

    │   │   ├── drawable-hdpi

    │   │   │   └── ic_launcher.png

    │   │   ├── drawable-ldpi

    │   │   │   └── ic_launcher.png

    │   │   ├── drawable-mdpi

    │   │   │   ├── background.png

    │   │   │   ├── ba.png

    │   │   │   ├── bb.png

    │   │   │   ├── bc.png

    │   │   │   ├── bk.png

    │   │   │   ├── bn.png

    │   │   │   ├── board.png

    │   │   │   ├── bp.png

    │   │   │   ├── br.png

    │   │   │   ├── cursor2.png

    │   │   │   ├── cursor.png

    │   │   │   ├── ic_launcher.png

    │   │   │   ├── ra.png

    │   │   │   ├── rb.png

    │   │   │   ├── rc.png

    │   │   │   ├── rk.png

    │   │   │   ├── rn.png

    │   │   │   ├── rp.png

    │   │   │   ├── rr.png

    │   │   │   ├── selected2.png

    │   │   │   ├── selected.png

    │   │   │   └── xqwlight.png

    │   │   └── drawable-xhdpi

    │   │   └── ic_launcher.png

    │   └── resources.ap_

    ├── gen

    │   └── com

    │   └── jameschen

    │   └── game

    │   └── chess

    │   ├── BuildConfig.java

    │   └── R.java

    ├── proguard-project.txt

    ├── project.properties

    ├── res

    │   ├── drawable

    │   │   ├── filled_box.xml

    │   │   └── hole_btn_color.xml

    │   ├── drawable-hdpi

    │   │   └── ic_launcher.png

    │   ├── drawable-ldpi

    │   │   └── ic_launcher.png

    │   ├── drawable-mdpi

    │   │   ├── background.png

    │   │   ├── ba.png

    │   │   ├── bb.png

    │   │   ├── bc.png

    │   │   ├── bk.png

    │   │   ├── bn.png

    │   │   ├── board.png

    │   │   ├── bp.png

    │   │   ├── br.png

    │   │   ├── cursor2.png

    │   │   ├── cursor.png

    │   │   ├── ic_launcher.png

    │   │   ├── ra.png

    │   │   ├── rb.png

    │   │   ├── rc.png

    │   │   ├── rk.png

    │   │   ├── rn.png

    │   │   ├── rp.png

    │   │   ├── rr.png

    │   │   ├── selected2.png

    │   │   ├── selected.png

    │   │   └── xqwlight.png

    │   ├── drawable-xhdpi

    │   │   └── ic_launcher.png

    │   ├── raw

    │   │   ├── game_bg.wav

    │   │   ├── hit_right.wav

    │   │   └── menu.ogg

    │   └── values

    │   ├── strings.xml

    │   └── style.xml

    └── src

    └── com

    └── jameschen

    └── game

    ├── chess

    │   ├── ChessGame.java

    │   ├── ChessView.java

    │   ├── Position.java

    │   └── Search.java

    └── util

    └── Util.java

    34 directories, 90 files

    展开全文
  • 中国象棋源码

    2013-07-03 16:16:46
    一个用Win32 API 实现的中国象棋游戏,实合中级选手对局。
  • 国际象棋引擎和简单的国际象棋用户界面
  • java中国象棋源码

    2019-07-05 16:44:47
    java中国象棋源代码,主要实现棋子行走部分,AI部分目前算法能力比较弱,希望有算法爱好者共同讨论交流
  • Java中国象棋源码程序

    2018-05-04 23:43:12
    Java中国象棋源码程序,作者将AI算法用得淋漓尽致,具有很高的学习研究价值。
  • xai:象棋ai-源码

    2021-03-29 09:51:29
    中国象棋AI 语言 C ++ python 3.9.2 环境 WSL2 工具 Visual Studio程式码 微软vcpkg 麦克马 谷歌测试
  • Node CChess 中国象棋AI算法,node版 大部分核心代码来自 如何使用,看例子 test.js ,很简单
  • 中国象棋源码,所有源文件,资源。 学习人工智能的好材料
  • VC版中国象棋源码智商比较高 人工智能入门 值得收藏
  • 人工智能的国际象棋 用于激活 1)安装此应用程序2)从deepfishai.com安装weights文件3)在任何gui中安装它或运行lichess-bot 怎么玩 如果您不想下载,可以使用巫妖机器人-@ chessrobotofficial,@ deepfishai,@ ...
  • 中国象棋AI源码.zip

    2021-03-12 20:08:22
    资源介绍 这是一款html5小游戏,主要功能在于js,带一套皮肤、内置ai算法,有能力的可以自行修改。
  • 国际象棋 深度学习国际象棋AI 国际象棋AI正在开发中,我的YouTube频道“ ZweiTinte”上有更新
  • 中国象棋源码,基于王小春《PC游戏编成--人机对弈》 版权归原作者所有 。
  • 本项目是一个基于安卓的象棋项目源码,为联网游戏而设计的。配有java服务端,不过只能单开。我没有测试具体的功能,感兴趣的可以自己链接数据库试试吧。下面是运行指南和开发设计文档。...9.智能AI(略) 10.流程
  • 象棋源码C#2005.rar

    2009-03-30 18:06:46
    中国象棋网络版C#源码简介Soft Introduction. Visual studio 2005,C#开发中国象棋网络版,具有人工智能,可采用人工下棋、电脑参谋、电脑下棋等模式参加互联网比赛。
  • vb.net中国象棋源码

    2010-01-24 09:24:35
    中国象棋人工智能开发 for vb.net
  • 国际象棋 Python中的简单国际象棋AI 使用数据集
  • AICheesBoard AI国际象棋棋盘
  • 罗恩·博特 深度学习国际象棋AI
  • 【180927】智能象棋游戏源码

    千次阅读 2018-09-27 16:04:41
     本源码是一个中国象棋游戏源码,可以单人游戏,也可以双人对战,系统默认有几种游戏模式,可以先择别人未战完的残局作战,也可以让电脑让步比你少一人作战,附有C#开发源文件,可以一边玩一边学习了。 三、菜单...

    一、源码特点
        采用winform进行开发,象棋游戏,欢迎下载
    二、功能介绍
        本源码是一个中国象棋游戏源码,可以单人游戏,也可以双人对战,系统默认有几种游戏模式,可以先择别人未战完的残局作战,也可以让电脑让步比你少一人作战,附有C#开发源文件,可以一边玩一边学习了。
    三、菜单功能
        1、文件:设置断点;读取断点;切换到双人游戏;切换到单人游戏;退出
        2、操作:新开一局;重新开始;选择残局;vs;转换玩家称呼;暂停
        3、控制:操作介绍
        4、音乐:可选择音乐或者关闭
        5、版本:显示版本信息
        6、显示当前系统时间
        7、结束后显示结果、用时、总剩余棋子数量,失去数量、比率、得分
    四、注意事项
        1、开发环境为Visual Studio 2010,使用.net 2.0开发。

    源码下载地址:点击下载

    备用下载地址:点击下载

    展开全文
  • 零零 基于Alpha零的国际象棋AI
  • 用MFC写的中国象棋游戏,VS2015可以直接编译,有多重AI算法,有兴趣可以研究,全网最好的象棋代码。又不懂的可以看看我的博客,有讲解。
  • Python 中国象棋源码 V1

    千次阅读 2019-12-18 15:53:43
    Pygame 做的中国象棋,一直以来喜欢下象棋,写了 python 就拿来做一个试试,水平有限,电脑走法水平低,需要在下次版本中更新电脑走法,希望源码能帮助大家更好的学习 python。总共分为四个文件,chinachess.py 为主...

    Pygame 做的中国象棋,一直以来喜欢下象棋,写了 python 就拿来做一个试试,水平有限,电脑走法水平低,需要在下次版本中更新电脑走法,希望源码能帮助大家更好的学习 python。总共分为四个文件,chinachess.py 为主文件,constants.py 数据常量,pieces.py 棋子类,走法,computer.py 电脑走法计算。
    链接:pan.baidu.com/s/1e1lzDiLT…
    提取码:cskj
    在这里插入图片描述
    chinachess.py 为主文件

    import pygame
    import time
    import constants
    import pieces
    import computer
    
    class MainGame():
        window = None
        Start_X = constants.Start_X
        Start_Y = constants.Start_Y
        Line_Span = constants.Line_Span
        Max_X = Start_X + 8 * Line_Span
        Max_Y = Start_Y + 9 * Line_Span
    
        player1Color = constants.player1Color
        player2Color = constants.player2Color
        Putdownflag = player1Color
        piecesSelected = None
    
        button_go = None
        piecesList = []
    
        def start_game(self):
            MainGame.window = pygame.display.set_mode([constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT])
            pygame.display.set_caption("天青-中国象棋")
            MainGame.button_go = Button(MainGame.window, "重新开始", constants.SCREEN_WIDTH - 100, 300)  # 创建开始按钮
            self.piecesInit()
    
            while True:
                time.sleep(0.1)
                # 获取事件
                MainGame.window.fill(constants.BG_COLOR)
                self.drawChessboard()
                #MainGame.button_go.draw_button()
                self.piecesDisplay()
                self.VictoryOrDefeat()
                self.Computerplay()
                self.getEvent()
                pygame.display.update()
                pygame.display.flip()
    
        def drawChessboard(self):
            mid_end_y = MainGame.Start_Y + 4 * MainGame.Line_Span
            min_start_y = MainGame.Start_Y + 5 * MainGame.Line_Span
            for i in range(0, 9):
                x = MainGame.Start_X + i * MainGame.Line_Span
                if i==0 or i ==8:
                    y = MainGame.Start_Y + i * MainGame.Line_Span
                    pygame.draw.line(MainGame.window, constants.BLACK, [x, MainGame.Start_Y], [x, MainGame.Max_Y], 1)
                else:
                    pygame.draw.line(MainGame.window, constants.BLACK, [x, MainGame.Start_Y], [x, mid_end_y], 1)
                    pygame.draw.line(MainGame.window, constants.BLACK, [x, min_start_y], [x, MainGame.Max_Y], 1)
    
            for i in range(0, 10):
                x = MainGame.Start_X + i * MainGame.Line_Span
                y = MainGame.Start_Y + i * MainGame.Line_Span
                pygame.draw.line(MainGame.window, constants.BLACK, [MainGame.Start_X, y], [MainGame.Max_X, y], 1)
    
            speed_dial_start_x =  MainGame.Start_X + 3 * MainGame.Line_Span
            speed_dial_end_x =  MainGame.Start_X + 5 * MainGame.Line_Span
            speed_dial_y1 = MainGame.Start_Y + 0 * MainGame.Line_Span
            speed_dial_y2 = MainGame.Start_Y + 2 * MainGame.Line_Span
            speed_dial_y3 = MainGame.Start_Y + 7 * MainGame.Line_Span
            speed_dial_y4 = MainGame.Start_Y + 9 * MainGame.Line_Span
    
            pygame.draw.line(MainGame.window, constants.BLACK, [speed_dial_start_x, speed_dial_y1], [speed_dial_end_x, speed_dial_y2], 1)
            pygame.draw.line(MainGame.window, constants.BLACK, [speed_dial_start_x, speed_dial_y2],
                             [speed_dial_end_x, speed_dial_y1], 1)
            pygame.draw.line(MainGame.window, constants.BLACK, [speed_dial_start_x, speed_dial_y3],
                             [speed_dial_end_x, speed_dial_y4], 1)
            pygame.draw.line(MainGame.window, constants.BLACK, [speed_dial_start_x, speed_dial_y4],
                             [speed_dial_end_x, speed_dial_y3], 1)
    
        def piecesInit(self):
            MainGame.piecesList.append(pieces.Rooks(MainGame.player2Color, 0,0))
            MainGame.piecesList.append(pieces.Rooks(MainGame.player2Color,  8, 0))
            MainGame.piecesList.append(pieces.Elephants(MainGame.player2Color,  2, 0))
            MainGame.piecesList.append(pieces.Elephants(MainGame.player2Color,  6, 0))
            MainGame.piecesList.append(pieces.King(MainGame.player2Color, 4, 0))
            MainGame.piecesList.append(pieces.Knighs(MainGame.player2Color,  1, 0))
            MainGame.piecesList.append(pieces.Knighs(MainGame.player2Color,  7, 0))
            MainGame.piecesList.append(pieces.Cannons(MainGame.player2Color,  1, 2))
            MainGame.piecesList.append(pieces.Cannons(MainGame.player2Color, 7, 2))
            MainGame.piecesList.append(pieces.Mandarins(MainGame.player2Color,  3, 0))
            MainGame.piecesList.append(pieces.Mandarins(MainGame.player2Color, 5, 0))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player2Color, 0, 3))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player2Color, 2, 3))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player2Color, 4, 3))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player2Color, 6, 3))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player2Color, 8, 3))
    
            MainGame.piecesList.append(pieces.Rooks(MainGame.player1Color,  0, 9))
            MainGame.piecesList.append(pieces.Rooks(MainGame.player1Color,  8, 9))
            MainGame.piecesList.append(pieces.Elephants(MainGame.player1Color, 2, 9))
            MainGame.piecesList.append(pieces.Elephants(MainGame.player1Color, 6, 9))
            MainGame.piecesList.append(pieces.King(MainGame.player1Color,  4, 9))
            MainGame.piecesList.append(pieces.Knighs(MainGame.player1Color, 1, 9))
            MainGame.piecesList.append(pieces.Knighs(MainGame.player1Color, 7, 9))
            MainGame.piecesList.append(pieces.Cannons(MainGame.player1Color,  1, 7))
            MainGame.piecesList.append(pieces.Cannons(MainGame.player1Color,  7, 7))
            MainGame.piecesList.append(pieces.Mandarins(MainGame.player1Color,  3, 9))
            MainGame.piecesList.append(pieces.Mandarins(MainGame.player1Color,  5, 9))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player1Color, 0, 6))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player1Color, 2, 6))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player1Color, 4, 6))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player1Color, 6, 6))
            MainGame.piecesList.append(pieces.Pawns(MainGame.player1Color, 8, 6))
    
        def piecesDisplay(self):
            for item in MainGame.piecesList:
                item.displaypieces(MainGame.window)
                #MainGame.window.blit(item.image, item.rect)
    
        def getEvent(self):
            # 获取所有的事件
            eventList = pygame.event.get()
            for event in eventList:
                if event.type == pygame.QUIT:
                    self.endGame()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    pos = pygame.mouse.get_pos()
                    mouse_x = pos[0]
                    mouse_y = pos[1]
                    if (
                            mouse_x > MainGame.Start_X - MainGame.Line_Span / 2 and mouse_x < MainGame.Max_X + MainGame.Line_Span / 2) and (
                            mouse_y > MainGame.Start_Y - MainGame.Line_Span / 2 and mouse_y < MainGame.Max_Y + MainGame.Line_Span / 2):
                        # print( str(mouse_x) + "" + str(mouse_y))
                        # print(str(MainGame.Putdownflag))
                        if MainGame.Putdownflag != MainGame.player1Color:
                            return
    
                        click_x = round((mouse_x - MainGame.Start_X) / MainGame.Line_Span)
                        click_y = round((mouse_y - MainGame.Start_Y) / MainGame.Line_Span)
                        click_mod_x = (mouse_x - MainGame.Start_X) % MainGame.Line_Span
                        click_mod_y = (mouse_y - MainGame.Start_Y) % MainGame.Line_Span
                        if abs(click_mod_x - MainGame.Line_Span / 2) >= 5 and abs(
                                click_mod_y - MainGame.Line_Span / 2) >= 5:
                            # print("有效点:x="+str(click_x)+" y="+str(click_y))
                            # 有效点击点
                            self.PutdownPieces(MainGame.player1Color, click_x, click_y)
                    else:
                        print("out")
                    if MainGame.button_go.is_click():
                        #self.restart()
                        print("button_go click")
                    else:
                        print("button_go click out")
    
        def PutdownPieces(self, t, x, y):
            selectfilter=list(filter(lambda cm: cm.x == x and cm.y == y and cm.player == MainGame.player1Color,MainGame.piecesList))
            if len(selectfilter):
                MainGame.piecesSelected = selectfilter[0]
                return
    
            if MainGame.piecesSelected :
                #print("1111")
    
                arr = pieces.listPiecestoArr(MainGame.piecesList)
                if MainGame.piecesSelected.canmove(arr, x, y):
                    self.PiecesMove(MainGame.piecesSelected, x, y)
                    MainGame.Putdownflag = MainGame.player2Color
            else:
                fi = filter(lambda p: p.x == x and p.y == y, MainGame.piecesList)
                listfi = list(fi)
                if len(listfi) != 0:
                    MainGame.piecesSelected = listfi[0]
    
        def PiecesMove(self,pieces,  x , y):
            for item in  MainGame.piecesList:
                if item.x ==x and item.y == y:
                    MainGame.piecesList.remove(item)
            pieces.x = x
            pieces.y = y
            print("move to " +str(x) +" "+str(y))
            return True
    
        def Computerplay(self):
            if MainGame.Putdownflag == MainGame.player2Color:
                print("轮到电脑了")
                computermove = computer.getPlayInfo(MainGame.piecesList)
                #if computer==None:
                    #return
                piecemove = None
                for item in MainGame.piecesList:
                    if item.x == computermove[0] and item.y == computermove[1]:
                        piecemove= item
    
                self.PiecesMove(piecemove, computermove[2], computermove[3])
                MainGame.Putdownflag = MainGame.player1Color
    
        #判断游戏胜利
        def VictoryOrDefeat(self):
            txt =""
            result = [MainGame.player1Color,MainGame.player2Color]
            for item in MainGame.piecesList:
                if type(item) ==pieces.King:
                    if item.player == MainGame.player1Color:
                        result.remove(MainGame.player1Color)
                    if item.player == MainGame.player2Color:
                        result.remove(MainGame.player2Color)
    
            if len(result)==0:
                return
            if result[0] == MainGame.player1Color :
                txt = "失败!"
            else:
                txt = "胜利!"
            MainGame.window.blit(self.getTextSuface("%s" % txt), (constants.SCREEN_WIDTH - 100, 200))
            MainGame.Putdownflag = constants.overColor
    
        def getTextSuface(self, text):
            pygame.font.init()
            # print(pygame.font.get_fonts())
            font = pygame.font.SysFont('kaiti', 18)
            txt = font.render(text, True, constants.TEXT_COLOR)
            return txt
    
        def endGame(self):
            print("exit")
            exit()
    
    if __name__ == '__main__':
        MainGame().start_game()
    

    constants.py 数据常量

    import pygame
    
    SCREEN_WIDTH=900
    SCREEN_HEIGHT=650
    Start_X = 50
    Start_Y = 50
    Line_Span = 60
    
    player1Color = 1
    player2Color = 2
    overColor = 3
    
    BG_COLOR=pygame.Color(200, 200, 200)
    Line_COLOR=pygame.Color(255, 255, 200)
    TEXT_COLOR=pygame.Color(255, 0, 0)
    
    # 定义颜色
    BLACK = ( 0, 0, 0)
    WHITE = (255, 255, 255)
    RED = (255, 0, 0)
    GREEN = ( 0, 255, 0)
    BLUE = ( 0, 0, 255)
    
    repeat = 0
    
    pieces_images = {
        'b_rook': pygame.image.load("imgs/s2/b_c.gif"),
        'b_elephant': pygame.image.load("imgs/s2/b_x.gif"),
        'b_king': pygame.image.load("imgs/s2/b_j.gif"),
        'b_knigh': pygame.image.load("imgs/s2/b_m.gif"),
        'b_mandarin': pygame.image.load("imgs/s2/b_s.gif"),
        'b_cannon': pygame.image.load("imgs/s2/b_p.gif"),
        'b_pawn': pygame.image.load("imgs/s2/b_z.gif"),
    
        'r_rook': pygame.image.load("imgs/s2/r_c.gif"),
        'r_elephant': pygame.image.load("imgs/s2/r_x.gif"),
        'r_king': pygame.image.load("imgs/s2/r_j.gif"),
        'r_knigh': pygame.image.load("imgs/s2/r_m.gif"),
        'r_mandarin': pygame.image.load("imgs/s2/r_s.gif"),
        'r_cannon': pygame.image.load("imgs/s2/r_p.gif"),
        'r_pawn': pygame.image.load("imgs/s2/r_z.gif"),
    }
    

    pieces.py 棋子类,走法,

    import pygame
    import constants
    
    class  Pieces():
        def __init__(self, player,  x, y):
            self.imagskey = self.getImagekey()
            self.image = constants.pieces_images[self.imagskey]
            self.x = x
            self.y = y
            self.player = player
            self.rect = self.image.get_rect()
            self.rect.left = constants.Start_X + x * constants.Line_Span - self.image.get_rect().width / 2
            self.rect.top = constants.Start_Y + y * constants.Line_Span - self.image.get_rect().height / 2
    
        def displaypieces(self,screen):
            #print(str(self.rect.left))
            self.rect.left = constants.Start_X + self.x * constants.Line_Span - self.image.get_rect().width / 2
            self.rect.top = constants.Start_Y + self.y * constants.Line_Span - self.image.get_rect().height / 2
            screen.blit(self.image,self.rect);
            #self.image = self.images
            #MainGame.window.blit(self.image,self.rect)
    
        def canmove(self, arr, moveto_x, moveto_y):
            pass
        def getImagekey(self):
            return None
        def getScoreWeight(self,listpieces):
            return  None
    
    class Rooks(Pieces):
        def __init__(self, player,  x, y):
            self.player = player
            super().__init__(player,  x, y)
    
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_rook"
            else:
                return "b_rook"
    
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] ==self.player :
                return  False
            if self.x == moveto_x:
                step = -1 if self.y > moveto_y else 1
                for i in range(self.y +step, moveto_y, step):
                    if arr[self.x][i] !=0 :
                        return False
                #print(" move y")
                return True
    
            if self.y == moveto_y:
                step = -1 if self.x > moveto_x else 1
                for i in range(self.x + step, moveto_x, step):
                    if arr[i][self.y] != 0:
                        return False
                return True
    
        def getScoreWeight(self, listpieces):
            score = 11
            return score
    
    class Knighs(Pieces):
        def __init__(self, player,  x, y):
            self.player = player
            super().__init__(player,  x, y)
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_knigh"
            else:
                return "b_knigh"
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] == self.player:
                return False
            #print(str(self.x) +""+str(self.y))
            move_x = moveto_x-self.x
            move_y = moveto_y - self.y
            if abs(move_x) == 1 and abs(move_y) == 2:
                step = 1 if move_y > 0 else -1
                if arr[self.x][self.y + step] == 0:
                    return True
            if abs(move_x) == 2 and abs(move_y) == 1:
                step = 1 if move_x >0 else -1
                if arr[self.x +step][self.y] ==0 :
                    return  True
    
        def getScoreWeight(self, listpieces):
            score = 5
            return score
    
    class Elephants(Pieces):
        def __init__(self, player, x, y):
            self.player = player
            super().__init__(player, x, y)
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_elephant"
            else:
                return "b_elephant"
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] == self.player:
                return False
            if self.y <=4 and moveto_y >=5 or self.y >=5 and moveto_y <=4:
                return  False
            move_x = moveto_x - self.x
            move_y = moveto_y - self.y
            if abs(move_x) == 2 and abs(move_y) == 2:
                step_x = 1 if move_x > 0 else -1
                step_y = 1 if move_y > 0 else -1
                if arr[self.x + step_x][self.y + step_y] == 0:
                    return True
    
        def getScoreWeight(self, listpieces):
            score = 2
            return score
    class Mandarins(Pieces):
    
        def __init__(self, player,  x, y):
            self.player = player
            super().__init__(player,  x, y)
    
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_mandarin"
            else:
                return "b_mandarin"
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] == self.player:
                return False
            if moveto_x <3 or moveto_x >5:
                return False
            if moveto_y > 2 and moveto_y < 7:
                return False
            move_x = moveto_x - self.x
            move_y = moveto_y - self.y
            if abs(move_x) == 1 and abs(move_y) == 1:
                return True
        def getScoreWeight(self, listpieces):
            score = 2
            return score
    
    class King(Pieces):
        def __init__(self, player, x, y):
            self.player = player
            super().__init__(player, x, y)
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_king"
            else:
                return "b_king"
    
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] == self.player:
                return False
            if moveto_x < 3 or moveto_x > 5:
                return False
            if moveto_y > 2 and moveto_y < 7:
                return False
            move_x = moveto_x - self.x
            move_y = moveto_y - self.y
            if abs(move_x) + abs(move_y) == 1:
                return True
        def getScoreWeight(self, listpieces):
            score = 150
            return score
    class Cannons(Pieces):
        def __init__(self, player,  x, y):
            self.player = player
            super().__init__(player, x, y)
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_cannon"
            else:
                return "b_cannon"
    
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] == self.player:
                return False
            overflag = False
            if self.x == moveto_x:
                step = -1 if self.y > moveto_y else 1
                for i in range(self.y + step, moveto_y, step):
                    if arr[self.x][i] != 0:
                        if overflag:
                            return False
                        else:
                            overflag = True
    
                if overflag and arr[moveto_x][moveto_y] == 0:
                    return False
                if not overflag and arr[self.x][moveto_y] != 0:
                    return False
    
                return True
    
            if self.y == moveto_y:
                step = -1 if self.x > moveto_x else 1
                for i in range(self.x + step, moveto_x, step):
                    if arr[i][self.y] != 0:
                        if overflag:
                            return False
                        else:
                            overflag = True
    
                if overflag and arr[moveto_x][moveto_y] == 0:
                    return False
                if not overflag and arr[moveto_x][self.y] != 0:
                    return False
                return True
        def getScoreWeight(self, listpieces):
            score = 6
            return score
    
    class Pawns(Pieces):
        def __init__(self, player, x, y):
            self.player = player
            super().__init__(player,  x, y)
        def getImagekey(self):
            if self.player == constants.player1Color:
                return "r_pawn"
            else:
                return "b_pawn"
    
        def canmove(self, arr, moveto_x, moveto_y):
            if self.x == moveto_x and self.y == moveto_y:
                return False
            if arr[moveto_x][moveto_y] == self.player:
                return False
            move_x = moveto_x - self.x
            move_y = moveto_y - self.y
    
            if self.player == constants.player1Color:
                if self.y > 4  and move_x != 0 :
                    return  False
                if move_y > 0:
                    return  False
            elif self.player == constants.player2Color:
                if self.y <= 4  and move_x != 0 :
                    return  False
                if move_y < 0:
                    return False
    
            if abs(move_x) + abs(move_y) == 1:
                return True
        def getScoreWeight(self, listpieces):
            score = 2
            return score
    
    def listPiecestoArr(piecesList):
        arr = [[0 for i in range(10)] for j in range(9)]
        for i in range(0, 9):
            for j in range(0, 10):
                if len(list(filter(lambda cm: cm.x == i and cm.y == j and cm.player == constants.player1Color,
                                   piecesList))):
                    arr[i][j] = constants.player1Color
                elif len(list(filter(lambda cm: cm.x == i and cm.y == j and cm.player == constants.player2Color,
                                     piecesList))):
                    arr[i][j] = constants.player2Color
    
        return arr
    

    computer.py 电脑走法计算

    import constants
    #import time
    from pieces import listPiecestoArr
    
    def getPlayInfo(listpieces):
        pieces = movedeep(listpieces ,1 ,constants.player2Color)
        return [pieces[0].x,pieces[0].y, pieces[1], pieces[2]]
    
    def movedeep(listpieces, deepstep, player):
        arr = listPiecestoArr(listpieces)
        listMoveEnabel = []
        for i in range(0, 9):
            for j in range(0, 10):
                for item in listpieces:
                    if item.player == player and item.canmove(arr, i, j):
                        #标记是否有子被吃 如果被吃 在下次循环时需要补会
                        piecesremove = None
                        for itembefore in listpieces:
                            if itembefore.x == i and itembefore.y == j:
                                piecesremove= itembefore
                                break
                        if piecesremove != None:
                            listpieces.remove(piecesremove)
    
                        #记录移动之前的位置
                        move_x = item.x
                        move_y = item.y
                        item.x = i
                        item.y = j
    
                        #print(str(move_x) + "," + str(move_y) + "," + str(item.x) + "  ,  " + str(item.y))
                        scoreplayer1 = 0
                        scoreplayer2 = 0
                        for itemafter in listpieces:
                            if itemafter.player == constants.player1Color:
                                scoreplayer1 += itemafter.getScoreWeight(listpieces)
                            elif  itemafter.player == constants.player2Color:
                                scoreplayer2 += itemafter.getScoreWeight(listpieces)
    
                        #print("得分:"+item.imagskey +", "+str(len(moveAfterListpieces))+","+str(i)+","+str(j)+"," +str(scoreplayer1) +"  ,  "+ str(scoreplayer2) )
                        #print(str(deepstep))
                        #如果得子 判断对面是否可以杀过来,如果又被杀,而且子力评分低,则不干
                        arrkill = listPiecestoArr(listpieces)
    
                        if scoreplayer2 > scoreplayer1 :
                            for itemkill in listpieces:
                                if itemkill.player == constants.player1Color and itemkill.canmove(arrkill, i, j):
                                    scoreplayer2=scoreplayer1
    
                        if deepstep > 0 :
                            nextplayer = constants.player1Color if player == constants.player2Color else constants.player2Color
                            nextpiecesbest= movedeep(listpieces, deepstep -1, nextplayer)
                            listMoveEnabel.append([item, i, j, nextpiecesbest[3], nextpiecesbest[4], nextpiecesbest[5]])
                        else:
                            #print(str(len(listpieces)))
                            #print("得分:" + item.imagskey + ", " + str(len(listpieces)) + "," + str(move_x) + "," + str(move_y) + "," + str(i) + "  ,  " + str(j))
                            if player == constants.player2Color:
                                listMoveEnabel.append([item, i, j, scoreplayer1, scoreplayer2, scoreplayer1 - scoreplayer2])
                            else:
                                listMoveEnabel.append([item, i, j, scoreplayer1, scoreplayer2, scoreplayer2 - scoreplayer1])
                        #print("得分:"+str(scoreplayer1))
                        item.x = move_x
                        item.y = move_y
                        if piecesremove != None:
                            listpieces.append(piecesremove)
    
        list_scorepalyer1 = sorted(listMoveEnabel, key=lambda tm: tm[5], reverse=True)
        piecesbest = list_scorepalyer1[0]
        if deepstep ==1 :
            print(list_scorepalyer1)
        return piecesbest
    

    computer.py 电脑走法计算

    import constants
    #import time
    from pieces import listPiecestoArr
    
    def getPlayInfo(listpieces):
        pieces = movedeep(listpieces ,1 ,constants.player2Color)
        return [pieces[0].x,pieces[0].y, pieces[1], pieces[2]]
    
    def movedeep(listpieces, deepstep, player):
        arr = listPiecestoArr(listpieces)
        listMoveEnabel = []
        for i in range(0, 9):
            for j in range(0, 10):
                for item in listpieces:
                    if item.player == player and item.canmove(arr, i, j):
                        #标记是否有子被吃 如果被吃 在下次循环时需要补会
                        piecesremove = None
                        for itembefore in listpieces:
                            if itembefore.x == i and itembefore.y == j:
                                piecesremove= itembefore
                                break
                        if piecesremove != None:
                            listpieces.remove(piecesremove)
    
                        #记录移动之前的位置
                        move_x = item.x
                        move_y = item.y
                        item.x = i
                        item.y = j
    
                        #print(str(move_x) + "," + str(move_y) + "," + str(item.x) + "  ,  " + str(item.y))
                        scoreplayer1 = 0
                        scoreplayer2 = 0
                        for itemafter in listpieces:
                            if itemafter.player == constants.player1Color:
                                scoreplayer1 += itemafter.getScoreWeight(listpieces)
                            elif  itemafter.player == constants.player2Color:
                                scoreplayer2 += itemafter.getScoreWeight(listpieces)
    
                        #print("得分:"+item.imagskey +", "+str(len(moveAfterListpieces))+","+str(i)+","+str(j)+"," +str(scoreplayer1) +"  ,  "+ str(scoreplayer2) )
                        #print(str(deepstep))
                        #如果得子 判断对面是否可以杀过来,如果又被杀,而且子力评分低,则不干
                        arrkill = listPiecestoArr(listpieces)
    
                        if scoreplayer2 > scoreplayer1 :
                            for itemkill in listpieces:
                                if itemkill.player == constants.player1Color and itemkill.canmove(arrkill, i, j):
                                    scoreplayer2=scoreplayer1
    
                        if deepstep > 0 :
                            nextplayer = constants.player1Color if player == constants.player2Color else constants.player2Color
                            nextpiecesbest= movedeep(listpieces, deepstep -1, nextplayer)
                            listMoveEnabel.append([item, i, j, nextpiecesbest[3], nextpiecesbest[4], nextpiecesbest[5]])
                        else:
                            #print(str(len(listpieces)))
                            #print("得分:" + item.imagskey + ", " + str(len(listpieces)) + "," + str(move_x) + "," + str(move_y) + "," + str(i) + "  ,  " + str(j))
                            if player == constants.player2Color:
                                listMoveEnabel.append([item, i, j, scoreplayer1, scoreplayer2, scoreplayer1 - scoreplayer2])
                            else:
                                listMoveEnabel.append([item, i, j, scoreplayer1, scoreplayer2, scoreplayer2 - scoreplayer1])
                        #print("得分:"+str(scoreplayer1))
                        item.x = move_x
                        item.y = move_y
                        if piecesremove != None:
                            listpieces.append(piecesremove)
    
        list_scorepalyer1 = sorted(listMoveEnabel, key=lambda tm: tm[5], reverse=True)
        piecesbest = list_scorepalyer1[0]
        if deepstep ==1 :
            print(list_scorepalyer1)
        return piecesbest
    

    扫码关注微信公众号 干货分享,获取更多资源
    在这里插入图片描述

    展开全文
  • C-国际象棋 (这是一个自动生成的文件。)
  • 我们基于α-β剪枝人工智能方法的的中国象棋使用python实现,分为走法计算、评估函数与搜索和UI三部分,并采用历史启发算法进行优化,有着不错的效果。可以实现正常的人机对战,有着普通人的棋力,经过多轮测试,...
  • 国际象棋 我使用minimax创建了一个国际象棋AI

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,454
精华内容 581
关键字:

ai象棋源码