回复:取石子- 原创

来源: file20002000 2009-12-11 14:51:09 [] [旧帖] [给我悄悄话] 本文已被阅读: 次 (1670 bytes)
Note. 这个思路是最直接也是最有趣的。
This is a perfect AI program! You can win the computer easily at beginning, but it becomes invulnerable later.
(You can let the computer play with itself to gain its knowledgebase.)

I have at least two other solutions, one can be as short as just a few lines. 先不贴 - 留给网上高手 (i am not a CS nor Math major)

Knowledge Database = {losing cases} ‘if I can left this case to opponent, I will win. such as (1-2-3)

Add (0-0-0) to {losing case} ‘(0-0-0) is a losing hand by game definition
Add (0-1-1) to {losing case} ‘Not Needed! I add here so you can understand my examples



SubFunction CanIWinThisHand (X-Y-Z)
Search all sub (X-Y-X)
If at least one sub(X-Y-Z) = {losing case} Then return TRUE
else return FALSE
End SubFunction




Function WhatToDoWith(A-B-C)

If (A-B-C) = {losing cases}
If A-B-C = {0-0-0} then end ‘Result 1a: Lost and Game Over and Opponent Won!
else create sub(A-B-C) randomly ‘Result 1b: Losing (such as 0-1-1)

If CanIWinThisHand (A-B-C) = TRUE ‘I can win! 0-0-5, 1-1-5 for example
Then I create that sub(A-B-C) ‘’Result 2- Wining (such as 1-1-1 -> 0-1-1)

if All CanIWinThisHand (sub(A-B-C)) =True ‘no matter what I move, my opponent may create a losing case to against me
Add (A-B-C) to my database ‘then I learned this is a new losing hand
pick randomly ‘Result 3 – Losing, but I learned from it! (Such as adding 1-2-3 to my Knowledge)

Else
pick randomly ‘Result 4 – I have no idea what this hand can be because my knowledge is no strong yet.


End Function
请您先登陆,再发跟帖!

发现Adblock插件

如要继续浏览
请支持本站 请务必在本站关闭/移除任何Adblock

关闭Adblock后 请点击

请参考如何关闭Adblock/Adblock plus

安装Adblock plus用户请点击浏览器图标
选择“Disable on www.wenxuecity.com”

安装Adblock用户请点击图标
选择“don't run on pages on this domain”