五子棋机器学习源代码_五子棋机器人/

大家好!我又回来了!也带来了最刚出炉的五子棋机器人。

0. 做五子棋机器人的初衷

大学已经毕业了一个月了,因为研究生那边暂时去不了,又不想回湖北。所以在学校里租了房暂住一个月,白天学车晚上实验室学(mo)习(yu)。因为毕设的时候有两位同学做的五子棋机器人的硬件和软件,每次听他们汇报都很想帮他们做毕设。于是在毕业之后,趁着这几天十分闲。做了一下五子棋机器人。

1. 总体介绍

其实做过魔方机器人之后这种东西套路都类似。接下来我从视觉、算法、硬件三个方面介绍,实际上每个部分都不太难,适合新手入门。

总的流程大致是这样,首先通过摄像头读取棋盘信息,并定位棋子位置,识别两种棋子颜色。然后将棋子位置传给求解函数。求解函数就是一个简单的博弈树加上α-β剪枝。因为没太多时间,所以搜索效率并不是很高。得到下一步该走的位置之后,将位置信息通过串口发送到下位机。下位机使用Arduinio编程,接收并处理上位机发送的信息。然后驱动机械臂和气动吸盘放置棋子。

2. 视觉部分

视觉部分没有用到智能算法,都是很基础的图像处理。简单学过一点opencv应该都可以看懂,所以我说这个项目很适合新手入门。

首先你需要有个python环境,还有一个opencv的库。使用pip安装就可以了。没有安装成功的可以去CSDN上看看教程,我就不细说了。然后流程是从摄像头获取图像,对图像进行预处理,从摄像头获得数据然后对其进行处理,各种图像预处理,然后是圆形识别和颜色识别。这个地方我反复识别了8次,也就是说每次识别棋盘的时候,读取8次摄像头数据,这样能够减小偶尔一两次识别不出来部分棋子的误差。最后写好接口,函数返回棋子在棋盘上的坐标以及图像。

流程大概就是下图所示:

Ps.一般颜色识别都很不好搞,但是黑白棋子识别就很简单!!随便画阈值就可以,和识别魔方颜色完全不是一个难度。

e44630dc3d5afca90a4ec0f845224e73.png
视觉流程图

放一张效果图

1a2d5900c17469a5e8ceee2c7e640528.png
黑白棋子都能准确识别

3. 算法部分

算法这方面,我觉得自己没有太多好说的。知乎上大神太多了,这方面也被说了很多了。主流做法大概有两种。大部分情况是使用博弈树然后使用α-β剪枝,这个方法是最常见。还有一种是我在GitHub上见到的,使用alpha-zero算法,用机器学习的方式去做。

我是用的第一种,也就是博弈树的方法做的。搜索深度为3效果还行。大致讲讲流程:

b672dc0f7a94c18ed6ff57b57631ab59.png
算法流程图

4. 机械部分

机械部分也是很有意思的一个部分,因为本命专业是机械,所以这种需要动手的工作我就很喜欢。其实每次做这些东西的时候我都在想,这些项目的进度完全取决于某宝卖家的发货速度和快递配送速度。

五子棋是实验室娱乐用的五子棋,底座的木板是某宝木材厂切的,铝型材是实验室回收的,摄像头是找同学撸的,机械臂是同学用过留下来的。

就这样拼拼凑凑也算是攒齐了一套材料。看看效果吧。

c589d569638c971345a745d12c6e00cf.png

1ce6c09d974e23d450fff5f66d4fb3ee.png

5. 总结

这个项目一共做了7天,每天花了大概4个小时调。每个模块的内容难度都适中,十分适合新手入门。建议机械电子的同学可以简单做一个练练手。对这些专业知识大概有一个了解,多接触一些知识发现自己兴趣所在~

还有一点想法,老师也在和我说,都大四毕业了要多写点论文少搞点这种东西。我觉得十分有道理,以后还是把时间拿来写论文吧。这种小发明可能做的比较少了QAQ

还可以看看我之前做的魔方机器人。

贺咔:魔方机器人~​zhuanlan.zhihu.com
dab1d06dd4b94f4b0e72565dfcb34576.png

最后祝大家学习进步啦~


最后的最后,如果有朋友想一起改进代码或者想要开发资料的也欢迎和我联系~知乎私信我就可以啦! 代码我就不放GitHub了。

40a5e7ee50bb8d4ab640b45478f86b20.png
发一张近照 欢迎来重庆找我玩~
======================================================================== MICROSOFT FOUNDATION CLASS LIBRARY : fir ======================================================================== AppWizard has created this fir application for you. This application not only demonstrates the basics of using the Microsoft Foundation classes but is also a starting point for writing your application. This file contains a summary of what you will find in each of the files that make up your fir application. fir.dsp This file (the project file) contains information at the project level and is used to build a single project or subproject. Other users can share the project (.dsp) file, but they should export the makefiles locally. fir.h This is the main header file for the application. It includes other project specific headers (including Resource.h) and declares the CFirApp application class. fir.cpp This is the main application source file that contains the application class CFirApp. fir.rc This is a listing of all of the Microsoft Windows resources that the program uses. It includes the icons, bitmaps, and cursors that are stored in the RES subdirectory. This file can be directly edited in Microsoft Visual C++. fir.clw This file contains information used by ClassWizard to edit existing classes or add new classes. ClassWizard also uses this file to store information needed to create and edit message maps and dialog data maps and to create prototype member functions. res\fir.ico This is an icon file, which is used as the application's icon. This icon is included by the main resource file fir.rc. res\fir.rc2 This file contains resources that are not edited by Microsoft Visual C++. You should place all resources not editable by the resource editor in this file. ///////////////////////////////////////////////////////////////////////////// For the main frame window: MainFrm.h, MainFrm.cpp These files contain the frame class CMainFrame, which is derived from CFrameWnd and controls all SDI frame features. ///////////////////////////////////////////////////////////////////////////// AppWizard creates one document type and one view: firDoc.h, firDoc.cpp - the document These files contain your CFirDoc class. Edit these files to add your special document data and to implement file saving and loading (via CFirDoc::Serialize). firView.h, firView.cpp - the view of the document These files contain your CFirView class. CFirView objects are used to view CFirDoc objects. ///////////////////////////////////////////////////////////////////////////// Other standard files: StdAfx.h, StdAfx.cpp These files are used to build a precompiled header (PCH) file named fir.pch and a precompiled types file named StdAfx.obj. Resource.h This is the standard header file, which defines new resource IDs. Microsoft Visual C++ reads and updates this file. ///////////////////////////////////////////////////////////////////////////// Other notes: AppWizard uses "TODO:" to indicate parts of the source code you should add to or customize. If your application uses MFC in a shared DLL, and your application is in a language other than the operating system's current language, you will need to copy the corresponding localized resources MFC42XXX.DLL from the Microsoft Visual C++ CD-ROM onto the system or system32 directory, and rename it to be MFCLOC.DLL. ("XXX" stands for the language abbreviation. For example, MFC42DEU.DLL contains resources translated to German.) If you don't do this, some of the UI elements of your application will remain in the language of the operating system. /////////////////////////////////////////////////////////////////////////////
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值