圈叉棋 Tic Tac Toe实现与AI分析

简介

井字棋 圈叉棋 Tic Tac Toe
在这里插入图片描述

原理

用数组代表棋子的位置,可以1x9也可以3x3

判断胜利

井字棋有八种胜利的方式,三横三竖两对角线,逐个遍历即可判定是否胜利,参考一就是遍历六次加上对角线,个人觉得参考三的七个or更优美简洁一点吧。

AI算法

算法思路在书上写的很明白

The AI’s algorithm will have the following steps:

  1.  First, see if there’s a move the computer can make that will win the game. If there is, take that move. Otherwise, go to step 2.
    
  2.  See if there’s a move the player can make that will cause the computer to lose the game. If there is, move there to block the player. Otherwise, go to step 3.
    
  3.  Check if any of the corner spaces (spaces 1, 3, 7, or 9) are free. If so, move there. If no corner piece is free, then go to step 4.
    
  4.  Check if the center is free. If so, move there. If it isn’t, then go to step 5.
    
  5.  Move on any of the side pieces (spaces 2, 4, 6, or 8). There are no more steps, because if the execution reaches step 5 the side spaces are the only spaces left.
    

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值