最近学了一点QT的绘图,于是乎照着学长的代码绘制了五子棋的小游戏。
最基础的东西这里就不说了,自己的知识也仅仅比会用多那么一点,下面我们来说说这里貌似高大上的人机AI吧。
评分表算法
一般情况下棋盘是15*15的。那么应该是572个五元组。而这五元组由黑棋白棋还有空格组成。也就是 3^5 * 572 = 138996; 看着很多吧,其实是可以分类的。每个五元组就是一种局势。
我们只用统计只有己方棋子的局势,以及只有敌方棋子的局势,针对这两种局势给予确定的评分,而其他局势直接评分为0。
下面是我使用的是评分表
// tuple is empty
Blank,
// tuple contains a black chess
B,
// tuple contains two black chesses
BB,
// tuple contains three black chesses
BBB,
// tuple contains four black chesses
BBBB,
// tuple contains a white chess
W,
// tuple contains two white chesses
WW,
// tuple contains three white chesses
WWW,
// tuple contains four white chesses
WWWW,
// tuple does not exist
Virtual,
// tuple contains at least one black and