丁庄秀园

欢迎光临秀园和丁庄…
个人资料
丁庄秀园 (热门博主)
  • 博客访问:  
归档
正文

用AI写代码实例2 Board游戏

(2026-07-07 19:33:47) 下一个

这是用Copilot写的一款游戏,我和AI的对话比较长所以省略部分AI的回答(你用我的问话应该可以得到类似的回答),AI给我的Python Code我都会在iPython执行然后继续提建议,实录

我:Let's do a board game. Board is 3 by 3 of 9 points. All horizontal and vertical lines connected, plus center point connected to 4 corner points. Can you show python code to display board

(AI给我的Code和回答省略。。。)

我:Good. It will be person against computer. I will start with 3 pieces on bottom and computer starts 3 pieces on top. Show board with piece

我:Take turn to move. You win if 3 pieces are in one straight line passing middle point

我:Good. Can you add computer move now

我:Perfect! Now please add level selection and computer move correspondingly

AI:If you want, I can add:
Level 4: Perfect AI (minimax)
highlight legal moves when selecting a piece
undo button
scoreboard
Just tell me what you want next.

我:Add all your good suggestions!

AI:If you want, I can also add:
Animation for moves
Sound effects
Menu screen for level selection
Save/load game
Online multiplayer
Just tell me what direction you want to take this next,

我:Yes and add all your suggestions

我:Game board display incorrect. Please try again

我:Please add these Save/Load game Online multiplayer

(AI给我几个选择。。。)

我:Let's do option A

我:can we put menu on top of board so it is accessable all the time

我:Build full dropdown game from scratch

AI:If you want hover highlights or keyboard shortcuts (e.g., Ctrl+S for save), we can layer those in next.

上面就是最后生成的游戏,你先走和计算机对弈,黄色是左边我的蓝棋子可以移动的点。其中Level 1是计算机随机的走棋,2是赢棋如果有机会,3是阻止你马上可以赢的位置,4是用MinMax人工智能算法得出最优解。Online是可以网上和朋友走棋。用你喜欢的AI能生成类似或更好的游戏吗?

儿子小时候我常和他玩,特别是在餐馆等待的时候,弄三个红纸的糖三个白纸的糖做棋子,棋盘想象一下就可以了,如果都特别小心那么谁都赢不了,但是如果加上时间限制就很容易出错输棋。

[ 打印 ]
阅读 ( )评论
评论
目前还没有任何评论
登录后才可评论.